home-assistant / architecture

Repo to discuss Home Assistant architecture
313 stars 100 forks source link

Introduce Fan speed percentage capability for MQTT fan integration #529

Closed jbouwh closed 3 years ago

jbouwh commented 3 years ago

Context

This as a follow up on architecture discussion https://github.com/home-assistant/architecture/issues/127. The fan core identity fas been changed recently to support speed percentage. Using speeds (off, low, medium and high) is decrepated now. Since HA core-2021.3.2 the fan integration has been updated. Separate fan speeds into percentages and presets modes #45407 The mqtt.fan should follow this architecture update.

Proposal

Update the mqtt fan integration to support setting a speed percentage.

Consequences

This will enable to pass percentage based speeds to MQTT fans and te be conformant to the architecture changes of the fan integration and core identity updates.

The current 'speeds' attribute will remain working as it is now to support backwards compatiblity. Functions to translate between predefined speeds and percentages have been built into ha core already (speed_to_percentage() and percentage_to_speed() in components/fan)

If both speeds and percentage methods are advertised (or set through config) the predefined functions will be used to translate a percentage to predefined speed and back (speed_to_percentage() and percentage_to_speed() in components/fan).

A MQTT fan advertises a percentage_command_topic to ha core mqtt auto discovery it supports percentage based variable speeds. A percentage_state_topic is used to report back the actual percentage set by the fan. A percentage_value_template defines te template to extract the percentage from the payload.

jbouwh commented 3 years ago

In addition to address this as an issue. Using the mqtt fan integration using set_speed (the only available method now) results to warnings in the logging:

Logger: homeassistant.components.fan
Source: components/fan/__init__.py:231
Integration: Fan (documentation, issues)
First occurred: 7:30:00 (1 occurrences)
Last logged: 7:30:00

fan.set_speed is deprecated, use fan.set_percentage or fan.set_preset_mode instead.
frenck commented 3 years ago

Transferring the issue into a discussion.