Currently running 0.113.2 HA core in a 3.7 venv on Ubuntu with NabuCasa, however this issue appeared for me in 0.112.5 and is logged as: Github issue
In the meantime I’m working on the assumption that I may need to change something in my configuration to permanently resolve the issue.
However despite reading multiple threads and endless tinkering around I’m getting nowhere fast - I’d really appreciate some community input at this point from those more familiar with template fans just for my own sanity.
Summary
Each fan is a 5 speed ceiling fan controlled via (individual) Broadlink 3 RM minis.
As noted on the Github issue, Google Assistant (now) always reports the fans as on regardless of their actual state, seemingly due to the speed_template having a value. If I remove the value from the speed_template in HA, Google Assistant reports the fan status correctly but HA logs ‘received invalid speed’.
It’s important to note that with my current configuration everything works correctly in HA - it’s the Google Assistant element I’m struggling to resolve.
Configuration.yaml
Fans are identically configured, so here is the relevant configuration.yaml entries for one fan.
# control ceiling fans using broadlink remotes
# depends on learnt commands held under .storage folder
#------------------------------------------
# LIVING ROOM FAN
#-----------------------------------------
# turn the fan on, defaulting to speed 2.
living_room_fan_on:
mode: single
sequence:
- service: remote.send_command
data:
entity_id: remote.living_room
device: fan
command: "Speed 2"
- service: input_boolean.turn_on
data:
entity_id: input_boolean.living_room_fan_power
- service: input_text.set_value
data:
entity_id: input_text.living_room_fan_speed
value: "2"
# turn off the fan, resetting boolean
# if we don't set the speed input_text to 0 then system thinks it is on regardless of power flag
living_room_fan_off:
mode: single
sequence:
- service: remote.send_command
data:
entity_id: remote.living_room
device: fan
command: "Turn off"
- service: input_boolean.turn_off
data:
entity_id: input_boolean.living_room_fan_power
- service: input_text.set_value
data:
entity_id: input_text.living_room_fan_speed
value: "0"
# set the fan speed by parameter
living_room_fan_set_speed:
fields:
speed:
description: "The required fan speed"
example: "2"
mode: single
sequence:
- service: remote.send_command
data_template:
entity_id: remote.living_room
device: fan
command: "Speed {{ speed }}"
- service: input_text.set_value
data_template:
entity_id: input_text.living_room_fan_speed
value: "{{ speed }}"
- condition: state
entity_id: input_boolean.living_room_fan_power
state: "off"
- service: input_boolean.turn_on
data:
entity_id: input_boolean.living_room_fan_power
# reverse the current direction of the fan.
living_room_fan_reverse:
alias: "Living room fan reverse"
mode: single
sequence:
- service: remote.send_command
data:
entity_id: remote.living_room
device: fan
command: "Reverse"
# sleep sets to speed 3 for 1 hour then down to 2.
living_room_fan_sleep:
alias: "Living room fan sleep mode"
mode: single
sequence:
- service: remote.send_command
data:
entity_id: remote.living_room
device: fan
command: "Sleep"
- service: input_boolean.turn_on
data:
entity_id: input_boolean.living_room_fan_power
- service: input_text.set_value
data_template:
entity_id: input_text.living_room_fan_speed
value: "2"
# reset the fan power state to on
living_room_fan_reset_as_on:
alias: "Living room fan reset as on"
mode: single
sequence:
- condition: state
entity_id: input_boolean.living_room_fan_power
state: "off"
- service: script.turn_on
data:
entity_id: script.living_room_fan_on
# reset the fan power state to off
living_room_fan_reset_as_off:
alias: "Living room fan reset as off"
mode: single
sequence:
- condition: state
entity_id: input_boolean.living_room_fan_power
state: "on"
- service: script.turn_on
data:
entity_id: script.living_room_fan_off
The only thing that strikes me as odd is the fact that your speeds are all strings. But that could work. Also, it’s possible that google home simply doesn’t support fans with speeds 0 to 6. It may only support off low medium and high.
And, I just checked the code. Looks like numbers aren’t supported from HA to Google home:
Yeah I was wondering myself why I’d done that as I was posting the configuration
If I understand the speed_synonyms correctly, I would need to translate them within my control scripts (from the 5 supported speeds on the hardware to the 3 supported by Google), e.g.
fan.SPEED_OFF -> returns speed_template as "off"
fan.SPEED_LOW -> 1 -> returns speed_template as "low"
fan.SPEED_MEDIUM -> 2 -> returns speed_template as "medium"
fan.SPEED_HIGH -> 3 -> returns speed_template as "high"
and ignore speed 4 and 5 unless Google expands the available synonyms.
I’ll have to get a consensus agreement on which fan speeds to utilise and give this a whirl - thank you.
Yes that makes more sense (my wife was unimpressed with my suggestion of dropping 2 speed options).
Thanks for the offer on the templates - I’ll have a crack at it tomorrow and post in this thread if I struggle.
Unfortunately there’s nothing in place for that, so I cobbled together a set of scripts to move HA’s knowledge of the fan power state between on and off:
# reset the fan power state to on
living_room_fan_reset_as_on:
alias: "Living room fan reset as on"
mode: single
sequence:
- condition: state
entity_id: input_boolean.living_room_fan_power
state: "off"
- service: script.turn_on
data:
entity_id: script.living_room_fan_on
# reset the fan power state to off
living_room_fan_reset_as_off:
alias: "Living room fan reset as off"
mode: single
sequence:
- condition: state
entity_id: input_boolean.living_room_fan_power
state: "on"
- service: script.turn_on
data:
entity_id: script.living_room_fan_off
Not the most elegant way of doing things I’m sure, but they are rather expensive units and I have a bit of a habit of electrocuting myself while doing DIY so wasn’t involved in the fitting at all.
In practice my wife prefers using HA / Google Assistant to use the fans rather than the supplied remote controls so I’m hoping real knowledge of the fans’ current power states won’t be an issue long term.
It turns out my day has finished sooner than expected (read-only Friday and all that) so while I monitor a couple of work jobs I’ve been thinking about the changes to make:
I’ve looked at a few threads where you’ve helped others with template fans, and can see how to change the main configuration to give Google the expected synonym (I think) to:
However I’m wondering how to best handle the speed template for both Google and HA usage.
We currently use a slider to set / change fan speed, which I could best reflect in an input_number I guess (getting rid of the input_text I was using)
That would then leave speed_template as something like:
Ah okay - so basically wrapping the existing template fan attributes inside a Google-Friendly second entity and syncing that one only with Google Assistant, so that HA and GA act on different entities with the same attributes?
I wouldn’t have thought of that solution myself, but it makes far more sense and should be much easier to maintain - both present and future me thank you.
Yeah, I’ve had to do it for a few items to make it work with Alexa. Hopefully support for other fans will be added in the future. I’m not sure google assistant can handle different fan speed names. Looking at the API, it suggests it can. I could be completely wrong with my interpretation though.
In an effort to avoid doing any coding for home this weekend (I’ve worked the last 14 days straight through) I’ve implemented your suggested solution this evening.
It’s worked a treat, both for specifying fan speed via Google Assistant and for resolving the On / Off issue.
Can’t thank you enough (and my wife says thank you as well) - not least because it’s currently 35C in the UK and we’re just not used to it.
For others reading this thread, I had to explicitly add ‘off’ to the speeds on the Googley version to ensure no logged errors in HA and that Google viewed the fan as off.
I’ll add an update to the Github issue as well to clarify - thanks again @petro.
Pretty much, and it no longer requires a “Google flavoured” version. Note that this is for a 5 speed fan controlled via Broadlink and that I’m not sure the “Speeds” section would function correctly as my lovelace uses individual buttons to increase and decrease fan speed, toggle state, etc.
Well thank you Sir. Really appreciate you sharing your full code. How do you measure the fan speed? I’m using power monitoring Shellies but I don’t see anything like that in your amended code.
Blind faith - this is a ceiling fan controlled through a Broadlink RM-Mini3. I’ve catered for someone using the provided remote using a “reset” script but at the moment HA cannot determine any information about the fan state.