and if it is not entiti itself, how can i get these states in Node Red?
The task is it detect if HA was restarted from software command or rebooted because of electricity down.
I thought to check on start if the last state was stop - it means that it was soft restarted, if last state after start is also start (and not stop) - i assume it was hard reboot.
I don’t know about Node Red as I don’t use it, however in an automation you would create a trigger as below:
However, I am not sure this will achieve what you want as how can you tell if the start/stop was due to a power fail verses a manual operation.
I have an APC UPS which cost around £65 and this keeps my HA hardware powered up for about 40mins, it also sends me a notification that the power has failed because it is able to do so since it is still running.
In all cases Node Red or not - i would like to get history of this states, and not just trigger. Because HA startst faster as Node Red and it will be trigged before Node Red starts.
Made it. I mean i got datimetime of last start and last stop of HA with custom sensors!
sensor:
- platform: sql
queries:
- name: Hassio Last Stop Date Time
query: "SELECT * FROM 'events' WHERE event_type = 'homeassistant_stop' ORDER BY event_id DESC LIMIT 1;"
column: 'time_fired'
- platform: sql
queries:
- name: Hassio Last Start Date Time
query: "SELECT * FROM 'events' WHERE event_type = 'homeassistant_started' ORDER BY event_id DESC LIMIT 1;"
column: 'time_fired'