Page 1 of 1

Blink light

Posted: Thursday 26 June 2014 11:43
by Gergg
hi,

i want to make a blink light to make a meeting reminder but i dont find the sleep command.

like :
commandArray = {}
if (devicechanged['blink_switsh'] == 'On') then
commandArray['blink_switsh']='Off'
commandArray['light']='On'
sleep(10000)
commandArray['light']='off'
end
return commandArray

Some one can help me ?

Ty
Greg

Re: Blink light

Posted: Thursday 26 June 2014 14:42
by CopyCatz
You can't do it that way because the light is not controlled during the time the script runs; the script decides what needs to be done and puts the action in the commandarray which is executed on return. The commandarray does not support intervals. What you can do is "On FOR 1" or "On FOR 0.1" for 6 seconds. A more robust way to do this when the light is dedicated for the meeting signal: put an off delay in the light setting, and only switch it on using the script.

Re: Blink light

Posted: Thursday 26 June 2014 16:39
by Gergg
ok thank you, I'll see to launch another script that will do what I want with curl.

like :

curl 'http://domoticz/json.htm?type=command&p ... &passcode='
...

Re: Blink light

Posted: Sunday 27 July 2014 23:20
by Derik
Is this working??

Like this option to..
Do you please have a code to share?
And perhaps a little support?
Is there a options to switch a dummy so the script is blinking for x seconds?


Thanks...

Wife @ home al light blinking... :D :D :D

Re: Blink light

Posted: Monday 07 September 2015 19:56
by Justintime
Also in search how to let a device blink.

But every post is a dead end. Someone managed to do this?

Re: Blink light

Posted: Monday 07 September 2015 22:34
by Egregius
Could be easy in php. A simple loop that executes x times with sleeps in between.

Re: Blink light

Posted: Tuesday 08 September 2015 7:24
by Egregius
Voila, previous post was on smartphone.
Now on computer:

Code: Select all

<?php
$idx=153;
for ($k = 1 ; $k <= 3; $k++){
	file_get_contents('http://ip:port/json.htm?type=command&param=switchlight&idx='.$idx.'&switchcmd=On');
	sleep(1);
	file_get_contents('http://ip:port/json.htm?type=command&param=switchlight&idx='.$idx.'&switchcmd=Off');
	sleep(1);
}
This will switch the idx on for 1 sec en then of for one second. The loop runs 3 times.
Is a 1 second resolution isn't enough you can also use usleep(500000) for 0,5 sec.

If you're using my php functions it could be as easy as

Code: Select all

<?php
include secure/functions.php
for ($k = 1 ; $k <= 3; $k++){
	Schakel(153,'On');
	sleep(1);
	Schakel(153,'Off');
	sleep(1);
}

Re: Blink light

Posted: Wednesday 11 November 2015 17:21
by BakSeeDaa
Here is my implementation of a "blink light" function.

The function takes 2 parameters.
Parameter 1: The idx of the device to blink
Parameter 2: (Optional) Number of times the device shall blink.

The function also checks if the light is on before the blink occurs, hence the lights initial status won't be altered. The blink length is hard coded to 3 seconds and the time between the blinks is also 3 seconds.

I use it for example when someone pushes the door bell to blink the outdoor lights as a confirmation that the doorbell is working. Without confirmation some people tend to bang the door instead after 10 seconds.

Code: Select all

function blinkLight(light, times)
	times = times or 2
	local cmd1 = 'Off'
	local cmd2 = 'On'
	local pause = 0
	if (otherdevices[light] == 'Off') then
		cmd1 = 'On'
		cmd2 = 'Off'
	end	
	for i = 1, times do
		commandArray[#commandArray + 1]={[light]=cmd1..' AFTER '..pause }
		pause = pause + 3
		commandArray[#commandArray + 1]={[light]=cmd2..' AFTER '..pause }
		pause = pause + 3
	end
end
Use it like this:

Code: Select all

blinkLight(53, 3) -- blink device 53 3 times
or just like this:

Code: Select all

blinkLight(53) -- blink device 53 the default number of times (which is 2)

Re: Blink light

Posted: Saturday 26 March 2016 17:57
by Xroads
Hi
As a really new user of Domoticz, I would like to use BakSeeDaa's function to blink a light.
But where do I put the function, is it in a lua script or?

Re: Blink light

Posted: Saturday 26 March 2016 18:21
by oliviers
Hi,

You could also just use a stroboscopic flash like this one:

http://www.conrad.fr/ce/fr/product/7531 ... archDetail

With a RFX433 or ZWAVE outlet ... You just need to turn it ON and OFF ... No scripts ! I use two of those personally.

Oliviers

Re: Blink light

Posted: Saturday 26 March 2016 19:53
by Xroads
Yes I could, but its only for my doorbell, so maybee a bit overkill :D

Re: Blink light

Posted: Sunday 27 March 2016 15:28
by Xroads
Ok, found out that it's for a lua script.
But now the only thing i'm getting is a error message.
Error: EventSystem: commandArray in script /home/pi/domoticz/scripts/lua/script_device_doorbell.lua should only return ['string']='actionstring' or [integer]={['string']='actionstring'}

This is the code I'm using, please anyone

Code: Select all

commandArray = {}

function blinkLight(light, times)
   times = times or 2
   local cmd1 = 'Off'
   local cmd2 = 'On'
   local pause = 0
   if (otherdevices[light] == 'Off') then
      cmd1 = 'On'
      cmd2 = 'Off'
   end   
   for i = 1, times do
      commandArray[#commandArray + 1]={[light]=cmd1..' AFTER '..pause }
      pause = pause + 3
      commandArray[#commandArray + 1]={[light]=cmd2..' AFTER '..pause }
      pause = pause + 3
   end
end

if (devicechanged['Doorbell'] == 'On') then
	blinkLight(75) -- blink device 75 the default number of times (which is 2)
	
end

return commandArray

Re: Blink light

Posted: Thursday 11 August 2016 18:43
by davewins
I just got this working, and you need to change the device ID (75) to the name of the device e.g. "Lamp",

so you change the BlinkLight line to be:

blinkLight("Lamp")

hope it helps.

Re: Blink light

Posted: Friday 12 January 2018 23:06
by chatainsim
Just found this in the wiki:

Code: Select all

   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
https://www.domoticz.com/wiki/LUA_commands

I don't know which version you need.

Re: Blink light

Posted: Wednesday 04 July 2018 13:49
by gemminiss
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!! :D

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!

Re: Blink light

Posted: Sunday 21 July 2019 16:11
by Eyedon
Hi,

What I want is to trigger multiple devices at once to blink. I made a dummy button and use the Lua script above as basic script. Unfortunately the blink frequency is very instable for each device. I want to trigger on/off all the lights at once with the same frequency.

Device: Zwave switches / Raspberry pi
Purpose: let all the lights in the house blink stable: the same time, the same frequency

Hope someone can give me an advice...

Script:

Code: Select all

commandArray = {}

if (devicechanged['Knipperen'] == 'On') then
   
   if(otherdevices['Verlichting_begane_grond_Woonkamer']== 'Off') then
    commandArray['Verlichting_begane_grond_Woonkamer'] = "On FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS" 

    else
    commandArray['Verlichting_begane_grond_Woonkamer'] = "Off FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS"

    end


   if(otherdevices['Verlichting_begane_grond_keuken']== 'Off') then
    commandArray['Verlichting_begane_grond_keuken'] = "On FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS" 

    else
    commandArray['Verlichting_begane_grond_keuken'] = "Off FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS"

    end

   if(otherdevices['Verlichting_eerste_verdieping_Overloop']== 'Off') then
    commandArray['Verlichting_eerste_verdieping_Overloop'] = "On FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS" 

    else
    commandArray['Verlichting_eerste_verdieping_Overloop'] = "Off FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS"

    end

   if(otherdevices['Verlichting_buitenlamp_achterdeur']== 'Off') then
    commandArray['Verlichting_buitenlamp_achterdeur'] = "On FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS" 

    else
    commandArray['Verlichting_buitenlamp_achterdeur'] = "Off FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS"

    end

   if(otherdevices['Verlichting_begane_grond_Hal']== 'Off') then
    commandArray['Verlichting_begane_grond_Hal'] = "On FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS" 

    else
    commandArray['Verlichting_begane_grond_Hal'] = "Off FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS"

    end


   if(otherdevices['Verlichting_tweede_verdieping_Overloop']== 'Off') then
    commandArray['Verlichting_tweede_verdieping_Overloop'] = "On FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS" 

    else
    commandArray['Verlichting_tweede_verdieping_Overloop'] = "Off FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS"

    end

   if(otherdevices['Verlichting_buitenlamp_schuur']== 'Off') then
    commandArray['Verlichting_buitenlamp_schuur'] = "On FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS" 

    else
    commandArray['Verlichting_buitenlamp_schuur'] = "Off FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS"

    end

   if(otherdevices['Verlichting_tweede_verdieping_Zolderkamer_Dakopbouw']== 'Off') then
    commandArray['Verlichting_tweede_verdieping_Zolderkamer_Dakopbouw'] = "On FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS" 

    else
    commandArray['Verlichting_tweede_verdieping_Zolderkamer_Dakopbouw'] = "Off FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS"

    end

   if(otherdevices['Verlichting_tweede_verdieping_Zolderkamer_Dakkapel']== 'Off') then
    commandArray['Verlichting_tweede_verdieping_Zolderkamer_Dakkapel'] = "On FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS" 

    else
    commandArray['Verlichting_tweede_verdieping_Zolderkamer_Dakkapel'] = "Off FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS"

    end


end
return commandArray



Re: Blink light

Posted: Monday 22 July 2019 22:31
by Eyedon
Hi,

I solved it myself using a group and the script below. The swithes don't work perfectly synch, but I can live with the result.

grtz

Code: Select all

commandArray = {}

if (devicechanged['Knipperen'] == 'On') then
   
   if(otherdevices['Verlichting_buitenlamp_schuur']== 'Off') then
    commandArray['Group:Knippergroep'] = "On FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS" 

    else
    commandArray['Group:Knippergroep'] = "Off FOR 2 SECONDS REPEAT 10 INTERVAL 4 SECONDS"
    end

end
return commandArray