Keep toggling brightness

Hi, I am trying to find some examples of increasing brightness in about 6 steps and when it reaches the maximum of 255 I would like it to switch to the minimum of 3.

I hava a xiaomi double switch and the left and right button will be used to increase the brightness (and decrease) of the front and back living room respectively.
The dual button I have set up to turn on and off these 2 lights plus the xiaomi gateway witch already works great.

Right now I have an automation that will only increase to 255 en decrease to 3.
How can I make it so it will be incremental and If it reaches 255 drop back to 3 so I can keep clicking?
This is a default behavior af the Mi Home app for increase brightness.
This is my automation at the moment:

Left swith

- alias: Switch brightness living room light front
  trigger:
    platform: event
    event_type: xiaomi_aqara.click
    event_data:
      entity_id: binary_sensor.wall_switch_left_XXXXXXXXXXXXXXXX
      click_type: single
  action:
    service: light.turn_on
    entity_id: light.living_room_rgb_front
    data_template:
      brightness: >
        {% if states.light.living_room_rgb_back.attributes.brightness  < 150 %}
         255
        {% elif states.light.living_room_rgb_back.attributes.brightness  <= 255 %}
         3
        {% endif %}

Please always post YAML code, log entries, etc. properly formatted so they can be read correctly. See instructions at the top of the page.

You could do something like this:

  action:
    service: light.turn_on
    entity_id: light.living_room_rgb_front
    data_template:
      brightness: >
        {% set b = state_attr('light.living_room_rgb_front', 'brightness')|int + 6 %}
        {{ b if b <= 255 else 3 }}

Awesome, I’ll try that tonight!
I’ll post the results as soon as I’m home from work.

And thanks for the tip on the format.
I’ve adjusted it according to the screenshot on top of the page :slight_smile:

Awesome!
You made my day, :innocent:
Your suggestion works beautifully

Thanks a million!

Pa. I only had to change the int + 6 to int + 42 :v:

1 Like