Simple Automatation that checks a specific attribute

Hey guys!

I installed my Rasberry pi with Hassio 3 days ago and I LOVE IT. however I have an issue that I can’t find any info on:

I want a simple automation that basically turns on my TV when my AVR is turned on EXCEPT when I stream spotify to the AVR. So here what i got so far:

Link to code:
https://pastebin.com/bwy2aZWZ

And the error:
2018-02-13 22:03:40 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: while parsing a block mapping
in “/config/configuration.yaml”, line 114, column 5
expected , but found ‘’
in “/config/configuration.yaml”, line 116, column 82

So there seems to be some syntax issues here, and I can’t for the love of me figure this out.

If pastebin didn’t mangle your config, your ‘- service’ line is not spaced properly

Under condition completely remove the entity_id line, and change the single quotes on the outside of the curly brackets of the template to double quotes.

1 Like

@flamingm0e Hmm, I can’t see that it pasted weird however it seems to work fine if the condition is removed, so I don’t think thats the issue.

@anon43302295. like so? value_template: "{{ states.media_player.denon_avrx2200w.attributes.source = ‘Spotify’}}"

that did not work unfortunately, however it is not like I need to create the template in configuration.yaml first or? sorry if that was a stupid question

Yeah, and it needs to be == too.

1 Like

YAY! Configuration valid! Now off to testing! THANKS!!

1 Like

It seems to work fine! thanks so much!

1 Like

I’m looking to do something along these lines (using an attribute in an automation). Did you end up needing to create a sensor template first? Or did putting it in the automation do it for you? Would you be able to post up your final, working code?

Thanks!

Hey oembob!

Nope, you just need to put in the exact code like stated above, now my automation looks like this:

 - alias: Turn on TV
   trigger:
     platform: state
     entity_id: media_player.denon_avrx2200w
     from: 'off'
     to: 'on'
   condition:
     condition: template
     value_template: "{{ states.media_player.denon_avrx2200w.attributes.source != 'Spotify'}}"
   action:
   - service: media_player.turn_on
     entity_id: media_player.sony_bravia_tv
   - service: light.turn_off
     entity_id: light.vardagsrum

So this turns my TV on and the living room light off when I turn on the AVR UNLESS it’s not streaming spotify, I hope it helps!

1 Like

Perfect, that is exactly what I needed! Thanks!