Hi,
I hope somebody can help me. What am I doing wrong?
During the last day I managed to write my first script, to put a TTS message to one of my speakers and try to restore the speaker state afterwards.
sequence:
- if:
- condition: template
value_template: "{% set WasOff=is_state( Player ,'off') %}{{WasOff}}"
then:
- service: media_player.turn_on
data: {}
target:
entity_id: "{{Player}}"
- wait_template: "{{ is_state( Player,'playing') }}"
timeout: 3
- service: script.mediaplayer_snapshot
data: {}
- if:
- condition: template
value_template: "{{ is_state( Player ,'playing') }}"
then:
- service: media_player.media_stop
data: {}
target:
entity_id: "{{Player}}"
- wait_template: "{{ is_state( Player,'idle') }}"
timeout: 10
- service: media_player.volume_set
data:
volume_level: 0.25
target:
entity_id: "{{Player}}"
- service: tts.google_translate_say
data:
entity_id: "{{Player}}"
message: "{{Nachricht}}"
- wait_template: "{{ is_state( Player,'playing') }}"
timeout: 10
- wait_template: "{{ is_state( Player,'idle') }}"
timeout: 40
- service: script.mediaplayer_restore
data: {}
- if:
- condition: template
value_template: "{{WasOff}}"
then:
- delay: 5
- service: media_player.turn_off
data: {}
target:
entity_id: "{{Player}}"
mode: single
My problem is the Variable “WasOff” which should reflect the power state of the speaker. The variable “Player” contains the entityID of the speaker and is consistent through the whole script.
The problem that I try to solve is that the snapshot function doesn’t store the speakers mode (input) when the speaker is off, when creating the snapshot.
So my goal was to switch it on so the the input is active, snapshot the state and switch it off afterwards, when I had to switched it on, before the snapshot.
The problem is, that the variable “WasOff” never seems to reflect the state at the end of the script.
I am at a loss, can somebody with more knowledge than me help please?
Cheers