Simple REST API to control magic-home lights on the same network, built with magic-home and express.
- Pull the latest version using
docker pull casperverswijvelt/magic-home-rest:latest
- Run the image using
docker run --net=host --env PORT=3001 casperverswijvelt/magic-home-rest
(Customize port to your liking)
- Clone this repository
- Make sure NPM/Node is installed
- Run
npm ci
- Run
npm start
Gets a list of magic-home devices on the network
URL : /api/devices/
Method : GET
Code : 200 OK
Content example
[
{
"address": "192.168.69.198",
"id": "F4CFA2120867",
"model": "AK001-ZJ2101"
}
]
Gets a the state of a magic-home device, by it's id
URL : /api/device/:id
Method : GET
Code : 200 OK
Content example
{
"type": 51,
"on": true,
"mode": "color",
"speed": 66.66666666666667,
"color": {
"red": 255,
"green": 255,
"blue": 0
},
"warm_white": 0,
"cold_white": 0
}
Change the color of a magic-home device, by it's address or id.
URL : /api/color/
Method : POST
Data constraints
If no id or address is provided, all lights on the network will receive this change.
{
"id": "id of magic-home device, string, optional",
"address": "address of magic-home device, string, optional",
"color": "color to change to, string (hex) or number (decimal), required",
"brightness": "brightness to adjust the color with, number, optional"
}
Data example
{
"id": "F4CFA2120867",
"address": "192.168.69.198",
"color": "#FF0000", // or "FF0000" or 16711680
"brightness": "100"
}
Condition : Color commands were sent
Code : 200 OK
Change the power state of a magic-home device, by it's address or id.
URL : /api/power/
Method : POST
Data constraints
If no id or address is provided, all lights on the network will receive this change.
{
"id": "id of magic-home device, string, optional",
"address": "address of magic-home device, string, optional",
"power": "power state to set, required"
}
Data example
{
"id": "F4CFA2120867",
"address": "192.168.69.198",
"power": false
}
Condition : Power commands were sent
Code : 200 OK
Activate an effect on a magic-home device, by it's address or id.
URL : /api/effect/
Method : POST
Data constraints
If no id or address is provided, all lights on the network will receive this change.
See this repository for a list of patterns.
{
"id": "id of magic-home device, string, optional",
"address": "address of magic-home device, string, optional",
"effect": "effect pattern to set, required",
"speed": "speed of the effect, number of 1 - 100, optional"
}
Data example
{
"id": "F4CFA2120867",
"address": "192.168.69.198",
"effect": "seven_color_cross_fade",
"speed": 50
}
Condition : Effect commands were sent
Code : 200 OK