Tracking State of Dumb Fan to Calculate Number of IR Signals to Send

Hello! First post. I’ve done my best to read the rules first - and search for other similar questions.
But my apologies if I’ve missed anything - I’ve dabbled with very basic Alexa automation, but this is my first step into deeper waters.

I have a window fan that takes an IR signal. It has 2 buttons:
Button A cycles thought the speeds (0, 1, 2, 3)
Button B cycles though fan direction (in, out, exchange)

I have a Broadlink RM Pro, and have written two HA scripts that send the two signals - I’ve tested them, everything is great there.

Now I would like to have a button on the dash that that allows me to easily select the fan settings, where I can get to each speed and airflow option with a single click.

The closest forum post I’ve found is this one: Automation to set fan speed using momentary button cycle - #8 by WittyHat

I feel like I can mostly follow what’s being done there, but I’m still learning, and I don’t know enough to know how to modify it to fit my use case.

Specifically, because my fan is dumb, there is no way to get any state information from it.
I need to know its current state in order to know how many signals to send to get it to the desired state.

Perhaps in the future, I’d get some sort of power monitoring device, and track it that way (that will also guard against it getting out of sync if someone pushes the button manually)
But for the sake of learning, I’d like to keep things as simple as possible for the time being.

As best as I can figure, I’ll need to add something to configuration.yaml to persistently keep track of the last known states, and then follow more or less the same steps outlined in the post I’ve linked.

Would an input_number be the best approach?

Something like:

input_number:
  back_bedroom_window_fan_speed:
      name: Back Bedroom Window Fan Speed
      min: 0
      max: 3
      step: 1

But, once I set that up, how would I access/change it from within the template?
Is that even the best approach? So far, I have not found a page that lists all the variables HA allows you to define, so I’m not even sure what all my options are.

Any help is greatly appreciated.
Thanks!

I personally think you will struggle with this without having power monitoring, as its very easy for this to become out of sync, someone manually controlling it, power outage, iR signal going astray etc.

I can see how you could determine fan speed based on power monitoring assuming the fan speed are sufficiently different enough to allow accurate power monitoring. But I am guessing that the fan direction will have little to no differences in power draw between the 3 different modes so this may be very difficult indeed.

Use the service ‘input_number.set_value’ to change the value to whatever you want within an automation or script.

Also, you can setup an input number helper within the UI: Settings - Devices & Services - Helpers - Create Helper

As @rossk mentioned, it’s eventually going to get out of sync for any number of reasons. That being said, I do something similar for my audio amp: I keep track of the mode (TV or music) and the volume level, although I’m using an ESPHome device to manage that and control it. In my case, it only gets out of sync if someone physically adjusts it instead of using HA or the remote. Probably once a month or two I have to manually sync things back up.