Dimming lights without going off

Hi everyone, could someone please help me get this code ‘translated’ to node-red?

                    brightness: >-
                      {{  [state_attr("light.master_bedroom","brightness")|int -
                      60, 1]|max  }}

In HA automation this above line will dim the lights to the minimum settings of 1 but I have no idea where to start with this in node-red to have same effect.

Would really appreciate if someone could help me out here.

Thanks!

If I read this right, you’re setting the light to current brightness - 60 or 1, whichever’s higher?

I’d use a call service node, you’ll need to amend for the names of your entities.

{
  "brightness": $max([
    $entities("light.ceiling").attributes.brightness - 60, 1
  ])
}
1 Like

Hi @eggman, thanks a lot for your help.

What I was trying to achieve is to dim lights to min but don’t turn lights off with dimmer.

So your code does work! I just had to change the minimum setting from 1 to 2 (1 was switching lights off - ikea tradfri).

Thank you very much for that!

You helped me a lot.

If you just always want to set the lights to 2 then it’s simpler, you only need

{
  "brightness": 2;
}

As JSON in the data field.

thank you @eggman - I wanted dimming action but protect the bulbs from turning off at the dimmest point :slight_smile:

value 2 instead of 1 helps with this as well as your whole code. Value 0 or 1 means bulbs off.

thank you once again.

I am wondering if HA sends an off command with 0 brightness or the bulbs I have do not respond that way.

See if this will work for you, I use the following to dim. The switch I use has 3 different commands single press, hold, and hold release.

Depending on the bulb you may need to adjust the step in the call service and the time between messages in the trigger node. When the button is held the trigger node will fire repeatedly until the button is released.

[{"id":"6476799275779344","type":"trigger","z":"f80b6c338afd5483","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-300","extend":false,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":600,"y":3280,"wires":[["cd0c062ffc8bac00"]]},{"id":"44da3c09a9ec58e7","type":"change","z":"f80b6c338afd5483","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":3340,"wires":[["6476799275779344"]]},{"id":"cd0c062ffc8bac00","type":"api-call-service","z":"f80b6c338afd5483","name":"","server":"6b1110b5.183a4","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.lefty_and_righty"],"data":"{\t   \"brightness_step\": -20\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":850,"y":3220,"wires":[[]]},{"id":"bafb7b2a626b8f16","type":"inject","z":"f80b6c338afd5483","name":"button pressed","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":3220,"wires":[["cd0c062ffc8bac00"]]},{"id":"466712ec09b2dbf6","type":"inject","z":"f80b6c338afd5483","name":"button held","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":3280,"wires":[["6476799275779344"]]},{"id":"7106fe13db6ee114","type":"inject","z":"f80b6c338afd5483","name":"button release","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":3340,"wires":[["44da3c09a9ec58e7"]]},{"id":"6b1110b5.183a4","type":"server","name":"Home Assistant","version":4,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m"}]

thanks @Mikefila - I had it this way and all tradfri/yeelight bulbs just switched off when they hit bottom of the scale. with the above solution bulbs will stay at their lowest value which is perfect :slight_smile: