I want to be able to know which user was the one that e.g. changed state of input_boolean toggle and use that info in an automation.
Use case: a user “locks” some resources (e.g. lights, switches) for certain period of time or until s/he unlocks them. So when locked, only the user that locked them can change their state etc.
How would I go about that? I saw that user_id is populated in UI triggered events {... "context": {... "user_id": "d4dc8..." }} , but context is not available in automations, components, … (or is it?).
Anyone has any ideas? Using zones is not an option.
I want to execute some actions only if the trigger was not performed by a user, which happens when I toggle a wall switch or motion sensor for example.
condition:
- condition: template
value_template: >
{{trigger.to_state.context.user_id is none}}
but you can also check for user_ids, which you can find at http://your-url/config/users.
May I know how can your find out this value template ? {{trigger.to_state.context.user_id is none}}
I am trying to determine the user who scanned the tag in order to do further automation based on the user_id but I cannot find any related documentation.
I have tried the {{ states.state_object.context.user_id }}, but seems it only works for state objects like input_boolean … etc. Is there any way to find out which user fired an event like tag_scanned?
I’m not sure if it’s possible at the moment. According to the data documentation context only contains context_id, user_id, and parent_id.
The only way I see it happening at the moment and what I’ve implemented into one of my automations and will continue to use until another solution is found, is the below.
The id you’ll insert where is says user_id_here can be found under users.
variables:
triggered_by: >
{% if trigger.to_state.context.user_id == 'user_id_1' %}
User 1
{% elif trigger.to_state.context.user_id == 'user_id_2' %}
User 2
{% endif %}
Then in my notification simply use {{ triggered_by }} to output the user who triggered the action. If you have more than two users simply copy the elif line and insert it underneath User 2 as in the below.
variables:
triggered_by: >
{% if trigger.to_state.context.user_id == 'user_id_1' %}
User 1
{% elif trigger.to_state.context.user_id == 'user_id_2' %}
User 2
{% elif trigger.to_state.context.user_id == 'user_id_3' %}
User 3
{% endif %}