Help on automating volume increase

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!

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 }}

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

That error is pointing to your old code, are you sure you updated it?

Or are you looking at the wrong error?

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