TLDR: The physical state of the mute control on my soundbar goes out of sync with the entity’s state in Home Assistant. This then messes up the execution of automations based on this state. Is there a way to ensure that the state held in Home Assistant stays in sync with the actual physical state? The mute button is a single button that controls mute on/off.
I can successfully use the following 2 automations to mute my soundbar on receiving a Rhasspy command, say one or multiple commands and then unmute it once I have finished.
# MUTE ON SESSION STARTED
- alias: "sessionStarted living room"
trigger:
platform: mqtt
topic: hermes/dialogueManager/sessionStarted
condition:
- condition: template
value_template: "{{ trigger.payload_json['siteId'] == 'living_room' }}"
- condition: template
# MUTE IS OFF IE NOT MUTED
value_template: "{{ is_state('switch.sb_mute', 'off') }}"
action:
- service: switch.turn_on
entity_id: switch.sb_mute
# MUTE ON SESSION ENDED
- alias: "sessionEnded living room"
trigger:
platform: mqtt
topic: hermes/dialogueManager/sessionEnded
condition:
- condition: template
value_template: "{{ trigger.payload_json['siteId'] == 'living_room' }}"
- condition: template
# MUTE IS ON IE MUTED
value_template: "{{ is_state('switch.sb_mute', 'on') }}"
action:
# UNMUTE AT END OF SESSION
- service: switch.turn_off
entity_id: switch.sb_mute
This works great for commands where I don’t need to hear any audio feedback eg controlling & navigating Netflix, Plex etc, turning lights and switches on/off.
However, when I am selecting an artist, playlist or podcast to play on media_player
(piCorePlayer) I only get a mute for the first command and then cannot hear anything until the session is completed. I would like to get a few seconds of audio after each command so that I know what to do next eg skip track, turn volume up, select a different artist etc.
I created the following automation to do this:
# continueSession. Need to unmute to hear result from previous command then remute before sessionEnded
- alias: "continueSession living room"
trigger:
platform: mqtt
topic: hermes/dialogueManager/continueSession
condition:
- condition: template
value_template: "{{ trigger.payload_json['siteId'] == 'living_room' }}"
- condition: template
# MUTE IS ON IE MUTED FROM SESSION STARTED OR PREVIOUS CONTINUE SESSION
value_template: "{{ is_state('switch.sb_mute', 'on') }}"
action:
# UNMUTE FOR 3 SECS THEN REMUTE AGAIN
- service: switch.turn_off
entity_id: switch.sb_mute
- delay:
seconds: 3
- service: switch.turn_on
entity_id: switch.sb_mute
switch.sb_mute
is the mute button on my soundbar. Unfortunately it is a single button to mute/unmute and something about my above automation sometimes causes the state of switch.sb_mute
to become out of sync with the true mute state of the soundbar.
I suspect that my issue is due to my delay in the continueSession
, sometimes when I say a sessionEnded
command the soundbar is muted and sometimes it is in the 3 seconds of being unmuted.
I tried to create a second sessionEnded
trigger that accounts for this situation so that I had both possibilities covered, however switch.sb_mute
still quickly manages to become out of sync with the true mute state of the soundbar.
- alias: "sessionEnded living room if mute starts off, DO NOT UNMUTE on sessionEnded"
trigger:
platform: mqtt
topic: hermes/dialogueManager/sessionEnded
condition:
- condition: template
value_template: "{{ trigger.payload_json['siteId'] == 'living_room' }}"
- condition: template
# MUTE IS OFF IE NOT MUTED
value_template: "{{ is_state('switch.sb_mute', 'off') }}"
action:
# IN THIS CASE DO NOT MUTE AS IT WILL PUT STATES OUT OF SYNC
- delay:
miliseconds: 0.1
Can anyone suggest how I can avoid the state of switch.sb_mute
becoming out of sync with the true mute state of the soundbar?
Thanks