Red Switch + NodeRed + Hue = Dimmer Flow?

I’m using Red Dimmers to control Hue bulbs. I’ve got them all in smart bulb mode, so I’m using NodeRed for hooking up on/off, scene control and all that.

I’ve got all the wave scenes triggering correctly, and can turn on/off groups of Hue lights no problem.

My problem is recreating dimming action from the switch. I originally had been using Hubitat, and had this working with the Rule Machine, but moved everything over to Home Assistant and OpenZwave recently, and trying to keep all automation in NodeRed.

I set up a loop, and incremented the brightness, but it’s pretty garbage in terms of latency and getting hung up in the loop. Nothing at all like the “start ramping” then “stop ramping” action I was able to do in Hubitat. I’ve tried using the Hue Magic sub flow, but I don’t know if I’m just making it more complicated that way. I’m still a bit of a novice with NodeRed.

So my question is; does anyone have the full dimming action setup in NodeRed with Hue lights, and can you share your flow if you do? Below is what I’ve got started, the “Office Dimmer” pink node splits out all of the different scenes (1-tap, 2-tap, hold up, release up, etc). My issues is what should come after “hold up” and “release up”.

1 Like

I was able to get a hue light to work reasonably well with dimming in node red, it’s still not perfect but it works for me. I’m on my phone now but I can try to send my flow later.

Basically, the loop continues while hold is pressed but stops when release is detected. Then you configure the loop frequency and increase brightness percentage you prefer per step of the loop. I also set transition for each change to smooth out the dimming a bit. Here is a screenshot of the loop I’m using.

I switched over to node red for my lights earlier this year and it’s become much easier for me to manage in home assistant (after you get the hang of it).

Super helpful, thank you. Mind showing what’s in the “Release detected - stop loop” and “Set dim percentage” nodes?

Do you ever get issues with the loop getting hung up while the paddle is held down? I can trigger the timing loop manually and everything works fine, but when I trigger it from the wave scene/switch being held, it’s like HA/NR gets hung up by too many events firing or something.

The looptimer has a max number of times it will run, which is configurable. I think I have it set to run up to 10 times if it never receives a STOP event. I don’t recall having major issues with the loop getting hung up but I guess that could happen depending on when the hub receives the release signal. It’s a little delayed but works well enough for my purposes, most of my control is through automation so the actual switch doesn’t get a ton of use.

Actually, the 2 switches I use for this are actually Zooz switches but they should fire the same events as Inovelli, I think. I could try my Inovelli switches with the same setup if you have any issues.

The “Release detected - stop loop” node just sends the STOP event to the looptimer.

“Set dim percentage” is just a simple script that looks at the scene_id event (up or down button on zwave switch) to determine whether to dim up or down. In my case, I set it to increase/decrease by 15% every 0.5 seconds.

var updown = msg.payload.event.scene_id;
if(updown == 2){
    msg.dim = 15;
} else { msg.dim = -15;}
return msg;

Here is the section of my node red flow that you can copy into your flow:
[{"id":"b842f142.b478b","type":"switch","z":"9118dec7.3d9168","name":"Side","property":"payload.event.scene_id","propertyType":"msg","rules":[{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":90,"y":300,"wires":[["9dc35dff.4087f"],["b4c99307.5e719"],[]]},{"id":"b4c99307.5e719","type":"switch","z":"9118dec7.3d9168","name":"Down: 1x, 2x, 3x, 4x, 5x, Hold, Release","property":"payload.event.scene_data","propertyType":"msg","rules":[{"t":"eq","v":"7680","vt":"str"},{"t":"eq","v":"7860","vt":"num"},{"t":"eq","v":"7920","vt":"num"},{"t":"eq","v":"7980","vt":"str"},{"t":"eq","v":"8040","vt":"str"},{"t":"eq","v":"7800","vt":"str"},{"t":"eq","v":"7740","vt":"str"}],"checkall":"true","repair":false,"outputs":7,"x":540,"y":360,"wires":[["6e2f00a9.5277b"],[],[],[],[],["686a3ce0.8addfc"],["c8444d31.8fc09"]]},{"id":"9dc35dff.4087f","type":"switch","z":"9118dec7.3d9168","name":"Up: 1x, 2x, 3x, 4x, 5x, Hold, Release","property":"payload.event.scene_data","propertyType":"msg","rules":[{"t":"eq","v":"7680","vt":"str"},{"t":"eq","v":"7860","vt":"num"},{"t":"eq","v":"7920","vt":"num"},{"t":"eq","v":"7980","vt":"str"},{"t":"eq","v":"8040","vt":"str"},{"t":"eq","v":"7800","vt":"str"},{"t":"eq","v":"7740","vt":"str"}],"checkall":"true","repair":false,"outputs":7,"x":540,"y":240,"wires":[["91d26336.38b638"],[],[],[],[],["686a3ce0.8addfc"],["c8444d31.8fc09"]]},{"id":"686a3ce0.8addfc","type":"looptimer","z":"9118dec7.3d9168","duration":"0.5","units":"Second","maxloops":"10","maxtimeout":"5","maxtimeoutunits":"Second","name":"","x":1090,"y":340,"wires":[["cea05663.16e6e"],[]]},{"id":"c8444d31.8fc09","type":"change","z":"9118dec7.3d9168","name":"Release detected - stop loop","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":930,"y":420,"wires":[["686a3ce0.8addfc"]]},{"id":"cea05663.16e6e","type":"function","z":"9118dec7.3d9168","name":"Set Dim Percentage","func":"var updown = msg.payload.event.scene_id;\nif(updown == 2){\n msg.dim = 15;\n} else { msg.dim = -15;}\nreturn msg;","outputs":1,"noerr":0,"x":1320,"y":340,"wires":[["675af41c.9677fc","398c5d00.a014f4"]]},{"id":"91d26336.38b638","type":"api-call-service","z":"9118dec7.3d9168","name":"Turn on Living Room Lamp","server":"aa6a5a1a.ff80a8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.living_room","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":950,"y":180,"wires":[[]]},{"id":"6e2f00a9.5277b","type":"api-call-service","z":"9118dec7.3d9168","name":"Turn off Living Room Lamp","server":"aa6a5a1a.ff80a8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.living_room","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":950,"y":260,"wires":[[]]},{"id":"398c5d00.a014f4","type":"debug","z":"9118dec7.3d9168","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1530,"y":460,"wires":[]},{"id":"675af41c.9677fc","type":"api-call-service","z":"9118dec7.3d9168","name":"Living Room Dim Light Up/Down","server":"aa6a5a1a.ff80a8","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.living_room","data":"{\"brightness_step_pct\":\"{{dim}}\",\"transition\":0.5}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1620,"y":340,"wires":[[]]},{"id":"aa6a5a1a.ff80a8","type":"server","z":"","name":"Home Assistant","addon":true}]

Let me know how it works out for you or if you find any improvements.

Quick h/t to @rbf - your variable dimming function is most excellent, very clean. I had to make a few tweaks to get it working with my LZW31-SN dimmers (might be the subroutine I’m using):

var updown = msg.payload.event.property_key;
if(updown == "002"){
msg.dim = 15;
} else { msg.dim = -15;}
return msg;

Now working as designed - still a little ‘jerky’, but some tweaking to the loop timing and dim steps should even it out. Thanks again!

Nice, glad to hear it is working for ya. It seems like the syntax changed in zwave js? I haven’t upgraded to zwave js yet so this looks like it will be helpful when I finally get around to it.

As for the jerky stepping, I experience the same thing but it doesn’t bother me that much so I never tried to improve it. because I mostly just use automatons to control the light and in my scenario I’m repurposing an otherwise useless light switch ( it’s hooked up to an always on flood light, so I’m repurposing the physical switch as a scene controller now).

Maybe later this year when the zigbee switch comes out, it will play better with hue bulbs

1 Like

Yep, this is Z-Wave JS - filtering zwave_js_value_notification through the flow. Started in OZW, tried JS2MQTT, settled on the ‘native’ JS integration. Rock solid / super fast in my experience.

fwiw, I found the sweet spot, at least for my setup (mix of Hue and LIFX)

  • loop speed = .2 sec
  • dim increments +/- 10%
  • align scene transition at .2 sec

Dang smooth. I played with dropping loop speed to .1 sec and behavior became a little erratic (loop dies mid-dim) - suspect I was overloading something (zwave network, aeotec usb controller, node-red, etc.). I’m also running HassOS on a repurposed / wired / dedicated Lenovo Yoga i7, and bet running on a Pie or under-resourced VM might require slower loops.

re: waiting for Zigbee Blue switch, I’m in same boat. I’ve installed my stock of 12 Reds and need more - love adding always-on Zigbee routers to my environment.

1 Like