simple test going wrong

Moderator: leecollings

Post Reply
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

simple test going wrong

Post 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?
User avatar
boum
Posts: 136
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: simple test going wrong

Post 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...
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: simple test going wrong

Post 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.
User avatar
jvdz
Posts: 2441
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: simple test going wrong

Post 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😉
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: simple test going wrong

Post 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!!
tiga
Posts: 159
Joined: Friday 27 May 2016 20:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: nederland
Contact:

Re: simple test going wrong

Post by tiga »

ps does anyone can help me with this??

viewtopic.php?t=37876
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest