Skip to content

Commit fde7ace

Browse files
committed
Add uptime sensor
1 parent 992055f commit fde7ace

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

main.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,29 @@ text_sensor:
7474
icon: mdi:network-outline
7575
- platform: version
7676
name: "ESPHome Version"
77+
# Uptime Sensor
78+
- platform: uptime
79+
name: "Uptime"
80+
id: uptime_sensor
81+
update_interval: 360s
82+
on_raw_value:
83+
then:
84+
- text_sensor.template.publish:
85+
id: uptime_human
86+
state: !lambda |-
87+
int seconds = round(id(uptime_sensor).raw_state);
88+
int days = seconds / (24 * 3600);
89+
seconds = seconds % (24 * 3600);
90+
int hours = seconds / 3600;
91+
seconds = seconds % 3600;
92+
int minutes = seconds / 60;
93+
seconds = seconds % 60;
94+
return (
95+
(days ? to_string(days) + "d " : "") +
96+
(hours ? to_string(hours) + "h " : "") +
97+
(minutes ? to_string(minutes) + "m " : "") +
98+
(to_string(seconds) + "s")
99+
).c_str();
77100
78101
# Captive Portal is the portal created by this node when Wifi connection fails
79102
captive_portal:

0 commit comments

Comments
 (0)