Page 1 of 1

lua script trigger

Posted: Sunday 03 September 2017 16:42
by tiga
i have this lua script i made

Code: Select all

commandArray = {}
 
if (devicechanged['zonnescherm'] == 'On' and otherdevices['auto omhoog zonnescherm ondergang'] == 'On' and otherdevices['telefoon 1'] == 'Off' and otherdevices['telefoon 2'] == 'Off') then
    commandArray['auto zonnescherm omhoog']='Active'
    print ('zonnescherm gaat vanzelf omhoog')
else
    commandArray['auto zonnescherm omhoog']='Inactive'
    print ('zonnescherm gaat niet vanzelf omhoog')
    end
    
return commandArray
i run it in DEVICE mode
but it gets triggerd every vew seconds.

i want it to run only when one of the devices is changed in state.

i use it to close my "zonnescherm" 30 minutes befor sunset

Re: lua script trigger

Posted: Sunday 03 September 2017 18:23
by lonebaggie
Use a dzVents script and trigger it to start a 30 mins before sunset

see

http://www.domoticz.com/forum/viewtopic.php?t=19171

Re: lua script trigger

Posted: Sunday 03 September 2017 23:13
by Nautilus
I think the biggest problem in your script is the "else"-part. You have basically told the script to run on each device change and execute one of the two parts of the script. The first part is executed only when the changed device is 'zonnescherm' and it changes to 'On' and the second part (= else) is then run in all other cases (= every time a device changes its state except if it is 'zonnescherm' turning 'On').

So, you need to think in which situation you want to run the second part:

Code: Select all

else
    commandArray['auto zonnescherm omhoog']='Inactive'
    print ('zonnescherm gaat niet vanzelf omhoog')
    end
And come up with proper condition. That said, I don't quite understand how this script relates to "i use it to close my "zonnescherm" 30 minutes befor sunset" - I guess you are you triggering that with a normal device timer? Maybe something like this would work:

Code: Select all

commandArray = {}
 
if (devicechanged['zonnescherm'] == 'On' and otherdevices['auto omhoog zonnescherm ondergang'] == 'On' and otherdevices['telefoon 1'] == 'Off' and otherdevices['telefoon 2'] == 'Off') then
    commandArray['auto zonnescherm omhoog']='Active'
    print ('zonnescherm gaat vanzelf omhoog')
elseif devicechanged['zonnescherm'] == 'Off' then
    commandArray['auto zonnescherm omhoog']='Inactive'
    print ('zonnescherm gaat niet vanzelf omhoog')
end
    
return commandArray
...but you might need to define it even more strictly than this - depending when you want it to run :)