Zigbee Button & Fan Automation

Hello friends!

I ordered one of those 1-key Zigbee button… LINKIND ZB Button
I was able to get the button to work to turn on/off lights.

But I’m thinking of trying to get it to work with my smart FAN. My fan has 3 speeds, low, med and high.
Can you please assist me in creating an automation that for every button press it will go through those speeds one by one in sequence – low, med, high, off. Is this possible? I just don’t know how to start.

Thanks in advance!

Straight forward solution(not the optimal);

  • create 3 automations same with each button click trigger
  • place different conditions to each as fan state low, med, high
  • in each automation, move to next state as low to med, med to high, high to low

Optimal solution is to go with one automation as;

  • triggered based on click event
  • in actions, have an action as choose
  • create three conditions as state equals to low or med or high
  • for each condition, set actions to move next state as from low to med, med to high, high to low

I cannot get the fan.toggle to work:

choose:

  • conditions:
    • condition: state
      entity_id: fan.master_bedroom_fan
      state: ‘on’
      sequence:
    • service: fan.increase_speed
      target:
      entity_id: fan.master_bedroom_fan
  • conditions:
    • condition: state
      entity_id: fan.master_bedroom_fan
      state: ‘off’
      sequence:
    • service: fan.toggle
      target:
      entity_id: fan.master_bedroom_fan
      default: []

I really could not get CHOOSE to work. I gave up! LOL
I ended up doing 3 separate automation. Which is fine for as long as it works, right?!

I have a zwave button and I use the following for an automation that steps thru the speeds on each button click.

I’m still on 2021.6.x so I can’t guarantee that it will still work when the new fan speed setting schema (removing the set-speed service) fully goes into effect.

  - alias: Turn MBR Fan On With Scene Switch
    trigger:
      - platform: event
        event_type: zwave.scene_activated
        event_data:
          entity_id: zwave.mbr_scene_switch
          node_id: 35
          scene_id: 1
          scene_data: 0
    action:
      - service: fan.set_speed
        data:
          entity_id: fan.master_bedroom_fan
          speed: >-
            {% if states('fan.master_bedroom_fan') == 'off' %}
              low
            {% elif states('fan.master_bedroom_fan') == 'on' and state_attr('fan.master_bedroom_fan', 'speed') == 'low' %}
              medium
            {% elif states('fan.master_bedroom_fan') == 'on' and state_attr('fan.master_bedroom_fan', 'speed') == 'medium' %}
              high
            {% elif states('fan.master_bedroom_fan') == 'on' and state_attr('fan.master_bedroom_fan', 'speed') == 'high' %}
              low
            {% endif %}