lua script trigger

Moderator: leecollings

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

lua script trigger

Post 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
User avatar
lonebaggie
Posts: 86
Joined: Tuesday 31 January 2017 13:21
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: England
Contact:

Re: lua script trigger

Post 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
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: lua script trigger

Post 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 :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest