Dim brightness gradually

Hi,

I have a dimmer switch which has the attribute brightness. I can adjust the brightness of this switch by pressing and holding one of the buttons.

I also have a dimmer with the brightness attribute.

Here is my automation for dimming the lights:

- alias: Dim1 dimmer test1
  trigger:
  - platform: mqtt
    topic: zigbee2mqtt/dim1/action
    payload: brightness_move_up_1
  action:
  - service: mqtt.publish
    data:
      topic: zigbee2mqtt/dimmer3/l1/set
      payload_template: '{"brightness": {{ state_attr("sensor.dim1_action", "brightness")}}}'

The issue is that when I start pressing the button it immediately sets the brightness for the dimmer. So whatever the brightness of the switch was before I started dimming will be passed on to the dimmer. I would prefer to gradually update the brightness over time as the button is pressed. Is this possible?

My switch and dimmer:
switch: ROBB ROB_200-008-0 control via MQTT | Zigbee2MQTT
dimmer: Moes MS-105B control via MQTT | Zigbee2MQTT

Sure, define a transition and it’ll step over the time you specify - it even tells you how to do that on the page you linked :wink:

But I guess I need to specify the transition time as an integer? I would like it to move the brightness when the button is pressed, and then stop moving when the button is released.

I managed to do this with Node-Red :slight_smile:

Here is my example flow:


Explanation:
Event state node sends the payload from the switch, in my case brightness_move_up_1 and brightness_stop_1. I put these two payloads into the switch node. The brightness_move_up_1 triggers looptimer set to 0.5 seconds and max 10 loops. Then moves on to the call service node, where I add my light/dimmer with these settings:
image

When I release the button, it sends the payload brightness_stop_1, which goes to a change state, and changes the payload from brightness_stop_1 to stop, and sends this to the loop timer to stop the loop :slight_smile:

Hope this helps someone else :smiley:

If you have a suggestion to acheiving this with automation please reply with your answer

you could use a “repeat…until” style automation action and put the button being not pressed as the “until” condition.

1 Like

@knallhare Hi, I am trying to do the same with my shelly RGBW for a single white stripe, triggered by a knx_event (dimmer pushbutton), I have tried with a normal automation with triggers ID without success, the brightness increase up to 255 and make a kind of overflow in the shelly, then it gets offline and unstable. Your solution looks good, but I am not very expert with Node Red, could you please pass me the code?

Hi :wave:!
You could try out my blueprint, maybe it works for your usecase. KNX - relative dimming for lights

Thank you very much @farmio !!
I will try this evening. It looks what I’m looking for, in my automation l am reading the knx_event of the group address 9-8 for UP and 1-0 for DOWN, like you do, but something goes wrong when sending the brighness value to shelly, thats why I am trying with MQTT.

My MQTT light sensor is below, I will check if I have to modify something in the sensor, but I guess I don’t have to publish the value with MQTT, but change the attribute “brightness” of the sensor like you do, correct?

light:
  - platform: mqtt
    schema: template
    name: "Led doccia MQTT"
    command_topic: "shellies/shellyrgbw2-E8DB84DDCC26/white/0/set"
    state_topic: "shellies/shellyrgbw2-E8DB84DDCC26/white/0/status"
    availability:
      topic: "shellies/shellyrgbw2-E8DB84DDCC26/online"
      payload_available: 'true'
      payload_not_available: 'false'
    command_on_template: >
      {"turn": "on"
      {%- if brightness is defined -%}
      , "brightness": {{ (brightness | float / 2.55) | int }}
      {%- endif -%}
      }
    command_off_template: '{"turn": "off"}'
    state_template: "{% if value_json.ison %}on{% else %}off{% endif %}"
    brightness_template: "{{ value_json.brightness | float | multiply(2.55) | round(0) }}"
    qos: 2

Sorry, I don’t have any knowledge about Mqtt.
My blueprint just calls the HA service to change the brightness, how this is done is defined by the integrations code of the selected entity (could also be multiple entities of different integrations).

Thank you very much @farmio !! It’s working perfectly. I had to factory reset the shelly cause probably during previous tests I have messed it up, but it’s fine, also with MQTT.

1 Like