I was looking at James McCarthy’s github (https://github.com/JamesMcCarthy79) and I’m very interested into calculating how much time it takes to have HA up and running after a reboot (or cold start in the event of a power failure).
Here is a screenshot of what he has done:
When looking at his config, he is getting a value from his MQTT Broker.
Since the MQTT Broker is involved, there is some kind of black magic done up there that is not covered by his configuration files.
So, the question, does anyone has an idea of how to achieve that? It may be using MQTT or anything else. If I had to choose, I would like to have the feature entirely done from HA (in Python, or whatever else). But hey, if you guys know a solution involving ANYTHING, let me know!
Otherwise, you may shoot some ideas where to look at in order to do some kind of a brainstorm!
I would suggest you ask this question on his github since he obviously has the answer?
I would suspect a third party script that runs at book and published to MQTT
Yeah I came across that post as well, and indeed, it does give me the reboot time… but what I wanted to have is how long it took to completely boot and have HA fully loaded and ready to rock!
Now remember that this will give you the difference between boot and last HA start:
If you restart your HA instance after that, it’ll give you something ginormous
But yeah, indeed, if I just restart the instance (and not the entire computer), it will most likely show a wrong value. Since I’m running HA in a Docker container, I almost never restart the host itself…
no matter what, I appreciate your knowledge… I’m quite new in HA. Your knowledge is great value!
I would edit the startup script for Hass. Have it publish the current time to MQTT right before it starts Hass. Then, in an automation, have a homeassistant start trigger read that value compare to current time and done.
You could also set a trigger on home assistant stop and start to get “restart time” which might be a little longer than startup time since Hass likely has shutdown activities to perform.
If you’re using docker, you can add ha dockermon from @philhawthorne. It’ll give you the docker start time. Then use the above to compute the time it takes ha to load
I was under the impression ha dockermon might be deprecated since the last real update was from quite some time ago. I’ll give it a try for sure.
Anyhow, the docker start time would give me the timestamp of when the docker has started? The best case would be to have the timestamp of when HA is fully loaded and up and running.
Not deprecated, I use it all the time. Dockermon gives you container up / start time. Ha still needs to load after that so it’ll be as close as what you’re after
That’s essentially when HA is “ready to rock” following a restart, you could then have a script action that takes the current time, locates the restart time in the home-assistant.log, and subtracts the two and stores it in a sensor…
Usually, you just want to know when you can log back in. I have an action on that trigger that sends a notification to my TV (which is where I do a log of my tinkering). That way I know I can get back in.
Which I assume, haven’t tested, is fired as part of a restart. You could also use that as a trigger to store a timestamp in a sensor. Then trigger another automation on
homeassistant_start
which stores the delta between stop and start, which would be the “Startup Time Elapsed” for Home Assistant itself. It depends what you’re trying to get at…
What I’m trying to get at is the time it takes for HA to completely boot. I’m currently building everything around it and I would like to monitor how long it takes to boot. I would use that info as a metric so I can optimize things afterwards and reduce boot time (and share to other what I’ve done to optimize).
That said, HA isn’t an operating system, it’s an application. Hence the delta in time between an actual cold restart of the host platform AND HA vs. the restart of just HA itself. Which are you looking to “predict” as they’ll be two different amounts of time.
The use case is the following: I’m living in an area that suffers power failures more frequently than usual. I would benefit having a system that boots as fast as possible. Moreover, by adding components, I will be able to tell whether or not a component is heavier to load than another…
I’m also using custom python scripts that aren’t optimized for the fastest execution. By having that info, I’ll have a metric telling me if the loading time is fast or not.
It makes perfect sense, to a point.
Why wouldn’t you just invest in a UPS, just for your Raspberry PI? If you put a UPS on it, and had it monitor the UPS status, it would probably run all day without interruption.
Just curious. I’m also not sure why something that loads in 1 second vs. 2 seconds is going to make a significant difference in your setup.
I’m currently running off a NUC, and after reading the UPS performance chart, I was under the impression it wouldn’t last long enough without losing power entirely. But yeah, I will invest in a UPS anytime soon.
As for the 1 or 2 seconds… it’s true, it is not a big deal, but I’m still learning HA and, while I’m learning, I wanted to develop a solution as close as possible to the reality. But yeah, if the boot time show 1m21sec but in reality it is 1m31sec, hey, no big deal! haha
But with all the replies I’ve got in this topic, I’ve learned a lot… and one day, I will feel confident enough to help other users struggling with issues I’ve been through.
sensor:
- platform: command_line
name: HA Start
command: grep -m1 'Home Assistant initialized' home-assistant.log | awk '{ print $6, $7, $8, $9, $10 }'
############################################################################
## In order to use sensor.ha_start, set the info logs in this way
############################################################################
# logger:
# default: warn
# logs:
# homeassistant.bootstrap: info