Page 1 of 1

simple test going wrong

Posted: Saturday 12 March 2022 20:51
by tiga
i made a script but i dont get it to work so i made a little test to see what is going wrong.

i made a simple lua script to test:

Code: Select all

commandArray = {}

if devicechanged['dimmertest'] == 'Set Level: 90 %' then
    commandArray['lamp huis'] = 'On'
    print ("lamp huis is aan")
end

if devicechanged['dimmertest'] ~= 'Set Level: 90 %' then
    commandArray['lamp huis'] = 'Off'
    print ("lamp huis is uit")
    end

return commandArray
i run the script on "device"
"dimmertest" is a virtual dimmer i made to do this test.

the On part works perfect.
but the Off part gets triggerd every second or so....i do not understand why becouse i have the lua set on "device"
how can i fix this?

Re: simple test going wrong

Posted: Saturday 12 March 2022 21:39
by boum
A "device" script is triggered every time any device change.
So you must first guard your script against triggers from other devices:

Code: Select all

commandArray = {}

local dimmerChanged = devicechanged['dimmertest']
if not dimmerChanged then return commandArray end -- early exit if triggered from another device

if dimmerChanged == 'Set Level: 90 %' then
-- rest of the script...

Re: simple test going wrong

Posted: Saturday 12 March 2022 21:49
by tiga
i did not know a device script triggers on ANY device....i thought it only triggered on the device after the "devicechanged"

strangely the script is triggerd once on the "On" condition
but allmost every second on the "Off" condition.

Re: simple test going wrong

Posted: Saturday 12 March 2022 22:29
by jvdz
Nope.. the script is triggered on each device change and your second if is always true for any device triggered!
Just think about it for a little😉

Re: simple test going wrong

Posted: Saturday 12 March 2022 22:58
by tiga
thank you verry much.i did not know that.

i have tested the script and now works well!

i have to change my way of thinking but it makes sense now.

thank you all for the help!!

Re: simple test going wrong

Posted: Saturday 12 March 2022 23:06
by tiga
ps does anyone can help me with this??

viewtopic.php?t=37876