s1de7
February 20, 2022, 7:15pm
1
I used to run an automation with where I use trigger.entity_id
as entity_id
in a condition. After the last core update it stopped working. Log says:
'Entity {{ trigger.entity_id }} is neither a valid entity ID nor a valid UUID'
I use the trigger.entity_id
in the action in the same automation where it is working as expected. This is the full automation I set up for testing:
alias: test1
description: ''
trigger:
- platform: state
entity_id: switch.living_heat
condition:
- condition: state
entity_id: '{{ trigger.entity_id }}'
state: 'on'
action:
- service: switch.turn_on
data: {}
target:
entity_id:
- switch.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_off
mode: parallel
max: 10
I’m new to home assistant and I don’t know where to start. Because it was working before the update I guess I missed a breaking change…?
123
(Taras)
February 21, 2022, 4:02am
3
A State Condition doesn’t support a template (not in the current version or in previous versions).
Remove the State Condition and specify the desired state-change in the State Trigger:
alias: test1
description: ''
trigger:
- platform: state
entity_id: switch.living_heat
from: 'off'
to: 'on'
condition: []
action:
.. etc ...
s1de7
February 21, 2022, 12:06pm
4
Thank you for your reply!
The above code is just a quick test. Here is my original automation which was definitely working before 2022.2.9:
- id: '1644834618661'
alias: home/heat/manual
description: Translate manual setting on valves to automation switches
trigger:
- platform: state
entity_id:
- climate.living_valve_1
- climate.living_valve_2
- climate.bedroom_valve
- climate.kids_valve_1
- climate.kids_valve_2
attribute: occupied_heating_setpoint
condition: []
action:
- choose:
- conditions:
- condition: numeric_state
entity_id: '{{ trigger.entity_id }}'
attribute: occupied_heating_setpoint
above: '20'
- condition: numeric_state
entity_id: sensor.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_valve_setpoint
below: '32'
sequence:
- service: switch.turn_on
data: {}
target:
entity_id: switch.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_boost
- service: switch.turn_off
data: {}
target:
entity_id:
- switch.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_off
- conditions:
- condition: numeric_state
entity_id: '{{ trigger.entity_id }}'
above: '14'
attribute: occupied_heating_setpoint
- condition: state
entity_id: sensor.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_valve_setpoint
state: '14'
sequence:
- service: switch.turn_on
data: {}
target:
entity_id: switch.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_heat
- conditions:
- condition: numeric_state
entity_id: '{{ trigger.entity_id }}'
above: '5'
attribute: occupied_heating_setpoint
- condition: state
entity_id: sensor.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_valve_setpoint
state: '5'
sequence:
- service: switch.turn_off
data: {}
target:
entity_id:
- switch.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_off
- conditions:
- condition: numeric_state
entity_id: '{{ trigger.entity_id }}'
attribute: occupied_heating_setpoint
below: '32'
- condition: state
entity_id: sensor.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_valve_setpoint
state: '32'
sequence:
- service: switch.turn_off
data: {}
target:
entity_id:
- switch.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_boost
- conditions:
- condition: numeric_state
entity_id: '{{ trigger.entity_id }}'
attribute: occupied_heating_setpoint
below: '20'
- condition: state
entity_id: sensor.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_valve_setpoint
state: '20'
sequence:
- service: switch.turn_off
data: {}
target:
entity_id:
- switch.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_heat
default:
- service: switch.turn_on
data: {}
target:
entity_id: switch.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_off
- service: switch.turn_off
data: {}
target:
entity_id:
- switch.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_boost
- switch.{{ (trigger.entity_id.split(".")[1]).split("_")[0] }}_heat
mode: queued
max: 30
As you can see I can’t simply do this by adding the conditions to the trigger.
I have also tried to use template states without success. I have access to the trigger var like this:
"{{ trigger.entity_id == 'climate.living_valve_2' }}"
(renders true)
and I can access the attribute by entity id like this:
"{{ (state_attr('climate.living_valve_2', 'occupied_heating_setpoint')|int) > 5 }}"
(also renders true)
But this one is just not working (renders false, no error):
"{{ (state_attr('trigger.entity_id', 'occupied_heating_setpoint')|int) > 20 }}"
What have I missed?
123
(Taras)
February 21, 2022, 1:15pm
5
In which version exactly? You’ll need that should you want to report this as a bug in the GitHub Core repository.
Here’s an identical failure report, from July 2021, due to the same reason:
You can’t template that field. Good rule of thumb: if the field is outside service call or service data, it can’t be templated unless the docs mention it.
If the feature was added, between July and February, it doesn’t appear to have been included in the documentation; it contains no example of what you want to do. The only examples (that I could find) in this forum of where it’s attempted are reports of failure.
petro
(Petro)
February 21, 2022, 1:20pm
6
I don’t see how that could have worked. You can’t template any condition outside template conditions. Also, you could use variables to reduce the number of templates you got there and put all the conditions into a single condition
123
(Taras)
February 21, 2022, 1:35pm
7
s1de7:
But this one is just not working (renders false, no error):
"{{ (state_attr('trigger.entity_id', 'occupied_heating_setpoint')|int) > 20 }}"
Remove the quotes from 'trigger.entity_id'
.
s1de7
February 21, 2022, 3:04pm
8
Well, I am sure that it worked. I don’t care enough to roll back and proove it and I even asked my wife who was using the automation if I’m crazy. (She said yes, but that’s another story.)
I am perfectly fine using template conditions. What I still don’t understand:
How can I put all into a single condition while they trigger different combinations of actions?
s1de7
February 21, 2022, 3:08pm
9
Thank you very much!
I changed everything to use template conditions and now it’s working - like before the update. I don’t need to file a bug if my old aproach is not even supposed to work this way.
tom_l
February 21, 2022, 10:59pm
10
Nope. This has never been valid:
You need to use a template condition here.