I have configured an iFan03 (with Tasmota) as MQTT fan based on some other topics here at the forum. That results in:
fan:
- platform: mqtt
name: "Plafondventilator"
command_topic: "cmnd/tasmota_8FAD22/FanSpeed"
speed_command_topic: "cmnd/tasmota_8FAD22/FanSpeed"
state_topic: "stat/tasmota_8FAD22/RESULT"
speed_state_topic: "stat/tasmota_8FAD22/RESULT"
state_value_template: >
{% if value_json.FanSpeed is defined %}
{% if value_json.FanSpeed == 0 -%}0{%- elif value_json.FanSpeed > 0 -%}4{%- endif %}
{% else %}
{% if states.fan.plafondventilator.state == 'off' -%}0{%- elif states.plafondventilator.state == 'on' -%}4{%- endif %}
{% endif %}
# optimistic: true
speed_value_template: "{{ value_json.FanSpeed }}"
availability_topic: tele/tasmota_8FAD22/LWT
payload_off: "0"
payload_on: "1"
payload_low_speed: "1"
payload_medium_speed: "2"
payload_high_speed: "3"
payload_available: Online
payload_not_available: Offline
speeds:
- "off"
- "low"
- "medium"
- "high"
When I comment the optimistic: true, HA will wait for the state topic before setting state. Unfortunately it doesn’t set speed to 'off'
.
Here it is on 'low'
and 'on'
.
Here I set the fan speed to 'off'
.
The fan turns off, but the speed remains 'low'
When I uncomment optimistic: true almost all works as expected. When I change speed to 'off'
through fan.set_speed
, the fan turns off AND the speed changed to 'off'
. But… when I change the speed to ‘off’ in the Tasmota interface it won’t change speed again (other speeds DO work though).
This is what Tasmota publishes in the state topic:
{"FanSpeed":1}
**qos** : 0, **retain** : false, **cmd** : publish, **dup** : false, **topic** : stat/tasmota_8FAD22/RESULT, **messageId** : , **length** : 42
{"FanSpeed":0}
**qos** : 0, **retain** : false, **cmd** : publish, **dup** : false, **topic** : stat/tasmota_8FAD22/RESULT, **messageId** : , **length** : 42
So it seems FanSpeed: 1 is understood (as the speed changes to 'low'
), while FanSpeed: 0 isn’t understood by Home Assistant?
So what does Home Assistant expect as a value, as '0'
isn’t working, maybe 'off'
? How would I change speed_value_template to test?