Condition template for an entity based on a trigger

Hi all,

I would like to create a template condition based on a trigger to assess whether a script is running. I’d like some help with the formatting.

  - id: scenes_kitchen_start
    initial_state: 'true'
    alias: 'scenes kitchen start'
    - platform: state
      entity_id:, switch.espresso, input_boolean.oven
      to: 'on'
    - condition: template
      value_template: :  {{ is_state(("script.{{ }}_turn_on"), 'off')}}
1 Like
value_template: "{{ is_state('script.' ~ ~ '_turn_on', 'off') }}"

Although I’m wondering if maybe you want trigger.to_state.object_id instead.

So you use tildes for templates in templates?

Not sure I understand your question. Tilde is a string concatenation operator.

Ah ok. Thanks.

Not got this. : -
“is_state(” ---- is asking if the state of this entity is “this possible state”
“(‘script.’” ---- so you are looking at ony “script.” objects
~ ---- looks like a string substution charachter to me so it then only matches with objects ending in -->
… “” (though as I write this it looks more like -->)
where the “” is -->
" ‘_turn_on’ " ???
but is " ‘off’ "
Nope, way over my head … is either the friendly_name, or the object_id (if it has no friendly_name), of the entity that caused the automation to trigger. So, e.g., 'Dish', or 'dish'.

Next the string concatenation operators (~) concatenate 'script.', the value of, and '_turn_on'. So, e.g., 'script.dish_turn_on'.

Next the is_state() function is called to see if that entity is 'off'. So it’s checking if the script of interest is off, which means it’s not running.

1 Like

Thank you, works perfectly.


Okay, I now understand that and I’ve made a note of it but ask me in a week’s time and I’ll only have a vague recollection (so I refer to my notes).
This depends upon a close correlation between entity names (be it id or friendly) and the associated script. BUT if the aim is to get the trigger to provide the necessary ‘par’ ‘ts to be cons’ ‘idered’ then that is a minor irritation.
Thanks for the explanation, it really does help.

I used to use concatenate() in lotus 123 macros, but that was a while ago now ! : - )))

~ ensures that every item being concatenated is a string.
+ just adds things willy nilly without ensuring it’s the same type.