Wow, thanks.
I did some research and after lots of trial and error got this to update an perccentage switch.
But your script seems much nicer and combines temperature and humidity into one device...
local scriptVar = 'humidityRetrieved'
return
{
on =
{
timer =
{
'every 5 minutes' -- to trigger the request
},
-- devices =
-- {
-- 'JSONTrigger' -- to trigger the request during development / test
-- },
httpResponses =
{
scriptVar, -- must match with the callback passed to the openURL command
},
},
logging =
{
level = domoticz.LOG_INFO,
marker = scriptVar,
},
execute = function(dz, item)
if item.isTimer or item.isDevice
then
dz.openURL(
{
url = '
http://my-toon-ip/tsc/sensors',
method = 'GET',
callback = scriptVar, -- see httpResponses above.
})
else
if item.ok then
myJSON = ( item.isJSON and item.json ) or dz.utils.fromJSON(item.data) -- JSON to Lua table ( also when not recognized as JSON )
if _G.logLevel == dz.LOG_DEBUG then
dz.utils.dumpTable(myJSON) -- show structure of converted JSON -- ( only for debug )
end
local humidityValue = dz.utils.round(myJSON["humidity"], 0)
dz.log("Toon luchtvochtigheid = ".. humidityValue .. "%",dz.LOG_DEBUG)
-- update Toon Humidity device in DomotiZ
dz.devices('Toon luchtvochtigheid').updatePercentage(humidityValue)
else
dz.log('There was a problem handling the request', dz.LOG_ERROR)
dz.log(item, dz.LOG_ERROR)
end
end
end
}