Generic hygrostat: support fan speed levels

I have a Stadler Form Karl (Big) connected via LocalTuya [0]. It has an “auto” feature which I don’t like because it never reaches its target. That’s mainly because it does not take into account how the room is ventilated (heat recovery systems blow in desert air). It doesn’t support hysteresis, leading to annoying frequent toggling between fan levels. Home Assistant to the rescue!

I built my own hygrostat to control the fan speed using some threshold sensors and automations. It reads from a separate humidity sensor that’s a bit further away from the device. It then takes into account what setting my home ventilation system is at and what humidity level it’s blowing (dry) air into the house, in order to pick the right fan speed.

In the long run it would be great if the Generic hygrostat integration could do all that. But for starters it would be nice if it supported fan speeds. Currently it only supports a binary on/off switch.

The Stadler has four levels, when it’s on (1 - 4). It can also be turned off, so that’s effectively level 0.

For my use case I’d like to be able to specify a template to decide what level to pick when humidity goes above or below the target (± hystereses). A simpler place to start would be to just increase/decrease it by 1 level (and again after some time passes).

[0] LocalTuya: Stadler Form Eva Humidifier - #17 by Sjors

If you think it’s a good idea, you should vote for it. I did…
Suggested Reading:
Feature Request Guidelines :notebook_with_decorative_cover: - Feature Requests - Home Assistant Community.

Better it shall support humidifying action and dehumidifying action. That’s way more flexible than only supporting a Fan or a Switch as it currently does – combining this with the lack of ability to define a virtual switch (e.g. Creating Virtual Switches - #3 by rfrenzl), the options are really really very limited.

Maybe the action’s metadata can also be templated to allow fan speed as a function of humidity delta, or something like that.

The generic thermostat has a similar switch based interface. I guess these generic helpers were added before config_flow allowed picking actions or maybe the original author used a relay to control the devices, which is actually a physical switch.

Looks like the code change itself won’t be too difficult – when I eventually find out how to set up a proper development environment I will probably file a PR.