Automation problems

Hi!
I created an automation for a media player- in this case for SONOS.
I checked the state of the 4 players and when some of them change the state from “off” to “paused” (and it is after 11o’clock) the player which has changed the state should begin to play.
The problem is the that the log say:

homeassistant.bootstrap: Invalid config for [automation]: Entity ID trigger.to_state.entity_id is an invalid entity id for dictionary value @ data[‘action’][1][‘entity_id’]. Got None. (See /home/homeassistant/.homeassistant/automation.yaml:4). Please check the docs at Automation - Home Assistant

Because I used for the entity_id of the service the “trigger.to_state.entity_id”.

Here is the complete code:

- alias: 'Status Sonos'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: media_player.kuche, media_player.bad, media_player.wohnzimmer, media_player.schlafzimmer
    from: 'off'
    to: 'paused'
  condition:
    - condition: time
      after: '11:00:00'
  action:
    - service: notify.pushover
      data_template:
        message: >
          {{ trigger.to_state.attributes.friendly_name }} is {{ trigger.to_state.state }} und {{ trigger.to_state.entity_id }}
        title: "state change alert"
    - service: media_player.play_media
      entity_id: trigger.to_state.entity_id
      data:
        media_content_id: x-rincon-mp3radio://regiocast.hoerradar.de/deltaradio-foehnfrisur-mp3-hq?sABC=582r034r%230%235469p473qo9365nr3n7564s9sn
        media_content_type: music

I use the notification for debugging:) the value of “trigger.to_state.entity_id” is the correct entity_id of the correct media player e.g.“media_player.schlafzimmer”

The value is correct but the log tells me that this is an invalid entity_id :frowning:

Has anyone an idea how to get a valid entity_id ?

Thank you

Is it the multiple entity_id line?

entity_id: media_player.kuche, media_player.bad, media_player.wohnzimmer, media_player.schlafzimmer

Does the automation work if it’s only

entity_id: media_player.kuche

instead?

try putting all attributes to the data block

 - service: media_player.play_media
   data:
    entity_id: trigger.to_state.entity_id
    media_content_id: x-rincon-mp3radio://regiocast.hoerradar.de/deltaradio-foehnfrisur-mp3-hq?sABC=582r034r%230%235469p473qo9365nr3n7564s9sn
    media_content_type: music

The multiple entity_id line is only for the trigger- that works fine.

The problem is the entity_id line in the action

entity_id: trigger.to_state.entity_id

Based on the information available on this page, it’s not trigger.to_state.entity_id but trigger.entity_id

1 Like

I try it with the
trigger.entity_id
And now I get no error in the log- but the player did not start to play :frowning:
The code is now:

- alias: 'Status Sonos'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: media_player.kuche, media_player.bad, media_player.wohnzimmer, media_player.schlafzimmer
    from: 'off'
    to: 'paused'
  condition:
    - condition: time
      after: '11:00:00'
  action:
    - service: notify.pushover
      data_template:
        message: >
          {{ trigger.to_state.attributes.friendly_name }} is {{ trigger.to_state.state }} und {{ trigger.to_state.entity_id }} und {{ trigger.entity_id }}
        title: "state change alert"
    - service: media_player.play_media
      entity_id: trigger.entity_id
      data:
        #entity_id: trigger.entity_id
        media_content_id: x-rincon-mp3radio://regiocast.hoerradar.de/deltaradio-foehnfrisur-mp3-hq?sABC=582r034r%230%235469p473qo9365nr3n7564s9sn
        media_content_type: music
    - service: media_player.volume_set
      data_template:
        entity_id: trigger.entity_id
        volume_level: 0.2

I also checked this - it does not work

Try

{{entity_id: trigger.entity_id}}

Then home assistant will not restart

Sorry, meant

entity_id: {{trigger.entity_id}}

Same problem
The Log:

homeassistant.util.yaml: invalid key: “OrderedDict([(‘trigger.entity_id’, None)])”
in “/home/homeassistant/.homeassistant/automation.yaml”, line 197, column 0

Try this:

- service: media_player.play_media
  data_template:
    entity_id: {{ trigger.entity_id }}
    media_content_id: x-rincon-mp3radio://regiocast.hoerradar.de/deltaradio-foehnfrisur-mp3-hq?sABC=582r034r%230%235469p473qo9365nr3n7564s9sn
    media_content_type: music

Same problem:

homeassistant.util.yaml: invalid key: "OrderedDict([('trigger.entity_id', None)])"
  in "/home/homeassistant/.homeassistant/automation.yaml", line 204, column 0

Try with quotes:

entity_id: '{{trigger.entity_id}}'

Ok, I put the code in the data block like this:

- service: media_player.play_media
      data:
        entity_id: '{{trigger.entity_id}}'
        media_content_id: x-rincon-mp3radio://regiocast.hoerradar.de/deltaradio-foehnfrisur-mp3-hq?sABC=582r034r%230%235469p473qo9365nr3n7564s9sn
        media_content_type: music

then I got no error by restart, but when I trigger the automation, I got in the Log:

homeassistant.core:
Invalid service data for media_player.play_media: Entity ID
{{trigger.entity_id}} is an invalid entity id for dictionary value @
data[‘entity_id’]. Got ‘{{trigger.entity_id}}’

Here is the solution:

- alias: 'Status Sonos'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: media_player.kuche, media_player.bad, media_player.wohnzimmer, media_player.schlafzimmer
    from: 'off'
    to: 'paused'
  condition:
    - condition: time
      after: '05:00:00'
  action:
    - service: notify.pushover
      data_template:
        message: >
          {{ trigger.to_state.attributes.friendly_name }} is changed to {{ trigger.to_state.state }}
        title: "SONOS state change alert"
    - service: media_player.play_media
      data_template:
        entity_id: '{{trigger.entity_id}}'
        media_content_id: x-rincon-mp3radio://regiocast.hoerradar.de/deltaradio-foehnfrisur-mp3-hq?sABC=582r034r%230%235469p473qo9365nr3n7564s9sn
        media_content_type: music
    - service: media_player.volume_set
      data_template:
        entity_id: '{{trigger.entity_id}}'
        volume_level: 0.2

Thanks for your help!!! You are awesome!

5 Likes