help needed to let RGB device "blink"

Tips, Tricks and Scripts to enhance your home automation and workaround known device bugs, limitations and incompatibilities
Post Reply
Karsten
Posts: 34
Joined: 09 May 2016 20:06

help needed to let RGB device "blink"

Post by Karsten »

Hello,
searching for a way to let indicator LED (night light mode) of an Aeotech Smart Dimmer 6 "blink".
Already managed to control LED by API like:

Code: Select all

/ZAutomation/api/v1/devices/ZWayVDev_zway_9-0-51-rgb/command/exact?red=255&green=0&blue=0
Also made code devices (toggle button) to activate different LED colors / brightness levels with:
a)

Code: Select all

var dev = controller.devices.get( 'ZWayVDev_zway_9-0-51-rgb'); dev.performCommand( 'exact', { red: 255, green: 0, blue: 0 } );
or b)

Code: Select all

var dev = controller.devices.get( 'ZWayVDev_zway_9-0-51-rgb'); dev.performCommand( 'exact', { red: 0, green: 0, blue: 0 } );
By "wrapping" these code devices into light scenes I can also use these as scenes in a lot of modules (in some modules they otherwise don't show up).
But now I'm stuck trying to find a solution to periodically (i.e. every 2 seconds) switch between a) and b) as long as an (activation) switch or a specific scene is active.
Can somebody help me please?
Any hints are very welcome.
BobElHat
Posts: 23
Joined: 27 Dec 2016 21:32

Re: help needed to let RGB device "blink"

Post by BobElHat »

On my phone so can't really write the code, but you could maybe use setInterval and setTimeout.

Something like: the "on" command for your code device calls setInterval, which periodically calls an anonymous function which turns the light on, then does a setTimeout to turn it off. Store the return vales from setInterval and setTimeout in the metrics for the code device, then your "off" command would turn the light off and call clearInterval and clearTimeout to stop the timers.

This is getting a bit messy for a code device though, probably better done as a module.
Karsten
Posts: 34
Joined: 09 May 2016 20:06

Re: help needed to let RGB device "blink"

Post by Karsten »

Thanks a lot, BobElHat. Thought something similar.
Maybe a good point to start with a module is Maros' timer switch?
http://developer.z-wave.me/?uri=public#/web/apps/335
Or another existing module to adapt?
Unfortunately my JS skills are rather limited. :(
So I appreciate any help.
Maybe this could end with a module, which can be also usefuls for others.
BobElHat
Posts: 23
Joined: 27 Dec 2016 21:32

Re: help needed to let RGB device "blink"

Post by BobElHat »

Maros' module looks like as good a place to start as any - the code looks clean and it does similar timer setting/clearing things.

Thinking about it, if equal on and off times are acceptable it would probably be simpler to just have one setInterval and have the code turn it off if it's on and on if it's off than mess about with multiple timers.
Karsten
Posts: 34
Joined: 09 May 2016 20:06

Re: help needed to let RGB device "blink"

Post by Karsten »

Played around a bit and managed to implement a blinking device now with the use of "Timer Switch", a "Dummy Device" (as the "Target") and some "Logical Rules".

Used Components:
- Timer Switch "BlinkerTimer" with time unit "seconds" and max. time "5"
- Dummy Device "Target" of device type "BinarySwitch"
- Logical Rule "BlinkerOn": if "BlinkerTimer"="5" then set "Target" to "On"
- Logical Rule "BlinkerOff": if "BlinkerTimer"="3" then set "Target" to "Off"
- Logical Rule "BlinkerStillOn": if "BlinkerTimer"="1" then set "BlinkerTimer" back to "5"
- Logical Rule "BlinkerFinalOff": if "BlinkerTimer"="0" then set "Target" to "Off"

Logic:
1. Switching on the "BlinkerTimer" starts the timer (level=5)
2. This also switches "Target" to "On".
3. "Off" for "Target" is after 2 seconds (level=3).
3. After 2 more seconds (level=1) "BlinkerTimer" is set back again to "5" (so we go back to 2.).
4. At any time I can switch off "BlinkerTimer" manually (level=0) to deactivate the whole blinking program and permanently switch "Target" off.

I assume it would be easy for a JS programmer to implement this as user module by slightly modifying the "Timer Switch" module accordingly. Unfortunately as stated above my JS skills are too limited... :(
Post Reply