Cycle thru brightness with one button based on current brightness value

Hello there,
I’d like to set up a Shelly Dimmer 2 with an Aquara (only supports single/double click) button to cycle thru brightness based on the current value of the brightness itself, but right now a bit lost with templates/multiple conditions/actions, I’d like to ask for help if possible. What I’d like to achive is (with only using double click as I’d like to leave single to on/off):
if the light is off, double click to turn on, brightness 255
if brightness is 1-42 lets say, set it to 80
when 43-80, set to 192
etc
Could you point me in the right direction? Thanks in advance
Balazs

1 Like
- alias: increase brightness
  trigger:
    - your double-click trigger goes here
  action:
    - service: light.turn_on
      entity_id: light.your_light
      data: 
        brightness: >
          {% if is_state('light.your_light', 'on') and state_attr('light.your_light', 'brightness') | int <=42 %}
            80
          {% elif is_state('light.your_light', 'on') and 43 <= state_attr('light.your_light', 'brightness') | int <=80 %}
            192
          {% else %}
            255
          {% endif %}

I think that should do it.

1 Like

Greatly appreciate your solution, cycling now as I wanted (0->100%->66%->33%->66%->100% and so on). Thanks a lot!

Where to insert this? I’ve tried config, lights, scripts, but I get errors. Pretty new to templates.

it’s an automation. It goes in the automations.yaml file.

I used this and changed it a bit for a script:

It goes
off > 20 > 150 > 255 > off

alias: dimmer_control_self
sequence:
  - service: light.turn_on
    data:
      entity_id: "{{ light }}"
      brightness: |
        {% if state_attr(light,'brightness') | float(10) <=19 %}
          20
        {% elif 20 <=state_attr(light, 'brightness') | float(10) <=149 %}
          150
        {% elif 150 <=state_attr(light, 'brightness') | float(10) <=254 %}
          255
        {% elif 255 <=state_attr(light, 'brightness') | float(10) %}
          0
        {% endif %}

Now I can use this for buttons or in lovelace or anywhere else. I add the light when I call the service:

- service: script.dimmer_control_self
  data:
    light: light.your_light
5 Likes