SOLVED
Hello everyone, I'm new to this forum and I would like to share something with you:
I just wanted to make a light blinking when another device was 'On'. As I have low programming skills, I tried to find an existing script in this forum already doing the job (LUA, Python, PHP), unfortunately, I got so many errors and problems, that I was close to give up.
Well, I did so much reading and testing that finally I learnt a little bit of LUA. Today I tried to do a script by myself, and it worked!!
The solution I found is so simple and easy that I have the impression that I'm missing something, it can not be so easy...(expert developer comments are welcomed)
HERE WE GO
Let's consider:
Device 'A' as trigger ( can be dummy switch, door Sensor, motion detector)
Device 'B' as the device we want it blinks (Another Dummy switch, a real siren, a Light dimmer...)
1st Step:
Go to Domoticz Event Editor, and create à new event with:
Event name: Blink Test
Second Box: Lua
Third box: device
Activate: Event Active (check box)
2nd Step
In the Left Editor, paste this:
Code: Select all
commandArray = {}
if (devicechanged['A'] == 'On') then
if(otherdevices['B']== 'Off') then
commandArray['B'] = "On FOR 3 SECONDS REPEAT 5 INTERVAL 6 SECONDS"
else
commandArray['B'] = "Off FOR 3 SECONDS REPEAT 5 INTERVAL 6 SECONDS"
end
end
return commandArray
3rd Step
Replace 'A' and 'B', by the Name's of your Device's you want to use instead. (We need the Name, NOT the Idx)
Save the Event and test it !!
For the test I did simple:
I created a Dummy switch (Switch 'A'), and I set as Switch 'B', my room's light (controlled by a Fibaro Dimmer 2), and It Works!,
The comment of
chatainsim gave me the idea (Thanks!!), he was right: in
https://www.domoticz.com/wiki/LUA_commands
There is a list of several possibilities of sending instructions with commandArray:
Code: Select all
commandArray['MyOtherDeviceName5']='Off RANDOM 30' -- random within x minutes
commandArray['MyOtherDeviceName6']='On REPEAT 5 INTERVAL 5' -- command will be repeated 5 times with 5 seconds interval
commandArray['MyOtherDeviceName7'] = "On FOR 2 SECONDS REPEAT 9 INTERVAL 4 SECONDS" -- every 4 seconds and do that 9 times, put device On for 2 seconds
For my test, I used the 3rd case but modifying the values. My dimmable LED bulbs need some time to get up 100% and then down to 0%. I've tried with:
"On FOR 1 SECONDS REPEAT 3 INTERVAL 2 SECONDS" , to have a Flash Effect...but it seems that it's too fast for the bulbs and/or the Fibaro Dimmers, they stay 'On' all along the cycle.
Regarding the code:
I had to add a 2nd IF:
if(otherdevices['B']== 'Off') else , because of:
1 - I want than at the end of the cycle the light gets back to the original state.
2 - I experimented (With the Fibaro Dimmer 2) that if the light was already 'On', sending a cycle of several 'On' the light stayed ''physically'' always 'On' , that's why I'm sending a cycle of several 'Off'
3 - I do not know, if a dimmer at 30% it is considered as 'On'. That's why saying that whatever else than 'Off', it is 'On'.
Well, Try it and let me know, all comments are welcomed!