Hi all,
I integrated my Nanoleaf lamps without a proper binding and it works fine. ON/OFF, brightness, colors etc. is all working properly. To achieve this a virtual item is required - in my case its name is f0_nanoleaf:
items file:
Color f0_nanoleaf "Nanoleaf" <colorlight> ["Lighting"]
Next a rule is required - within this rule the commands for the virtual color item will be splitted in 4 cases:
- ON
- OFF
- change color
- change brightness
When these commands are detected properly they will be provided to the Nanoleaf API. Therefore a shellscript (nanoleaf.sh) will take care about the webservice requests.
Important: Please do not forget to insert your nanoleaf auth token wihtin the nanoleaf.sh file! To receive your auth token hold the on-off button down for 5-7 seconds until the LED starts flashing in a pattern. Next send a POST request to the authorization endpoint http://NANOLEAFIP/api/v1/new within 30 seconds. As a response you will receive the auth token.
Maybe that helps somebody who likes to integrate his nanoleaf lights into the openhab world
nanoleaf.rules file:
rule "f0_nanoleaf"
when
Item f0_nanoleaf received command
then
logInfo("f0_nanoleaf", "state changed to: " + receivedCommand)
var cmd = "/Users/jakez/openhab/conf/shellscripts/nanoleaf.sh "
switch(receivedCommand) {
case receivedCommand instanceof OnOffType: cmd = cmd + receivedCommand
case receivedCommand instanceof HSBType: cmd = cmd + "COLOR " + receivedCommand.toString.replace(",", " ")
case receivedCommand instanceof PercentType: cmd = cmd + "DIM " + receivedCommand
}
logInfo("nanoleaf", "cmd : " + cmd)
val results = executeCommandLine(cmd, 1000)
//logInfo("nanoleaf", "res: " + results)
end
nanoleaf.sh file:
#!/bin/sh
if [ "$1" = "ON" ]; then
echo "switch on"
curl -X PUT -H "Content-Type: application/json" -d '{"on" : {"value":true}}' "http://10.10.10.166:16021/api/v1/[YOURAPIKEY]/state/"
elif [ "$1" = "OFF" ]; then
echo "switch off"
curl -X PUT -H "Content-Type: application/json" -d '{"on" : {"value":false}}' "http://10.10.10.166:16021/api/v1/[YOURAPIKEY]/state/"
elif [ "$1" = "DIM" ]; then
echo "dim to $2"
curl -X PUT -H "Content-Type: application/json" -d '{"brightness" : {"value":'$2'}}' "http://10.10.10.166:16021/api/v1/[YOURAPIKEY]/state/"
elif [ "$1" = "HUE" ]; then
echo "hue to $2"
curl -X PUT -H "Content-Type: application/json" -d '{"hue" : {"value":'$2'}}' "http://10.10.10.166:16021/api/v1/[YOURAPIKEY]/state/"
elif [ "$1" = "SAT" ]; then
echo "sat to $2"
curl -X PUT -H "Content-Type: application/json" -d '{"sat" : {"value":'$2'}}' "http://10.10.10.166:16021/api/v1/[YOURAPIKEY]/state/"
elif [ "$1" = "COLOR" ]; then
echo "hue to $2"
echo "sat to $3"
echo "dim to $4"
curl -X PUT -H "Content-Type: application/json" -d '{"sat" : {"value":'$3'}, "hue" : {"value":'$2'}, "brightness" : {"value":'$4'}}' "http://10.10.10.166:16021/api/v1/[YOURAPIKEY]/state/"
fi
updated thanks to rlkoshak’s comments!