You asked for a condition for when the state change is not from another automation, which is what’s provided. That condition will stop the automation from running when automation.xyz
is what caused the state change.
That’s the Automation…
alias: Küche Bewegungsmelder
description: ""
trigger:
- platform: state
entity_id:
- light.kuche_decke
- light.kuche_herd
condition:
- condition: template
value_template: |-
- condition: template
value_template: "{{ trigger.to_state.context.parent_id != states.automation.kuche_bewegung.context.id }}"
action:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.kuche_bewegungsmelder
mode: restart
it should be
alias: Küche Bewegungsmelder
description: ""
trigger:
- platform: state
entity_id:
- light.kuche_decke
- light.kuche_herd
condition:
- condition: template
value_template: "{{ trigger.to_state.context.id != states.automation.kuche_bewegung.context.id }}"
action:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.kuche_bewegungsmelder
mode: restart
I See, the UI- Editor…
And now, It works fine!
Thank u very much!
EDIT: It doesn’t works
I think the problem is that the changes for lights are more then 1 Automation.
Now I want to build the automation in such a way that only when HomeKit or the ui the changes come, the helper is switched on.
condition:
- condition: template
value_template: "{{ trigger.to_state.context.parent_id not in states.automation | map(attribute='context.id') | list }}"
what’s that?
what you just asked for?
I mean I don’t understand what the code
makes sure the automation only runs when it comes from a source outside automations.
states.automation → makes a list of all automations
| map(attribute=‘context.id’) → maps the automations context.id as the item in the list
| list → makes it a list
trigger.to_state.context.parent_id not in → checks to see if the parent_id is in the automation list
Thanks for the information
But it still doesn’t work.
If I control via HomeKit, it does not trigger.
alias: Küche Bewegungsmelder
description: ""
trigger:
- platform: state
entity_id:
- light.kuche_decke
- light.kuche_herd
condition:
- condition: template
value_template: >-
"{{ trigger.to_state.context.parent_id not in states.automation |
map(attribute='context.id') | list }}"
action:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.kuche_bewegungsmelder
mode: restart
check the trace and see why it didn’t trigger.
Triggered by the state of light.kuche_herd at 27. September 2022, 01:20:00
template condition
Stopped because a condition failed at 27. September 2022, 01:20:00 (runtime: 0.00 seconds)
remove teh quotes around your template.
Now the template is captured, but always seems to say yes.
id: '1664203448089'
alias: Küche Bewegungsmelder
description: ''
trigger:
- platform: state
entity_id:
- light.kuche_decke
- light.kuche_herd_links
- light.kuche_herd_rechts
condition:
- condition: template
value_template: >-
{{ trigger.to_state.context.parent_id !=
states.automation.kuche_bewegung.context.id }}
action:
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.kuche_bewegungsmelder
mode: single
It’s going to always say yes when the context isn’t coming from an automation.
Context can only distinguish it’s origin if it came from: Automations, A user action in the frontend, and scripts. Everything else (Physical press or from the integration) are seen with no context as they both look the same.
So, this automations condition will only stop when it comes from an automation.
Sorry, I can’t read non-english.
In the third picture you can see that the lamp was switched by automation (Küche Bewegung). So the condition is met.
Sorry, but I can’t confirm anything without seeing it in english. Remember, if another automation triggers the entity in your trigger, it will not continue. That’s the only use case here.
OK, I understand. But I’m still too new to understand the system
The aim was / is for automation (A) to check whether the lights have been switched by another specific automation (B) and if so, then nothing else does. If not, then keep running and turn on the helper.
Now the answer is always no… because even if the specific automation (B) switches the lights, the automation (A) is continued and the helper is switched on.