#Specializing Automation for a certain user

1 messages · Page 1 of 1 (latest)

tall hearth
#

I have this automation working to stop switches from being switched.
How can I specify this for a certain user? I need to do it for some users.

`alias: Prevent Access to Dummy Light
description: ""
triggers:

  • entity_id:
    • input_boolean.dummy_light_1
      trigger: state
      conditions:
  • condition: state
    entity_id: input_boolean.light_access_control
    state: "off"
  • condition: state
    entity_id: input_boolean.automation_lock
    state: "off"
    actions:
  • data:
    message: "TT: {{ trigger }} "
    level: info
    action: system_log.write
  • target:
    entity_id: input_boolean.automation_lock
    action: input_boolean.turn_on
    data: {}
  • target:
    entity_id: input_boolean.dummy_light_1
    action: input_boolean.toggle
    data: {}
  • delay:
    hours: 0
    minutes: 0
    seconds: 0
    milliseconds: 1
  • target:
    entity_id: input_boolean.automation_lock
    action: input_boolean.turn_off
    data: {}
    mode: single`

I tried the template, but the triggers don't have any context or user-related information.
{{ trigger.context.user_id == 'defcef455af7458496656999f9f3800d' }}

2024-12-11 14:54:25.233 INFO (MainThread) [homeassistant.components.system_log.external] TT: {'id': '0', 'idx': '0', 'alias': None, 'platform': 'state', 'entity_id': 'input_boolean.dummy_light_1', 'from_state': <state input_boolean.dummy_light_1=off; editable=False, icon=mdi:lightbulb-outline, friendly_name=Dummy Light 1 @ 2024-12-11T14:54:25.039918+02:00>, 'to_state': <state input_boolean.dummy_light_1=on; editable=False, icon=mdi:lightbulb-outline, friendly_name=Dummy Light 1 @ 2024-12-11T14:54:25.233094+02:00>, 'for': None, 'attribute': None, 'description': 'state of input_boolean.dummy_light_1'}

and tried the person.state, but it didn't set correctly; all users' states were unknown.
condition: state entity_id: person.kutad state: home

any solution?

agile coral
marsh goblet
#

trigger.context.user_id should be trigger.to_state.context.user_id?

agile coral
#

state change triggers should have context at the trigger level IIRC

#

lemme double check

#

you're correct, it's at the state level, not trigger

tall hearth
#

2024-12-11 15:45:42.399 ERROR (MainThread) [homeassistant.helpers.template] Template variable error: 'dict object' has no attribute 'context' when rendering '{{ trigger.context.user_id == 'defcef455af7458496656999f9f3800d' }}' 2024-12-11 15:45:42.405 WARNING (MainThread) [homeassistant.components.automation] Error evaluating condition in 'Prevent Access to Dummy Light _ yazan': In 'condition' (item 1 of 3): In 'template' condition: UndefinedError: 'dict object' has no attribute 'context'

latent coral
agile coral
#

context needs some consistency in triggers

tall hearth
#

its work thanks