Enhancing Dimming Control for Office Lighting

I’ve been working on refining my office lighting automation using Node-RED, and I wanted to share my journey and solution for anyone facing similar challenges. My setup includes three Hue lights, a Hue remote, and a Hue sensor, all integrated into a Zigbee network. The goal was to ensure that dimming commands only affect lights currently on, avoiding unintended activations.

Initially, pressing the dim up or down buttons on the Hue remote would adjust the brightness of all lights in the group, even those that were off. This behavior wasn’t ideal, as it would sometimes turn on lights I intended to keep off. To address this, I needed a way to filter out lights that were off before applying the dimming command.

Here’s how I approached the solution:

  1. Retrieve Light States: I utilized the ha-get-entities node in Node-RED to fetch the current state of each light in the group. This allowed me to check whether each light was on or off.

  2. Filter Lights: Using a change node, I created a list of only the lights that were on. This involved iterating through each light’s state and conditionally adding their entity IDs to a new array if they were active.

  3. Apply Dimming: With the filtered list of active lights, I adjusted the light.turn_on service call to target only these lights. This ensured that dimming commands would only affect lights that were already on, preventing unintended activations.

  4. Testing and Refinement: I thoroughly tested each part of the flow to ensure it worked as intended. Debug nodes were invaluable in verifying that the correct lights were being targeted and that the dimming commands were applied accurately.

This solution not only resolved the issue but also provided a clearer understanding of how to manipulate and target specific devices within a group. If anyone has questions or needs further clarification, feel free to reach out!

Here’s a snippet of the key flow configuration:
javascript
[{
“id”: “filter_on_lights”,
“type”: “change”,
“name”: “Filter On Lights”,
“rules”: [
{
“t”: “set”,
“p”: “payload”,
“pt”: “msg”,
“to”: “{{
let onLights = ;
for (let light of msg.payload) {
if (light.state === ‘on’) {
onLights.push(light.entity_id);
}
}
return onLights;
}}”,
“tot”: “jsonata”
}
],
“action”: “”,
“property”: “”,
“from”: “”,
“to”: “”
},
{
“id”: “dim_adjust”,
“type”: “api-call-service”,
“name”: “Adjust Dim Level”,
“domain”: “light”,
“service”: “turn_on”,
“data”: {
“entity_id”: “{{ payload }}”,
“brightness_step”: “{{ dim_step }}”,
“transition”: “1”
}
}]

This approach ensures that dimming commands are applied only to lights that are currently on, enhancing the precision and user experience of the automation setup.