Support for Nanoleaf

Hello !

I’ve found a very good deal at Costo"s for the Nanoleaf (9) pack, bought it, installed it, and succefully working with Alexa.

Is there a way to control the Nanoleaf trough the Vera ?

Their website is not very helpful so it is not clear how they communicate. It speaks of an API so one may be able to write a plug-in for Vera if Vera can see it. It also talks of HomeKit so again it appears to be possible to have them controlled by Vera.

Apparently there is an open API.

https://nanoleaf.me/en/consumer-led-lighting/products/smarter-series/nanoleaf-cloud/nanoleaf-local-api/

I’m using lua code, i hope it helps until someone will write a plugin:

On/off aurora

[code]local http=require(“socket.http”)
local auroraToken = “YOUR_TOKEN”;
local siteurl = “http://AURORA_IP:16021/api/v1/”…auroraToken…“/state/on/”
local siteurl1 = “http://AURORA_IP:16021/api/v1/”…auroraToken…“/state/”
local respback = { }
local res, code, response_headers, status = http.request
{
url = siteurl,
method = “GET”,
headers =
{
[“Content-Type”] = “application/json”
},
sink = ltn12.sink.table(respback)
}

if tonumber(code) == 200
then
for key,value in pairs(respback) do
auroraOn = string.match(value, “%a+”, 8)
end
end

if auroraOn == ‘false’
then auroraOn = ‘true’
else
auroraOn = ‘false’
end

local payload = ‘{“on” : {“value”:’…auroraOn…‘}}’
print(payload)

local respback = { }
local res, code, response_headers, status = http.request
{
url = siteurl1,
method = “PUT”,
headers =
{
[“Content-Type”] = “application/json”,
[“Content-Length”] = payload:len()
},
source = ltn12.source.string(payload),
sink = ltn12.sink.table(respback)
}[/code]

Next effect

[code]local http=require(“socket.http”)
local json = require(“dkjson”)
local auroraToken = “YOUR_TOKEN”;
local siteurl = “http://AURORA_IP:16021/api/v1/”…auroraToken…“/effects/effectsList”
local siteurl1 = “http://AURORA_IP:16021/api/v1/”…auroraToken…“/effects/select”
local siteurl2 = “http://AURORA_IP:16021/api/v1/”…auroraToken…“/effects”

– current_effect
local respback = { }
local res, code, response_headers, status = http.request
{
url = siteurl1,
method = “GET”,
headers =
{
[“Content-Type”] = “application/json”
},
sink = ltn12.sink.table(respback)
}

for k, v in pairs(respback) do
auroraCurrentEffect = v
auroraCurrentEffect = string.gsub(auroraCurrentEffect,‘"’,‘’)
break
end

– all effects list
local respback = { }
local res, code, response_headers, status = http.request
{
url = siteurl,
method = “GET”,
headers =
{
[“Content-Type”] = “application/json”
},
sink = ltn12.sink.table(respback)
}

function get_key_for_value(t,value)
for k,v in pairs(t) do
if v == value then return k
end
end
end

function get_value_for_key(t,key)
for k,v in pairs(t) do
if k == key then return v
end
end
end

for k,v in pairs(respback) do
auroraEffectsList = json.decode(v)
auroraEffectsSum = #auroraEffectsList
auroraCurrentId = get_key_for_value(auroraEffectsList,auroraCurrentEffect)
break
end

if auroraCurrentId < auroraEffectsSum then
auroraCurrentId = auroraCurrentId + 1
auroraEffect = get_value_for_key(auroraEffectsList,auroraCurrentId)
else
auroraEffect = 1
auroraEffect = get_value_for_key(auroraEffectsList,auroraEffect)
end

local payload = ‘{“select” :"’…auroraEffect…‘"}’

local respback = { }
local res, code, response_headers, status = http.request
{
url = siteurl2,
method = “PUT”,
headers =
{
[“Content-Type”] = “application/json”,
[“Content-Length”] = payload:len()
},
source = ltn12.source.string(payload),
sink = ltn12.sink.table(respback)
}
[/code]

I couldn’t get the luup code to work. My auth token is correct and I have the IP address. Any ideas? In the test luup code it says code successful so the code is running. I copied and pasted the code as is and put in my IP address and my auth token.

My code is as follows:

local http=require("socket.http")
local auroraToken = "xxxxxxxxxxxxxxxxxxxxxxx";
local siteurl = "http://192.168.x.xx:16021/api/v1/"..auroraToken.."/state/on/"
local siteurl1 = "http://192.168.x.xx:16021/api/v1/"..auroraToken.."/state/"
local respback = { }
  local res, code, response_headers, status = http.request
  {
    url = siteurl,
    method = "GET",
    headers =
    {
      ["Content-Type"] = "application/json"
    },
    sink = ltn12.sink.table(respback)
  }

if tonumber(code) == 200
then
for key,value in pairs(respback) do
auroraOn = string.match(value, "%a+", 8)
end
end

if auroraOn == 'false'
then auroraOn = 'true'
else
auroraOn = 'false'
end

local payload = '{"on" : {"value":'..auroraOn..'}}'
print(payload)

local respback = { }
  local res, code, response_headers, status = http.request
  {
    url = siteurl1,
    method = "PUT",
    headers =
    {
      ["Content-Type"] = "application/json",
      ["Content-Length"] = payload:len()
    },
	source = ltn12.source.string(payload),
    sink = ltn12.sink.table(respback)
  }

Gonna try working on this again today, but was wondering if anyone was looking at building a plug-in.

1 Like

I would have thought this code would work. Anyway, please update us if you make progress. I’d like to tinker with my Nanoleaf too.

I’ve been able to create a batch file that works as well as a python script. Absolutely no luck on luup.

Python script looks like this:

import requests

url = "http://192.168.x.x:16021/api/v1/AUTHTOKEN/state/"

payload = "{\"on\": {\"value\": false}}"
headers = {
    'cache-control': "no-cache",
    'Postman-Token': "861a0138-2bb5-4108-xxx-8622e8ad2daa"
    }

response = requests.request("PUT", url, data=payload, headers=headers)

print(response.text)

Is there any way to send a request to a server to run a python script on a raspberry pi from the Vera?

The code posted by Mobilniy works for me for on/off on my Nanoleaf triangles, but not for the next effect.

This was the only curl command I could get to run to turn them off in Windows:

curl -X PUT -H “Content-Type: application/json” -d “{"value":false}” http://YOURIP:16021/api/v1/YOURTOKEN/state/on

Anyone had more features via the Vera?

But now the same scene to toggle the power no longer works. Bizarre.

I ended up sending an event from Vera to EventGhost to toggle my light switch instead, and running the above curl .bat file from there instead.