#Valid to use template for `entity_id` in a condition?
41 messages · Page 1 of 1 (latest)
No, you can't use a template there
What are you trying to accomplish? There may be a different way.
For example, use of fields or blueprints.
You can use such template in action, but I believe not in condition. However, you can use template condition like this:
condition: template
template_value: "{{ states(trigger.entity_id)|int < 10 }}"
Where trigger.entity_id is example of your entity.
Not sure if I'm meant to open a new thread or use this, as it's basically the same question I have. Let me know if a new thread is preferred.
In an automation, I am trying to trigger a script where the name of the script to trigger is the one selected in an input_helper.
I saw in the docs :
actions:
- action: light.turn_off
target:
entity_id: "{{ trigger.entity_id }}"
(from 'automation 3' in the examples on https://www.home-assistant.io/docs/automation/templating/ )
I've tried to add in my automation:
entity_id: "script.{{ states('input_select.livingroom_ac_morning') }}"
But that does not work.
Although the top of that page it says that 'the Home Assistant templates extensions to scripts are available for automations', I'm guessing this does not apply to every field.
So I'm wondering ... what is my best approach here?
- Somehow make this possible through variables or something?
- Trigger a script that figures out what's in the input_select, and have that then trigger that script?
Would welcome any thoughts on this / experience in the matter.
Where exactly are you using this entity_id field?
Yeah, give the full action code, where you're using this. Also would be nice to know what you have in that input_select. And trace please.
- id: livingroom_ac_daymode
alias: Turn on living room a/c when waking up
trigger:
platform: state
entity_id: input_select.home_mode
to: 'day'
condition:
condition: state
entity_id: binary_sensor.home_occupied
state: 'on'
action:
- service: script.turn_on
# entity_id: "script.{{ states('input_select.livingroom_ac_morning') }}"
entity_id: script.livingroom_airconditioner_auto26_focusedright
livingroom_ac_morning:
name: Livingroom a/c morning setting
options:
- livingroom_airconditioner_auto20
- livingroom_airconditioner_auto21
- livingroom_airconditioner_auto22
- livingroom_airconditioner_auto23
- livingroom_airconditioner_auto24
- livingroom_airconditioner_auto25
- livingroom_airconditioner_auto26
- livingroom_airconditioner_auto27
- livingroom_airconditioner_auto28
- livingroom_airconditioner_auto29
- livingroom_airconditioner_auto20_focusedright
- livingroom_airconditioner_auto21_focusedright
- livingroom_airconditioner_auto22_focusedright
- livingroom_airconditioner_auto23_focusedright
- livingroom_airconditioner_auto24_focusedright
- livingroom_airconditioner_auto25_focusedright
- livingroom_airconditioner_auto26_focusedright
- livingroom_airconditioner_auto27_focusedright
- livingroom_airconditioner_auto28_focusedright
- livingroom_airconditioner_auto29_focusedright
initial: livingroom_airconditioner_auto25_focusedright
Apologies, I should have included these in the first place. I just wasn't sure if I should post here or open a new thread.
Thanks for your help!
To further add, the scripts mentioned all look like this:
livingroom_airconditioner_auto25_focusedright:
sequence:
- service: remote.send_command
data:
entity_id: remote.kitchen_broadlink
device: livingroom_airconditioner
command: power_on_temp_25_fan_auto_direction_focusedright
I know this is a bit silly and I could just use that command directly, but this is how I built it close to a decade ago and I call these scripts from a bunch of automations so I've just not gotten around to rejigging that all.
I mean, obviously right now it works. I actually want to use the commented line 🙂
But if I uncomment that line, and comment the other ... HA says "Nope." and disables it. Let me try to reload to get you an exact error message. Give me 1 minute.
Hmm
The automation "Turn on living room a/c when waking up" (automation.set_living_room_air_conditioning_for_day_mode) is not active because the configuration has errors.
Error:not a valid value for dictionary value @ data['actions'][0]['entity_id']. Got "script.{{ states('input_select.livingroom_ac_morning') }}".
I don't think it should restrict entity id templating, but maybe for script run it does...
I've tried to find clarity in the documentation, but couldn't find consistent "does or does not support templating" for different fields.
Yeah I definitely have templates for entity IDs in several places. But I guess it differs action by action
Hmm, it feels a bit arbitrary that it wouldn't do that for script.turn_on. But I guess it's possible.
I just quickly did this in script:
action: script.turn_on
target:
entity_id: script.{{ "adjust_humidifiers_for_area" }}
It allows me.
You forgot target:
You can't use a template unless it's under data: or target:
Yep. That fixed it.
I'm really sorry! That's a mistake I shouldn't have bugged you guys with.
it does indeed 🙂