Page 1 of 1
Scene triggers unwanted a LUA script
Posted: Wednesday 10 February 2016 18:18
by mischa
I have the following script which set on a light based on the dim value of another light. see below
Code: Select all
commandArray = {}
if (otherdevices_svalues['Overloop 1e etage'] > '10' and otherdevices['Trap'] == 'Off') then
commandArray['Trap']='Set Level 1'
elseif
(devicechanged['Overloop 1e etage'] == 'Off') then
commandArray['Trap']='Off'
end
return commandArray
I also have made a "all off" scene with a timer which set all my lights off, but somehow this scene triggers the script above and set the ['Trap'] lights to level 1
I don't understand why this happens, can anyone point me in a direction.
Thanks,
Mischa
Re: Scene triggers unwanted a LUA script
Posted: Wednesday 10 February 2016 19:11
by Westcott
Should it be -
if (tonumber(otherdevices_svalues['Overloop 1e etage']) > 10 and ...
Re: Scene triggers unwanted a LUA script
Posted: Wednesday 10 February 2016 19:28
by mischa
Westcott wrote:Should it be -
if (tonumber(otherdevices_svalues['Overloop 1e etage']) > 10 and ...
This is also working, but my scene still triggers the LUA script.
Don't think it matters using tonumber or the string value, as far as i know the svalues are stored as a string variable.
Re: Scene triggers unwanted a LUA script
Posted: Thursday 11 February 2016 6:59
by Dnpwwo
When a device value is set Domoticz will call 'device' scripts one after the other so if your Scene sets a device state your script will be called. This is expected behavior.
You need to extend your logic to make it only work when you want it to. Something like:
Code: Select all
commandArray = {}
if (devicechanged['Overloop 1e etage'] ~= nil) then
if (otherdevices_svalues['Overloop 1e etage'] > '10' and otherdevices['Trap'] == 'Off') then
commandArray['Trap']='Set Level 1'
elseif
(devicechanged['Overloop 1e etage'] == 'Off') then
commandArray['Trap']='Off'
end
end
return commandArray
Re: Scene triggers unwanted a LUA script
Posted: Thursday 11 February 2016 17:32
by mischa
So if I do not check the device state (as I did in my script) the script will be executed when another device state is changed. Am I understand this correctly?
Re: Scene triggers unwanted a LUA script
Posted: Thursday 11 February 2016 17:48
by mischa
@Dnpwwo If i try your script I get the same behavior when scene is activated, deleted the scene and added again. But still the same behavior.
only my ['Trap'] lights are witched on, the are on a Fibaro RGB module.
Re: RE: Re: Scene triggers unwanted a LUA script
Posted: Thursday 11 February 2016 18:32
by jannl
mischa wrote:So if I do not check the device state (as I did in my script) the script will be executed when another device state is changed. Am I understand this correctly?
Correct
Re: RE: Re: Scene triggers unwanted a LUA script
Posted: Saturday 13 February 2016 9:15
by mischa
jannl wrote:mischa wrote:So if I do not check the device state (as I did in my script) the script will be executed when another device state is changed. Am I understand this correctly?
Correct
Why is it then that only this scene triggers my script and every other device change does not?
Re: Scene triggers unwanted a LUA script
Posted: Saturday 13 February 2016 9:52
by jannl
Every device change triggers every script. Only some exceptions when a script changes a device.