Lua scripts for newbies
Posted: Wednesday 20 April 2016 21:56
Hello guys,
I've been looking around the forum and the wiki for info on lua scripts. I looked at numerous examples, but I'm missing the basic starting steps. Really hope somebody can give me some step by step directions because I can't figure out where to start?
I want to make the following script:
I have a philips hue lamp that I want to control with a philips hue tap and an coco wall switch. The hue lamp and hue tap are already directly connected through the hue bridge and don't make part of the script. What I want is that after I have turned the hue lamp on with the hue tap I can turn the hue lamp off with coco switch with 1 flick of the switch. So the lamp has to be turned off after it receives a off OR a on command of the coco switch (because the coco switch can be in a off or a on position).
Without the script it can be possible you have to flick the switch twice to sent the off command because the switch was already in the off positon
I think this has to be done with a dummy switch. I was thinking of the following scripts:
---turn dummy switch on for a few seconds when coco switch is turned on or off
if ((otherdevices['coco switch'] == 'On') or (otherdevices['coco switch'] == 'Off')) then
(otherdevices['dummy switch'] == 'On') for 3 seconds
end
--check status of the hue lamp and turn it on or off after dummy switched has turned on
if ((otherdevices['hue lamp'] == 'On') and (otherdevices['dummy switch'] == 'On')) then
(otherdevices['hue lamp'] == 'Off')
else if ((otherdevices['hue lamp'] == 'Off') and (otherdevices['dummy switch'] == 'On')) then
(otherdevices['hue lamp'] == 'On')
end
Is this the rightway? And how do I implement this correctly in a lua script that is recognized by Domoticz?
Really hope you can point me in the right directions!
Best regards,
d3rax
I've been looking around the forum and the wiki for info on lua scripts. I looked at numerous examples, but I'm missing the basic starting steps. Really hope somebody can give me some step by step directions because I can't figure out where to start?
I want to make the following script:
I have a philips hue lamp that I want to control with a philips hue tap and an coco wall switch. The hue lamp and hue tap are already directly connected through the hue bridge and don't make part of the script. What I want is that after I have turned the hue lamp on with the hue tap I can turn the hue lamp off with coco switch with 1 flick of the switch. So the lamp has to be turned off after it receives a off OR a on command of the coco switch (because the coco switch can be in a off or a on position).
Without the script it can be possible you have to flick the switch twice to sent the off command because the switch was already in the off positon
I think this has to be done with a dummy switch. I was thinking of the following scripts:
---turn dummy switch on for a few seconds when coco switch is turned on or off
if ((otherdevices['coco switch'] == 'On') or (otherdevices['coco switch'] == 'Off')) then
(otherdevices['dummy switch'] == 'On') for 3 seconds
end
--check status of the hue lamp and turn it on or off after dummy switched has turned on
if ((otherdevices['hue lamp'] == 'On') and (otherdevices['dummy switch'] == 'On')) then
(otherdevices['hue lamp'] == 'Off')
else if ((otherdevices['hue lamp'] == 'Off') and (otherdevices['dummy switch'] == 'On')) then
(otherdevices['hue lamp'] == 'On')
end
Is this the rightway? And how do I implement this correctly in a lua script that is recognized by Domoticz?
Really hope you can point me in the right directions!
Best regards,
d3rax