28.11.2017, 10:53
Thanks for your answer, but it doesn't work, I think my script is bad I've only paste your answer after an other script from you about nest thermostat:
"
function request()
local auth, url, res, stat, hdrs
require('json')
require('ssl.https')
auth = '...'
url = 'https://developer-api.nest.com/devices.json?auth=' .. auth
res, stat, hdrs = ssl.https.request(url)
if stat == 307 then
res = ssl.https.request(hdrs.location)
end
return json.decode(res)
end
res, data = pcall(request)
log(data)
alarms = data['smoke_co_alarms']['sgUHZf.....APJP7e2-z........Y']
co_alarm_ok = alarms['co_alarm_state'] == 'ok'
grp.update('1/1/1', co_alarm_ok, dt.bool)
"
But I think it's not the good way .. I have to create an other script ? or an other variable ?
"
function request()
local auth, url, res, stat, hdrs
require('json')
require('ssl.https')
auth = '...'
url = 'https://developer-api.nest.com/devices.json?auth=' .. auth
res, stat, hdrs = ssl.https.request(url)
if stat == 307 then
res = ssl.https.request(hdrs.location)
end
return json.decode(res)
end
res, data = pcall(request)
log(data)
alarms = data['smoke_co_alarms']['sgUHZf.....APJP7e2-z........Y']
co_alarm_ok = alarms['co_alarm_state'] == 'ok'
grp.update('1/1/1', co_alarm_ok, dt.bool)
"
But I think it's not the good way .. I have to create an other script ? or an other variable ?