bbalazs
(Björn)
November 17, 2020, 7:01pm
1
In the scope creating my wakeup scene, I am trying this little skript to increase the volume of a single media player. Just - the configuration check fails, and I hve no clue whats wrong…
So, this is the script I would like to call:
aufwachen_radio_bjoern:
alias: aufwachen radio bjoern
sequence:
- alias: Set Volume
service: media_player.volume_set
data:
entity_id: media_player.bjoerns_sound
volume_level: '0.05'
- service: media_player.select_source
data:
source: radioeins
entity_id: media_player.bjoerns_sound
- delay: 15
- alias: Lautstaerke erhoehen
repeat:
while:
- condition: template
value_template: >
{{ state_attr('media_player.bjoerns_sound', 'volume_level') < '1' }}
sequence:
- service: media_player.volume_set
data_template:
entity_id: media_player.bjoerns_sound
volume_level: >
{{ (state_attr('media_player.bjoerns_sound', 'volume_level') + '0.05' }}
- delay: 10
Thanks for any tips!
petro
(Petro)
November 17, 2020, 7:41pm
2
If you’re on the latest versions, typing matters. Also, your templates don’t properly check volume levels. You’re checking strings and adding them together. Which won’t give you numbers, just odd strings. You also had an extra parenthesis in the second template, that makes the code syntax invalid.
- condition: template
value_template: >
{{ state_attr('media_player.bjoerns_sound', 'volume_level') | float < 1 }}
- service: media_player.volume_set
data_template:
entity_id: media_player.bjoerns_sound
volume_level: >
{{ state_attr('media_player.bjoerns_sound', 'volume_level') | float + 0.05 }}
bbalazs
(Björn)
November 17, 2020, 8:09pm
3
Thanks a lot for your quick help. Just the configuration validation still complains:
Invalid config for [script]: invalid template (TemplateSyntaxError: unexpected ‘}’, expected ‘)’) for dictionary value @ data[‘script’][‘aufwachen_radio_bjoern’][‘sequence’][3][‘repeat’][‘sequence’][0][‘data_template’]. Got OrderedDict([(‘entity_id’, ‘media_player.bjoerns_sound’), (‘volume_level’, “‘{{ (state_attr(‘media_player.bjoerns_sound’, ‘volume_level’) + ‘0.05’ }}’\n”)]). (See /config/configuration.yaml, line 120).
I do not understand, what that actually means. Just to compare, here is my current script:
aufwachen_radio_bjoern:
alias: aufwachen radio bjoern
sequence:
- alias: Set Volume
service: media_player.volume_set
data:
entity_id: media_player.bjoerns_sound
volume_level: '0.05'
- service: media_player.select_source
data:
source: radioeins
entity_id: media_player.bjoerns_sound
- delay: 15
- alias: Lautstaerke erhoehen
repeat:
while:
- condition: template
value_template: >
{{ state_attr('media_player.bjoerns_sound', 'volume_level') | float < 1 }}
sequence:
- service: media_player.volume_set
data_template:
entity_id: media_player.bjoerns_sound
volume_level: >
{{ state_attr('media_player.bjoerns_sound', 'volume_level') | float + 0.05 }}
- delay: 10
petro
(Petro)
November 17, 2020, 8:17pm
4
That error is pointing to your old code, are you sure you updated it?
Or are you looking at the wrong error?
bbalazs
(Björn)
November 17, 2020, 8:23pm
5
You are right - there is something strange going on here. No, things did not get saved… Seems the file editor was crashed or something. Anyhow, works after ro-opening and saving. Thanks a lot again!
1 Like