#Condition for manual/automation/UI context ids

1 messages Β· Page 1 of 1 (latest)

heavy plinth
#

I had this automation working at some point but I broke it, and now I don't understand why it doesn't work properly.

It's all about the condition to distinguish if a light was toggled manually, or UI, or by an automation.

Atm I want this timer to run either if it was toggled manually or UI.

Here's the relevant bit of the automation trace when triggered by UI. Parent is clearly null, so none should be working. But it isn't.
Full step trace attached.

    context:
      id: 01K77QFWB8BTMV8Z24WHRFFVMH
      parent_id: null
      user_id: fd5af314dfad4f499cfc3a6e7029dbf2

Relevant automation condition. Attached full automation.

{{ trigger.to_state.context.parent_id is none }}

I had issues using variables, so I removed them. But it didn't fix it.

Thanks!

warm zenith
#

I haven't seen your automation, but if I had to do it, I would use id per trigger

#

Let's say, if the initial trigger is manual, I'll use a id called id_manual. And the same with the UI, Let's say id_ui

#

That way, you can know what have been the initial trigger πŸ™‚

errant dome
#

You need to use:
{# comment here #}

heavy plinth
heavy plinth
warm zenith
heavy plinth
heavy plinth
#

I guess it could be a template as trigger

#

it'd be just moving my condition to the trigger basically

warm zenith
#

I can switch on a smartplug trough a remote or through an automation.

#

In the remote instructions, I detect a simple click

#

That's a 'manual' switch on

heavy plinth
#

well, that's a different case as you're using an external source for the switch

warm zenith
#

Does that have sense in your automation? πŸ™‚

heavy plinth
#

not in mine, as there's no external source. It's either manual/automation/UI

warm zenith
#

Ah, ok, what do you mean by manual, then?

#

A hardware analog switch?

heavy plinth
#

it's a switch on the wall. Manual it's me going and pressing the button

warm zenith
#

A misunderstanding

heavy plinth
#

no prob

#

just curious if I was missing an alternative way

warm zenith
#

Do you measure the lamp power consumption?

#

That would be another way to know if the lamp is on, without an active automation

heavy plinth
#

not really. I just know its On consumption, so I have a virtual sensor

warm zenith
#

I'm lost then, sorry πŸ˜…

heavy plinth
#

I resolved it with the previous help, so no worries

warm zenith
#

In my HA head, "manual" now means a renote or similar, I need to not assume that πŸ˜…

heavy plinth
sudden oriole
#

Maybe because it took 14 seconds HA assumed the call in the automation failed. And when it does turn on after 14 seconds it is seen as not by the automation anymore.

heavy plinth
sudden oriole
#

It's the feedback to HA that matters. So maybe have a look at that the next time you walk in.

#

Might be that it does turn on directly but if the feedback is delayed to HA it may still see it as failed

#

for the 08:02:08 trace, can you see if the turn on step returned fail? (Although I'm not sure it will show it...)

heavy plinth
sudden oriole
#

how good is it's connection? Does the device map show it linked to a logical device? Might not be the really clossest device but if the parant is on the other side of the house that's not great

heavy plinth
# sudden oriole how good is it's connection? Does the device map show it linked to a logical dev...

I wouldn't say it's bad. It's a zigbee device, using z2mqtt. 60 lqi, not huge, but not giving problems.

Just tested twice but z2m log shows it going on instantly.

Automation
Perform action 'Light: Turn on' on Kitchen lights and Utility room light
Executed: 20 October 2025 at 09:46:27

Z2MQTT log
[20/10/2025, 09:46:27] z2m:mqtt: MQTT publish: topic 'zigbee2mqtt/Kitchen lights', payload '{"backlight_mode":"inverted","linkquality":156,"power_on_behavior":"off","state":"ON"}'

sudden oriole
#

mm, intermitterend issues are great... πŸ˜…

heavy plinth
#

no prob, I'll keep checking whenever it happens and see if I can spot something

misty dew
#

but I'm not completely sure

heavy plinth
sudden oriole
#

Had to check and I use the to_state version as well:

conditions:
  - condition: template
    alias: Not by automation
    value_template: "{{ trigger.to_state.context.parent_id == None }}"
  - condition: template
    alias: Not by UI
    value_template: "{{ trigger.to_state.context.user_id == None }}"