uptime sensors (#998)

This commit is contained in:
w00zy
2023-08-28 18:28:30 +01:00
committed by GitHub
parent 97109f4ba5
commit b5614bb3d8

View File

@@ -81,6 +81,8 @@ time:
id: refresh_datetime id: refresh_datetime
on_time_sync: on_time_sync:
then: then:
- component.update: api_timestamp
- component.update: device_timestamp
- logger.log: "System clock synchronized" - logger.log: "System clock synchronized"
- script.execute: - script.execute:
id: refresh_datetime id: refresh_datetime
@@ -856,10 +858,26 @@ binary_sensor:
##### START - SENSOR CONFIGURATION ##### ##### START - SENSOR CONFIGURATION #####
sensor: sensor:
##### Uptime Template ##### ##### Uptime Sensors #####
- name: ${device_name} Last started - name: ${device_name} Uptime seconds
id: last_started id: uptime_sec
platform: uptime
internal: true
- name: ${device_name} API uptime
id: api_timestamp
platform: template platform: template
lambda: 'return id(time_provider).now().timestamp;'
internal: false
device_class: timestamp
entity_category: diagnostic
accuracy_decimals: 0
update_interval: never
- name: ${device_name} Device uptime
id: device_timestamp
platform: template
lambda: 'return (id(time_provider).now().timestamp - id(uptime_sec).state);'
internal: false internal: false
device_class: timestamp device_class: timestamp
entity_category: diagnostic entity_category: diagnostic
@@ -1351,9 +1369,6 @@ display:
- lambda: id(disp1).set_component_text_printf("boot.esph_version", "%s", "${version}"); ### esphome-version ### - lambda: id(disp1).set_component_text_printf("boot.esph_version", "%s", "${version}"); ### esphome-version ###
- wait_until: - wait_until:
api.connected api.connected
- sensor.template.publish:
id: last_started
state: !lambda 'return id(time_provider).utcnow().timestamp;'
- lambda: id(disp1).set_component_text_printf("boot.ip_addr", "%s", id(ip_address).state.c_str()); - lambda: id(disp1).set_component_text_printf("boot.ip_addr", "%s", id(ip_address).state.c_str());
- lambda: |- - lambda: |-
auto ha_event = new esphome::api::CustomAPIDevice(); auto ha_event = new esphome::api::CustomAPIDevice();