Condition - state change is NOT from -other Automation-

Hi,

i have 1 Automation for Light on/off with Motion-Sensor. This is default.

Now I will toggle-off this automation, when the light state changes from other way (UI-Frontend, HomeKit, ec.).
May idea is to to build a automation and check with conditions the state change from the light and when the change is not from the motion-automation, then toggle off the motion-automation. And when the light turn_off, to toggle_on the motion-automation.

is this possible?

Welcome!

Have a look here:

1 Like

thx, but this solution doesn’t works for my problem.

So I need to check for specific Automations.

Im confused about. I see in the logbook if the lights turn on/off include the triggered automation. So If hass can log this it must be possible to use this for automations?

This is not a recommended design practice; automations should avoid programmatically disabling other automations as a normal part of their operation. The recommended practice is to allow an automation to inhibit another automation. In other words, one automation can set a flag (such as an input_boolean) that is referenced by another automation’s condition. The flag’s state controls the other automation’s behavior.

This recommended practice reserves disabling an automation for other purposes (i.e. temporarily removing it from service for deprecation, isolation, experiment, etc). In other words, an automation is never automatically disabled as part of normal day-to-day operations but only manually for exceptional reasons.

Okay, thank you, I understand so far.

This means that I would not control the automation but a Bool helper, which in turn is queried in automation.

However, this does not yet solve the question of how I control this helper. So that when the light changes, the second automation checks and recognizes that the change is not triggered by the 1st automation and then switches the helper.

This stops an automation from running the actions when automation.xyz is what triggered it.

- condition: template
  value_template: "{{ trigger.to_state.context.parent_id != states.automation.xyz.context.id }}"

EDIT: Assuming this is a state trigger.

I’m sorry, I’m still new with home assistant.

But I don’t understand that.

If I enter … = states.automation.test.context.id }}" as a condition, it does not work.

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
1 Like

I See, the UI- Editor…

And now, It works fine!

Thank u very much!

EDIT: It doesn’t works :frowning:

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 :slight_smile:

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)