My set-up includes LightwaveRF gen 1 433 switches which do not report on/off state. The frontend status is usually wrong, but I can live with that. I mainly use Google Assistant or the physical switches. HA doesn’t seem to care what the reported “actual” state of a switch is. It will accept and execute an on or off command regardless. For example, even if HA thinks that the bedroom light is already on when it’s actually off, saying “Hey, Google, turn on the bedroom light” does just that.
I’d like to have the same behavior from Google Assistant with a input_boolean switch (“Sonos Everywhere”) that I use with automations to trigger separate on or off scripts that either [input_boolean ON] group and turn on (media_play), or [input_boolean OFF] turn off (media_pause) all speakers. Currently, a command like “Hey, Google, turn on Sonos Everywhere” only works if HA thinks that Sonos Everywhere is off. The problem is that someone may have manually started or paused Sonos using an app or the buttons on the speaker. HA is unaware of those manual changes.
I imagine that I could query media player status and have the input_boolean update accordingly. But the many possible scenarios mean that’s not something I want to tackle now. There must be a simpler way as long as I don’t care what the switch status shows in the front end.
I’m happy to use something other than an input_boolean as the trigger, as long a “turn on” and “turn off” work with Google Assistant.
Here’s the input_boolean:
sonos_everywhere_on_off:
name: Sonos Everywhere
initial: off
icon: mdi:speaker
And here are the automations:
- id: '1549024279717'
alias: Sonos Everywhere On
trigger:
platform: state
entity_id: input_boolean.sonos_everywhere_on_off
to: 'on'
action:
service: script.turn_on
entity_id: script.sonos_play_whole_house
- id: '1549024407869'
alias: Sonos Everywhere Off
trigger:
platform: state
entity_id: input_boolean.sonos_everywhere_on_off
to: 'off'
action:
service: script.turn_on
entity_id: script.sonos_pause_whole_house
Input boolean will ‘store the state’. But the script will always fire. The switch doesn’t care, it get’s the state from the input boolean. And if you don’t even care about storing the state and you just want a switch that you can call on or off with…
I exposed switch (templates) to Google, but using it makes Google say “Sorry [homeassistant] is not available right now” / “I can’t reach homeassistant”, or any connection error (maybe because it’s made with template platform, which is a UI platform, not a data platform?)
So what I did is:
1. Create appropriate reusable scripts so everything is clean:
projector_on:
alias: Projector on
sequence:
- service: remote.send_command
data:
[data: turn on my projector]
projector_off:
alias: Projector off
sequence:
- service: remote.send_command
data:
[data: turn on my projector]
2. Create input_boolean
projector:
name: Projector
initial: off
3. Create switch templates to have switches available in the UI
projector_onoff:
value_template: '{{ states("input_boolean.projector") }}'
friendly_name: "Projector"
turn_on:
- service: input_boolean.turn_on
data:
entity_id: input_boolean.projector
# Other service will be linked with automation due to Google home voice command errors
# - service: script.projector_on
turn_off:
- service: input_boolean.turn_off
data:
entity_id: input_boolean.projector
# Other service will be linked with automation due to Google home voice command errors
# - service: script.projector_off
4. Then created corresponding automations to link input_booleans to scripts
- id: "1613500967652"
alias: Turn on projector
description: ""
trigger:
- platform: state
entity_id: input_boolean.projector
to: "on"
condition: []
action:
- service: script.projector_on
mode: single
- id: "1613500967653"
alias: Turn off projector
description: ""
trigger:
- platform: state
entity_id: input_boolean.projector
to: "off"
condition: []
action:
- service: script.projector_off
mode: single
5. Then exposed the input_boolean to Google (not the switch)