# kaku-rest

> A rest api for KaKu (CoCo) devices

Latest version **0.2.0** (published 2018-09-11) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install kaku-rest
pnpm add kaku-rest
yarn add kaku-rest
bun add kaku-rest
```

Provides the command `kaku-rest`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2018-09-11 |
| First published | 2018-09-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 11.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Micha den Heijer |
| Maintainers | michadenheijer |
| Keywords | KaKu, REST |

## Links

- npm: https://www.npmjs.com/package/kaku-rest
- Repository: https://github.com/michadenheijer/kaku-rest-api
- Homepage: https://github.com/michadenheijer/kaku-rest-api#readme
- Issues: https://github.com/michadenheijer/kaku-rest-api/issues
- npm.io page: https://npm.io/package/kaku-rest

## Dependencies (4)

- [express](https://npm.io/package/express.md) ^4.16.3
- [kaku-rpi](https://npm.io/package/kaku-rpi.md) ^2.1.0
- [user-home](https://npm.io/package/user-home.md) ^2.0.0
- [file-system](https://npm.io/package/file-system.md) ^2.2.2

## Recent versions

- 0.2.0 (latest) — 2018-09-11
- 0.1.2 — 2018-09-05
- 0.1.1 — 2018-09-05
- 0.1.0 — 2018-09-05

## README

# kaku-rest
[![CircleCI](https://circleci.com/gh/michadenheijer/kaku-rest-api.svg?style=svg&circle-token=e06c27eac7c9cff5ba9283b447023246fe4f204e)](https://circleci.com/gh/michadenheijer/kaku-rest-api)

A REST-api for KlikAanKlikUit (CoCo) devices using NodeJS.

## Requirements
To use this API, you have to connected a generic 433-mhz transmitter to your Raspberry Pi (3). The data-port has to be connected to the physical pin 11.

## Installation
### Step 1: Download the project
#### Using npm
Downloading and installing using npm is the easiest installation method.
```
npm i kaku-rest -g
```
You can skip the from source method.
#### From source
```
git clone https://github.com/michadenheijer/kaku-rest-api.git
```
Go to the downloaded folder:
```
cd kaku-rest-api
```
Install the project:
```
sudo npm install -g
```
### Step 2: Locate the setup folder
First run the program, it will stop afer a few seconds, but it will create the needed files and folders.
```
kaku-rest
```
Then change to the setup folder
```
cd ~/.kaku-rest
```
Copy the device example
```
cp devices.example.json devices.json
```
Add your own devices, using the nano command:
```
nano devices.json
```
### Step 3: Add your devices
To add your devices change the ```devices.json``` file:
```
nano devices.json
```
You should see a file like this:
```
{
	"devices": ["light", "switch", "christmas-tree"],
	"light": {
		"address": 1592,
		"device": 2
	},
	"switch": {
		"address": 1593,
		"device": 3
	},
	"christmas-tree": {
		"address": 1594,
		"device": 4
	}

}
```
After ```"devices"``` there are your switches written down. The settings of your devices are below there. Every device is defined like this:
```
"light": {
  "address": 1592,
  "device": 2
}
```
First is the name, below the device address and below that the device id.
The device address is a number. If you know your device address you can fill it in (you can skip step 5), most often you don't so just fill in a number between ```1000``` and ```9000```.
The device id should ideally be a number that you won't use for the other devices.

Change the names, device addresses and id's and save the file using:
```
Ctrl^X
```
It'll ask to save and press ```y```. Followed by an ```enter```.
### Step 4: Learn your devices to respond
At this moment your devices do NOT yet respond to your commands. But you can teach them to do so. First, run the server using:
```
kaku-rest
```
Then unplug your switches and replug them, using an other terminal run (the learning fase is only in the first 6 seconds, so it might require some running):
```
curl -X POST http://localhost:8081/THE-DEVICENAME-YOU-JUST-UNPLUGGED/on
```
If it worked the switch will click 4 times and your device can be turned on using the previous command. If you want to turn your device off, use:
```
curl -X POST http://localhost:8081/THE-DEVICENAME/off
```
You can see the status of your devices using the command:
```
curl http://localhost:8081/status
```
This command uses a system that, saves the old commands, so it cannot see changes using an other remote.
To view the status of one device use
```
curl http://localhost:8081/THE-DEVICENAME
```
At this moment the rest-api is only accessible for the ```localhost```.
## Credits
Using the [kaku-rpi](https://github.com/robertklep/node-kaku-rpi) module from [Robert Klep](https://github.com/robertklep).

---
_Source: https://npm.io/package/kaku-rest · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
