is there something like valuechanged instead of devicechanged in Lua?

Moderator: leecollings

Post Reply
Bram81
Posts: 22
Joined: Saturday 02 May 2015 11:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Utrecht, NL
Contact:

is there something like valuechanged instead of devicechanged in Lua?

Post 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?
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: is there something like valuechanged instead of devicechanged in Lua?

Post 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
The most dangerous phrase in any language is:
"We always done this way"
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: is there something like valuechanged instead of devicechanged in Lua?

Post 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.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: is there something like valuechanged instead of devicechanged in Lua?

Post 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
The most dangerous phrase in any language is:
"We always done this way"
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: is there something like valuechanged instead of devicechanged in Lua?

Post 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&param=udevice&idx=6&nvalue=0&svalue=$NEWTEMP"`
fi
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: is there something like valuechanged instead of devicechanged in Lua?

Post by emme »

;) ....so... it's time for me to learn bash scripting also :lol: :lol: :lol:
The most dangerous phrase in any language is:
"We always done this way"
Bram81
Posts: 22
Joined: Saturday 02 May 2015 11:00
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.9700
Location: Utrecht, NL
Contact:

Re: is there something like valuechanged instead of devicechanged in Lua?

Post 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!
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest