Node-Red, get brightness from light and use that to choose action

I don’t understand how to get the brightness from a lamp and depending on the results send the command to either of two choices.

The reason I want to do this is that I have a motion detector that switches on the lamp with low brightness if someone moves in that room.

I also want to control this lamp with a switch that has only one button.

If the lamp is triggered by the motion sensor and brightness is set to <150 then I want it to set brightness to 255.

If it is set >150 then I want it to be turned off.

I have tried with “current state node” but doesn’t get it to work whatever type I select for input.

I have no problem turning off the lamp or giving it the values ​​I want, I only have problems with get the value from thew light.

This is an example of what I’m trying to accomplish, not the code itself. :slight_smile:

Anyone that can help me?

1 Like

Thats quite simple. You need to add a debug node and change it from Payload to FULL Message.
Then check the message for the value you need, and read from it. i.e. msg.attribute.brightness. You can do that with a switch node for example.

1 Like

Hi @Anders_M_Olausson, I too am new to Node Red with HA, found this thread trying to do exactly the same thing I am trying to acheive, and after a few hours tonight i have got it all working

My solution is below.

Aim: To control my living room lights with a Xiaomi (zigbee) button, with context based on the current living room lights brightness
Single Click - Toggle Lights on/off
Double Click - Toggle between 255 and 127 brightness
Hold Button - Toggle between 127 and 9 brightness

requirement: light brightness value could be set to any value 1-255 via the LIFX app, or the HA webpage, the flow/sequance must account for any value of brightness.

the key i found was to have the “current state” node that reads the status of the lights, override the topic and block input overides

once this is done, the message data in the sequance containes the living room lights data, which i can then feed into the switch node which looks at the brightness value and acts accordingly.

the brightness vairable is located at “data.attributes.brightness” for my LIFX lights, and i made sure to choose “number” in the switch fields.

i know this thread is over 10 months old, but this was the #1 google search i had, so hopefully if this doesn’t help you out, it will help somone.

10 Likes

@culloden_spectre, do you know if you can also use this in percentage?

I don’t want to use the normal brightness settings (0 - 255) I rather user percentage pct.

I did try to change the msg. to data.attributes.brightness_pct and tried data.attributes.brightness.pct but that won’t work.

Any ideas?