I’m trying to create a single automation that updates the status of my door locks back to my ISY994 and I’m running into unexpected behavior using a template for “entity_id”. The automation looks like this:
- id: 'Update Lock Status'
alias: Update Lock Status
initial_state: true
trigger:
- platform: state
entity_id: lock.garage_side_door_lock
- platform: state
entity_id: lock.front_door_lock
- platform: state
entity_id: lock.dr_door_lock
condition: []
action:
- data_template:
message: '{{ trigger.entity_id + "_state_isy994" }}'
service: persistent_notification.create
- service_template: lock.{{ trigger.to_state.state|replace("ed","") }}
data_template:
entity_id: lock.{{ trigger.entity_id + "_state_isy994" }}
This consistently gives me this error:
2019-03-12 13:17:31 ERROR (MainThread) [homeassistant.components.automation] Error while executing automation automation.update_lock_status. Invalid data for call_service at pos 2: not a valid value for dictionary value @ data['entity_id']
If I change to a static entity_id like this, it works fine:
data:
entity_id: lock.dr_door_lock_state_isy994
I’ve confirmed that the template is producing the right name by looking at the notification that’s produced and simulating it in the template dev tool. I’ve also tried the following with the same error:
data_template:
entity_id: >-
lock.{{ trigger.entity_id + "_state_isy994" }}
Any idea what the problem is?
Edit: Here’s a post that claims that it should work, but unfortunately details were lost to time: Templating problem (service_template and data_template)
Nevermind. I’m an idiot. The problem was that I was adding “lock.” onto the entity_id (copied from the service call) and I just need the entity_id. The correct clause looks like this:
- service_template: lock.{{ trigger.to_state.state|replace("ed","") }}
data_template:
entity_id: {{ trigger.entity_id + "_state_isy994" }}