Automation state change doesnt work

Hello,

I am a bit new at home assistant.
I have a automation that if someone changes the channel to 3FM that it has to play 538. (Becouse my colleague doesnt like radio 538). However that doesnt work. When i execute the automation manually it works. But it looks like the trigger doesnt get fired. I think sensor.sonos_media_play_it is the error in this automation. Is someone similair with this problem or can help me solving it?
This is what i have.

id: eab049f0d63c4c70a3cd81e26734b69f
  alias: Geen 3FM afspelen
  trigger:
  - entity_id: sensor.sonos_media_player_it
    platform: state
    to: 3FM
  action:
  - data:
      entity_id: media_player.it
      source: '538'
    service: media_player.select_source
- alias: Sonos IT inschakelen
  description: Sonos IT inschakelen
  trigger:
  - at: '7:40'
    platform: time
  condition: []
  action:
  - data:
      entity_id: media_player.it
    service: media_player.media_play
  id: e42224af466b41f28a04765d4e091a0e

Kind regards,

Stan

  • Manually triggering an automation skips the trigger and the condition. To test your automation you will have to ensure the state of sensor.sonos_media_player_it changes to 3FM.
  • Please post the configuration for sensor.sonos_media_player_it
  • Try it like this:
    to: '3FM'

Hello @123 thanks for your asnver. where can i see the configuration of sensor.sonos_media_player_it? Do you mean in the automations panel? i changed 3fm to ‘3fm’

There’s nothing in the Sonos integration indicating that it automatically creates a Sonos-related sensor so I assumed you defined it manually in configuration.yaml (or in a separate file like sensors.yaml).

  • In your automation you defined it using capitalized letters like this: 3FM
  • For Home Assistant, 3FM and 3fm are not the same. Ensure you are using the correct one.
  • Go to Developer > Tools > States, find sensor.sonos_media_player_it in the list and confirm how it is spelled (3FM or 3fm).

@123 I am at my internship and didnt configure it. The automation doesnt work so they asked me to fix it.
In the list states there is no sensor.sonos_media_player_it so i think that is probely the problem.

Correct. You will need to define this sensor.

Hello @123 I am searching for a while how to define a sensor but i cant find it. Are you familiar with it?

Yes, I’m familiar with how to create a sensor.

What I don’t understand is why you have an automation that contains a sensor you know nothing about.

Whoever asked you to fix it, ask them about the sensor.

I assume that sensor.sonos_media_player_it is a template sensor (probably defined somewhere in a file called sensors.yaml or in configuration.yaml in the section:) that extracts the attribute source from media_player.it. For this automation, you shouldn’t need this sensor.

If my assumptions are correct, try changing your trigger part to this and see if it works:

trigger:
  - platform: template
    value_template: "{{ state_attr('media_player.it', 'source') == '3FM' }}"

Hi @Burningstone that trigger part doesnt work unfortunally.

id: eab049f0d63c4c70a3cd81e26734b69f
  alias: Geen 3FM afspelen
  trigger:
  - platform: template
    value_template: "trigger:\n  - platform: template\n    value_template: \"{{ state_attr('media_player.it',\
      \ 'source') == 'NPO 3FM' }}\"\n"
  action:
  - data:
      entity_id: media_player.it
      source: '538'
    service: media_player.select_source
  - data: {}
    service: script.sonos_tts

This is what i have now.

Because you didn’t do as I suggested, I told you to replace the whole trigger part, don’t know what you did here, it should look sometjing like this:

- id: eab049f0d63c4c70a3cd81e26734b69f
  alias: Geen 3FM afspelen
  trigger:
  - platform: template
    value_template: "{{ state_attr('media_player.it', 'source') == '3FM' }}"
  action:
  - data:
      entity_id: media_player.it
      source: '538'
    service: media_player.select_source
  - data: {}
    service: script.sonos_tts

Wow, nice colleagues you got there… They ask a guy who knows nothing about Home Assistant (just an assumption, no offence) to fix a problem with it.

@Burningstone i know. But home assistant automatically added that.

@Burningstone i litterly copy pasted :slight_smile:

If you go to the sidebar then select Developer Tools -> States, search for media_player.it. Please post a screenshot from this when “3FM” is playing on this media player.

Do you get any errors in the logs?

@Burningstone


i see no errors

If you go to Developer Tools -> Templates and enter this

"{{ state_attr('media_player.it', 'source') == 'NPO 3FM' }}"

does it show true?

@Burningstone No, false…

it works now. i changed 3FM to NPO 3FM