Hi guys,
Just reinstalled my Home Assistant after some time without it. I put back my old automation file and get som weird new error, anyone who can help me?
Error: Error while executing automation automation.changed_to_sonos_from_tv. Invalid data for call_service at pos 1: not a valid value for dictionary value @ data[‘entity_id’]
id: toTVfromSONOS
alias: Changed to TV from SONOS
trigger:
platform: state
entity_id: input_select.active_status
from: ‘SONOS’
to: ‘TV’
action:
Please format your code. YAML’s syntax (indenting and quotation characters) is critical to its operation. If presented unformatted, it’s difficult to tell if you have syntax errors.
The error message you are receiving is due to the template.
When the if statement is true, entity_id is set to switch.pioneer.
When the if statement is false, entity_id is set to nothing. That’s an invalid option for the switch.turn_on service.
- id: toTVfromSONOS
alias: Changed to TV from SONOS
trigger:
- platform: state
entity_id: input_select.active_status
from: 'SONOS'
to: 'TV'
action:
- service: switch.turn_on
data_template:
entity_id: >-
{% if is_state('switch.pioneer', 'off') %}
switch.pioneer
{% endif %}
- service: homeassistant.turn_on
entity_id: script.pioneer_volume_down_20
- delay: '00:00:03'
- service: homeassistant.turn_on
entity_id: script.optisk_1
Thank you for your reply. Above you can see my code presented in codeblocks. Second thing, what do I do when i only want to start my surround system when it’s off, and do nothing when its on?
That requirement wasn’t clear from your original automation (where the template would simply fail if switch.pioneer was already on).
Question for you: What happens if you turn on switch.pioneer when it’s already on?
My guess is that it simply stays on and nothing bad happens (other than we needlessly sent the on command). If that’s true then the automation is simplified:
- id: toTVfromSONOS
alias: Changed to TV from SONOS
trigger:
- platform: state
entity_id: input_select.active_status
from: 'SONOS'
to: 'TV'
action:
- service: switch.turn_on
entity_id: switch.pioneer
- service: homeassistant.turn_on
entity_id: script.pioneer_volume_down_20
- delay: '00:00:03'
- service: homeassistant.turn_on
entity_id: script.optisk_1
In that case, I recommend you restructure the automation’s action. You are already using scripts so I suggest you call one script when switch.pioneer is off and another script when it is on.
- id: toTVfromSONOS
alias: Changed to TV from SONOS
trigger:
- platform: state
entity_id: input_select.active_status
from: 'SONOS'
to: 'TV'
action:
- service: script.turn_on
data_template:
entity_id: script.pioneer_is_{{states('switch.pioneer') | lower}}