Notify what user turns Alarm off or on

I am using the Alarm Control Panel and I am able to send messages when sensors go off.
Is there a way to include the user name that turns the alarm ‘off’ or ‘on’ in the notify.notify message??
Thank you,

This is on my to-do list but I’ve only done some very provisional testing so YMMV.

The below is based on the this documentation and some previous discussions that I didn’t keep the links for.

It seems the user id can be retrieved - this is an alphanumeric string.
You can identify each user’s user id manually through the Configuration > Users section of the UI by viewing each user in turn.

Using the examples in the documentation I’ve just returned home, and my user id is recorded against my person entity and retrievable:

{{ states.person.tazuk.attributes.user_id  }}
# safer way below
{{ state_attr('person.tazuk', 'user_id')  }}

I was the last person to turn the kitchen lamp off last night, and can see my user id recorded against it now - so presumably the id persists until the lamp changes state:

{{ states.switch.kitchen_lamp_switch.context.user_id }}
# the below does NOT work - presumably because the context object is not included with the attributes. so the above must be used and should be protected against 'none' etc.
{{ state_attr('switch.kitchen_lamp_switch', 'user_id') }}

I don’t know of a way to retrieve user ids dynamically and the associated user name is not contained in the context object so my plan would be to store user ids in secrets.yaml, load them into individual template sensors on start-up and match them to produce a friendly name in automations etc.
I do something similar with phone numbers for text message handling, as it provides a single information store for easy maintenance.

Hope this is of some help.

Thank you. I am half way there. Now I need help with getting the Friendly name from the id.

Looking at History for the alarm I see that the interaction is recorded with the friendly user name. Is there a way to retrieve the History message and use that inside automation???

Not to my knowledge but then I’ve not really dug into it.

Hi,

Sorry for not responding sooner but I saw your query the other day and thought of trying to solve it to gain experience of HA as I’m very much a novice with only a month of use under my belt.

Based on the information provided I came up with this which does work but is extremely ugly due to the for loop and potentially this could break in the future if there are HA schema changes which is why I didn’t post

Sample Automation

alias: _Example Log user action
description: ''
trigger:
  - platform: state
    entity_id: input_number.hive_boost_temp
condition: []
action:
  - service: system_log.write
    data:
      message: >
        {% for person in states.person %} {%- if person.attributes.user_id ==
        states.input_number.hive_boost_temp.context.user_id %}hive_boost_temp
        modified by {{ person.attributes.id }}{% endif %} {% endfor %}
mode: single

Hope this helps

ps just replace

person.attributes.id

with

person.attributes.friendly_name
1 Like