Self-resetting counter for fan speed

Im going to add an iFan04 and am looking at how to control the fan speed with a single hardware button on an NSPanel. Basically, it will be a counter with 4 steps, 0-3, with zero being ‘Off’ and 3 being ‘Max’. Each button tap will increase the counter.

What i can’t get my head around is how to see what the current counter # is so that it knows that if it’s already 3 then reset the counter to 0 before sending the fan controller the speed command.

Im using the gui because I’ve yet to get my head around YAML coding.

This is the best that I’ve been able to come up with. Does it look right?

Edit: no, it doesn’t look right. The copy/paste made it all run together…

alias: BR Fan Speed automation description: "" trigger: - platform: state entity_id: - input_button.br_fan_speed_button condition: [] action: - if: - condition: numeric_state entity_id: counter.br_fan_speed above: 2 then: - service: counter.reset data: {} target: entity_id: counter.br_fan_speed else: - service: counter.increment data: {} target: entity_id: counter.br_fan_speed mode: single

Lol as horrible as the formatting of the code is, it works perfect.

You need to paste your code as preformatted text (this is now in the cogwheel bit of the toolbar).

How about…

Trigger: Button press
Action: Increment counter helper
Condition: If numeric state of counter > 3
Action: Reset counter

1 Like

Here’s the properly formatted code and it works perfect. I just have to add the action at the end to send the fan controller the command to actually set the speed. I put a ‘notify’ command as a temporary placeholder for where the command will go.

alias: BR Fan Speed automation
description: ""
trigger:
  - platform: state
    entity_id:
      - input_button.br_fan_speed_button
condition: []
action:
  - if:
      - condition: numeric_state
        entity_id: counter.br_fan_speed
        above: 2
    then:
      - service: counter.reset
        data: {}
        target:
          entity_id: counter.br_fan_speed
    else:
      - service: counter.increment
        data: {}
        target:
          entity_id: counter.br_fan_speed
  - service: notify.notify
    data:
      message: Fan Speed set
    enabled: false
mode: single