Page 1 of 1

Humidity dummy sensor

Posted: Friday 13 May 2016 8:55
by Swokey
I'm trying to update an dummy sensor with the current humidity from a Cresta TX320

I'have the following lua script:

Code: Select all

--script_device_Tempdroogkast.lua
local sensorcr = 'Cresta' --name of the sensor that gets created when you add t$
local idx = 189 --idx of the humidity sensor you created for scrapping the temp$
commandArray = {}

if devicechanged[sensorcr] then
   sCrestaTemp, sCrestaHumidity = otherdevices_svalues[sensorcr]:match("([^;]+)$
   sCrestaHumidity = tonumber(sCrestaHumidity)
   commandArray['UpdateDevice'] = idx .. '|0|' .. (sCrestaHumidity)
   print("Droogkast luchtvochtigheid is " .. sCrestaHumidity .. "% ");
end
return commandArray
----------

The log file gives me the following back:
2016-05-13 08:52:36.065 LUA: Droogkast luchtvochtigheid is 63%
2016-05-13 08:53:19.067 EventSystem: Script event triggered: /home/swokey/domoticz/scripts/lua/script_device_humdroogkast.lua

So the script is executed, but the 'last seen' of the device (189) is then also 8:53 only the humidity is 0%

Any idea why the humidity isn't updated?

Re: Humidity dummy sensor

Posted: Friday 13 May 2016 10:05
by Swokey
I'm also trying to do it with JSON, but i don't understand how to add that in LUA.

When I execute the following url (http://192.168.2.21:8080/json.htm?type= ... &nvalue=25) within a browser the dummy sensor is updated.

How can I add this (with variable sCrestaHumidity) to LUA?

Re: Humidity dummy sensor

Posted: Friday 13 May 2016 13:23
by Swokey
I solved it with JSON, see below code for someone who is looking for the same:

Code: Select all

--script_device_Tempdroogkast.lua
local sensorcr = 'Cresta' --name of the sensor that gets created when you add the Cresta device (and that contains multiple values like temperature, humidi$
local idx = 189 --idx of the virtual temperature sensor you created for scrapping the temperature
commandArray = {}

if devicechanged[sensorcr] then
   sCrestaTemp, sCrestaHumidity = otherdevices_svalues[sensorcr]:match("([^;]+);([^;]+)")
   sCrestaHumidity = tonumber(sCrestaHumidity)
   commandArray['OpenURL'] = 'http://192.168.2.21:8080/json.htm?type=command&param=udevice&idx=189&nvalue='..sCrestaHumidity..''
   print("Droogkast luchtvochtigheid is " .. sCrestaHumidity .. "% ");
end
return commandArray

Re: Humidity dummy sensor

Posted: Tuesday 28 November 2017 16:24
by AlwinHummels
Looks very impressive, can ik also reverse? To dummy temp only? I use it for my refrigeratorson 😃 so I only need the temperature.