Page 1 of 1
is there something like valuechanged instead of devicechanged in Lua?
Posted: Tuesday 22 November 2016 10:42
by Bram81
Hi,
Is there something like a valuechanged command in LUA which can be used instead of devicechanged? My problem is this. I'm using a a FosBaby camera with thermometer in my babyroom. Through a bash script I collect the current temperature every minute to update a virtual sensor in Domoticz. If the temperature drops below 16C the heating system is turned on.
Right now I use this line
Code: Select all
if (devicechanged['Temperatuur babykamer_Temperature']) < 16 then
commandArray['Verwarming Comfort']='On'
The script is only supposed to run when the temperature changes in a value below 16C and then preferably only once, but because the virtual sensor is updated every minute through a bash in crontab it seems that the update of the sensor is the trigger and not the change of value. Is there someone who knows of a smart workaround or maybe there is something like valuechanged that can be used?
Re: is there something like valuechanged instead of devicechanged in Lua?
Posted: Tuesday 22 November 2016 11:00
by emme
I think you cannot avoid the trigger... but you can set an additional check:
Code: Select all
if ((devicechanged['Temperatuur babykamer_Temperature'] < 16) and (otherdevices['Verwarming Comfort']=='Off')) then
commandArray['Verwarming Comfort']='On'
end
you can even set a global variable with the old value e compare it... but it requires mode code lines...
this, I think, is the smarter way to do that
Re: is there something like valuechanged instead of devicechanged in Lua?
Posted: Tuesday 22 November 2016 11:30
by Egregius
Write the last value from your shell script in a temp file.
Read that temp file in next run to compare new vs old.
Only update domoticz if temp has changed.
Re: is there something like valuechanged instead of devicechanged in Lua?
Posted: Tuesday 22 November 2016 11:58
by emme
it can store the value in a domoticz variable and then trigger an event (variable type)... check and eventually update the virtual temp
Re: is there something like valuechanged instead of devicechanged in Lua?
Posted: Tuesday 22 November 2016 12:06
by Egregius
But then you need on every run a call to domoticz, and when updated another 2 calls.
In shell it's quite easy:
Code: Select all
#!/bin/bash
LASTTEMP=`cat /tmp/lasttemp.txt`
NEWTEMP= DO YOUR STUFF TO GET THE VALUE
if [[ $LASTTEMP -ne $NEWTEMP ]];then
echo $LASTTEMP > /tmp/lasttemp.txt
DOMOTICZ=`curl -s "http://127.0.0.1:8084/json.htm?type=command¶m=udevice&idx=6&nvalue=0&svalue=$NEWTEMP"`
fi
Re: is there something like valuechanged instead of devicechanged in Lua?
Posted: Tuesday 22 November 2016 12:14
by emme
Re: is there something like valuechanged instead of devicechanged in Lua?
Posted: Tuesday 22 November 2016 12:55
by Bram81
Thanks for the quick replies! I guess that the suggestion made by Egregius is my best option. Since the switch 'Verwarming Comfort' is a push button launching a bash to control my thermostat I can't get a status on or off on that one. I'll post my progress later on. Thanks again to the both of you!