Pico1965
(Pico1965)
February 11, 2025, 6:32pm
1
Good evening!
For logging purposes I would like to know the user who restarted HA.
Here I found a nice method to understand the type of HA shutdown.
Since I already have an automation that triggers when HA reboots (and I would like to avoid creating one for when shutdown) I thought of something like this:
- trigger:
- platform: homeassistant
event: shutdown
sensor:
name: "autore_ultimo_riavvio_piattaforma"
icon: mdi:information-variant-circle-outline
state: "{{ user_info(trigger.event.context.user_id).name}}"
In order to record in the sensor the user who requested the reboot and go and read it in the reboot automation.
But the state is: unknown
Same in:
state: "{{ trigger.event.context.user_id}}"
Where I’m wrong?
123
(Taras)
February 11, 2025, 6:56pm
2
Refer to the table in the following post:
Based on my own testing, this is combination of values that characterize each action:
Action
id
parent_id
user_id
Physical
Not Null
Null
Null
Automation
Not Null
Not Null
Null
UI
Not Null
Null
Not Null
A more comprehensive list of actions can be found here .
If you are saying that your testing shows that Physical and UI produce identical combinations then, unfortunately for you, there’s no available means of distinguishing between the two.
Unless the triggering source was via the UI, the value of user_id
is normally null (none
).
Also, are you certain that the trigger object produced by a Homeassistant Trigger contains an event
property?
trigger.event.context.user_id
^^^^^