From 0ae61eda66f3a92d71f9d2293f0a6072f0ca06e3 Mon Sep 17 00:00:00 2001 From: Ryan Horiguchi Date: Thu, 16 Nov 2023 00:58:32 +0100 Subject: [PATCH] Some tweak to hs server uptime --- .../server/home-assistant/lovelace.nix | 5 +++- .../server/home-assistant/systemmonitor.nix | 23 ++++++++++++------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/configuration/devices/headless/server/home-assistant/lovelace.nix b/configuration/devices/headless/server/home-assistant/lovelace.nix index e73e2cf4a..6f53e03d3 100644 --- a/configuration/devices/headless/server/home-assistant/lovelace.nix +++ b/configuration/devices/headless/server/home-assistant/lovelace.nix @@ -277,9 +277,12 @@ in { type = "entities"; title = "Info"; entities = [ + { + name = "Last rebooted"; + entity = "sensor.last_rebooted"; + } { name = "Uptime"; - icon = "mdi:clock"; entity = "sensor.uptime"; } { diff --git a/configuration/devices/headless/server/home-assistant/systemmonitor.nix b/configuration/devices/headless/server/home-assistant/systemmonitor.nix index 0bbc92ab5..643a87de8 100644 --- a/configuration/devices/headless/server/home-assistant/systemmonitor.nix +++ b/configuration/devices/headless/server/home-assistant/systemmonitor.nix @@ -17,6 +17,21 @@ in { ]); }]; + template = [{ + sensor = [ + { + name = "Uptime"; + icon = "mdi:clock"; + state = "{{ states('sensor.last_boot') | as_datetime | relative_time }}"; + } + { + name = "Last rebooted"; + icon = "mdi:clock"; + state = "{{ states('sensor.last_boot') | as_timestamp | timestamp_custom('%d.%m.%Y %H:%M:%S') }}"; + } + ]; + }]; + command_line = [ { sensor = { @@ -41,14 +56,6 @@ in { command = "${pkgs.coreutils}/bin/uname -r"; }; } - { - sensor = { - name = "Uptime"; - scan_interval = 60; - command = - "${pkgs.coreutils}/bin/uptime | ${pkgs.gawk}/bin/awk -F '( |,|:)+' '{d=h=m=0; if ($7==\"min\") m=$6; else {if ($7~/^day/) {d=$6;h=$8;m=$9} else {h=$6;m=$7}}} {print d+0,\"days\",h+0,\"hours\",m+0,\"minutes\"}'"; - }; - } ]; }; }