Page 1 of 1

monitoring Toon 2 humidity sensor

Posted: Sat Oct 22, 2022 10:17 pm
by ikookmaar
Hi Toon experts!
Does anyone know if / where the Toon 2 's humidity sensor can be read remotely?
Is the humidity percentage visible at some sort of URL and can it be retrieved biy some json string (so I can show it in Domoticz)?
Thanks in advance...

Re: monitoring Toon 2 humidity sensor

Posted: Sat Oct 22, 2022 10:47 pm
by ikookmaar
Oh, just found http://my.toon2.ip.adress/tsc/sensors:
{"temperature":18.1, "humidity":77.2, "tvoc":892, "eco2":2087, "intensity":0}
Now let's find out how to get the humidity value into Domotcz...

Re: monitoring Toon 2 humidity sensor

Posted: Sun Oct 23, 2022 9:59 am
by madpatrick
Maybe this will help you.
It is a Dzvents script (not tested, because it is a snip from my total Toon script)
viewtopic.php?p=100776&hilit=script#p100776

Code: Select all

local ToonTempHum           = 588                                           --   Vochtsensor ID
return {
        on          = { timer = {'every minute'},
                        },
    
        logging     = { level = domoticz.LOG_ERROR, -- change to domoticz.LOG_ERROR when all OK
                        marker      = scriptVar 
                        },
       		 	   
execute = function(domoticz)
        local ToonIP                = domoticz.variables('UV_ToonIP').value         --   IP address of your Toon

-- Vochtsensor
        local handle3 = assert(io.popen(string.format('curl http://%s//tsc/sensors', ToonIP)))
        local TSCsensors = handle3:read('*all')
        handle3:close()
        jsonTSCsensors = json:decode(TSCsensors)

-- Update the BoilerMoisture sensor to current value
        local TSCsensors_hum = tonumber(jsonTSCsensors.humidity)
        local TSCsensors_temp = tonumber(jsonTSCsensors.temperature)
        domoticz.devices(ToonTempHum).updateTempHum(TSCsensors_temp,TSCsensors_hum).silent()

   end
}
2022-10-23 10_00_17-Domoticz - Temperatuur.png
2022-10-23 10_00_17-Domoticz - Temperatuur.png (13.36 KiB) Viewed 5076 times

Re: monitoring Toon 2 humidity sensor

Posted: Mon Oct 24, 2022 1:50 am
by ikookmaar
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
}

Re: monitoring Toon 2 humidity sensor

Posted: Mon Oct 24, 2022 3:08 pm
by madpatrick
You need to use the Temp+Hum sensor type as a virtual switch

P.S. can you use <code> when posting a part of the script.
See </> button above the text box

Code: Select all

Makes it more readable.....