Page 1 of 1

Lua triggerd very often

Posted: Wednesday 25 January 2017 16:52
by TimH
Hi there,

i have wrote a LUA scripte. You can see this below.
My Problem is the Script is triggerd very often. The Temperature isn't changed in this time. The Setpoint devices is the same Danfoss LC-13
I have attached the log below two.
Why is it triggerd so often.

Code: Select all

local act_time = os.date("%H:%M")

commandArray = {}
if ((otherdevices['Esszimmer Heizung']~='16') or (otherdevices['Wohnzimmer Heizung 1']~='16')) and (otherdevices['Wohnzimmer Heizung']=='17°C') then
    commandArray[1]={['UpdateDevice']="48|0|16"}
    commandArray[2]={['UpdateDevice']="50|0|16"}
    print("Heizung auf 16°C eingestellt")
elseif ((otherdevices['Esszimmer Heizung']~='23') or (otherdevices['Wohnzimmer Heizung 1']~='23')) and (otherdevices['Wohnzimmer Heizung']=='23°C') then
    print(otherdevices['Wohnzimmer Heizung 1'])
    print(otherdevices['Esszimmer Heizung'])
    commandArray[1]={['UpdateDevice']='50|0|23'}
    commandArray[2]={['UpdateDevice']='48|0|23'}
    commandArray[3]={['Variable:Heizungschalten']=act_time}
    print("Heizung auf 23°C eingestellt")
end
return commandArray
LOG FIle:

Code: Select all

2017-01-25 16:38:42.288 User: Tim initiated a switch command (22/Anwesenheit/Off)
2017-01-25 16:43:09.549 LUA: 23
2017-01-25 16:43:09.549 LUA: 23.00
2017-01-25 16:43:09.549 LUA: Heizung auf 23°C eingestellt
2017-01-25 16:43:09.553 EventSystem: Script event triggered: Heizungneu
2017-01-25 16:43:09.739 LUA: 23
2017-01-25 16:43:09.739 LUA: 23.00
2017-01-25 16:43:09.739 LUA: Heizung auf 23°C eingestellt
2017-01-25 16:43:09.744 EventSystem: Script event triggered: Heizungneu
2017-01-25 16:43:15.778 LUA: 23.00
2017-01-25 16:43:15.779 LUA: 23
2017-01-25 16:43:15.779 LUA: Heizung auf 23°C eingestellt
2017-01-25 16:43:15.784 EventSystem: Script event triggered: Heizungneu
2017-01-25 16:43:15.979 LUA: 23.00
2017-01-25 16:43:15.979 LUA: 23
2017-01-25 16:43:15.979 LUA: Heizung auf 23°C eingestellt
2017-01-25 16:43:15.984 EventSystem: Script event triggered: Heizungneu
2017-01-25 16:43:50.799 EventSystem: reset all events...
2017-01-25 16:48:12.131 LUA: 23.00
2017-01-25 16:48:12.131 LUA: 23
2017-01-25 16:48:12.132 LUA: Heizung auf 23°C eingestellt
2017-01-25 16:48:12.135 EventSystem: Script event triggered: Heizungneu
2017-01-25 16:48:12.322 LUA: 23.00
2017-01-25 16:48:12.322 LUA: 23
2017-01-25 16:48:12.322 LUA: Heizung auf 23°C eingestellt
2017-01-25 16:48:12.327 EventSystem: Script event triggered: Heizungneu

Re: Lua triggerd very often

Posted: Wednesday 25 January 2017 18:33
by jvdz
You are not doing a numeric test but alphanumeric. Just do a numeric compare like:

Code: Select all

elseif ((tonumber(otherdevices['Esszimmer Heizung'])~=23) or (tonumber(otherdevices['Wohnzimmer Heizung 1'])~=23)) and (otherdevices['Wohnzimmer Heizung']=='23°C') then
I am assuming that the result of otherdevices['Wohnzimmer Heizung'] really is something as you test with '23°C'.

Jos

Re: Lua triggerd very often

Posted: Wednesday 25 January 2017 19:08
by simonrg
TimH wrote:Hi there,

i have wrote a LUA scripte. You can see this below.
My Problem is the Script is triggerd very often. The Temperature isn't changed in this time. The Setpoint devices is the same Danfoss LC-13
I have attached the log below two.
Why is it triggerd so often.
Assuming this is a device script i.e. script_device_setpoint.lua, then the script will be triggered every time any device changes.

Hence the use of deviceChanged to see if the device you are interested in has changed or not:

Code: Select all

local act_time = os.date("%H:%M")

commandArray = {}
if deviceChanged['Temperature Sensor'] then
     -- all your code with the temperature tests and acitons
end
return commandArray
This way the script will only check temperature differences when the temperature device has changed

Re: Lua triggerd very often

Posted: Thursday 26 January 2017 8:24
by TimH
jvdz wrote:You are not doing a numeric test but alphanumeric. Just do a numeric compare like:

Code: Select all

elseif ((tonumber(otherdevices['Esszimmer Heizung'])~=23) or (tonumber(otherdevices['Wohnzimmer Heizung 1'])~=23)) and (otherdevices['Wohnzimmer Heizung']=='23°C') then
I am assuming that the result of otherdevices['Wohnzimmer Heizung'] really is something as you test with '23°C'.

Jos
Yes thats it. That works for me. The Switch Wohnzimmer Heizung is a Selector switch an there are select with 23°C.
The idea from simonrg is also good.
I Think i try with another heater when it's manually changed.

Thanks everybody