Does any one have example of sensor that shows time since last HASS service start?
I have this one :
https://github.com/CCOSTAN/Home-AssistantConfig/blob/master/sensor/hass_stats.yaml
I’m still working to convert the time to time since. I tried using relative_time()
but could’t get it to work though. Its a good start though.
There is also code here for processing the date:
https://github.com/CCOSTAN/Home-AssistantConfig/blob/master/sensor/systemmonitor.yaml#L8-L50
I’m reading the date/time of the first line of the logfile and templating the output.
### HA Uptime #########################################################
- platform: command_line
name: "HA Uptime"
command: echo "$(($(date +%s) - $(date -d "$(head -n1 /home/homeassi/.homeassistant/home-assistant.log | cut -d' ' -f-2)" +%s)))"
scan_interval: 60
value_template: >-
{% set uptime = value | int %}
{% set seconds = uptime % 60 %}
{% set minutes = ((uptime % 3600) / 60) | int %}
{% set hours = ((uptime % 86400) / 3600) | int %}
{% set days = (uptime / 86400) | int %}
{%- if days > 0 -%}
{%- if days == 1 -%}
1 day
{%- else -%}
{{ days }} days
{%- endif -%}
{{ ', ' }}
{%- endif -%}
{{ '%02d' % hours }}:{{ '%02d' % minutes }}
Which leads to x day(s) hours:minutes
HI @CCOSTAN.
I was looking on your config today.
Last boot works great.
HA version was also moved to my config.
But your ha_last_restart tied to your automation that fires on homeassistant_start.
I don’t have such automation yet. Right now I don’t see that I need notification on startup. I’m in process of setting up and restart service several times during a day.
Nice idea to read log. I’ll try.