Created
December 2, 2020 18:15
-
-
Save dale3h/417f3e6fc2fc12a3e7c71fbeac5325c1 to your computer and use it in GitHub Desktop.
[Home Assistant] Restart Time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################ | |
# Automations / Restart Time | |
# Publish timestamps to MQTT broker on start and shutdown. | |
################################################################ | |
- id: restart_time_start | |
alias: Publish Start Time | |
description: Publish current timestamp to MQTT broker on startup. | |
mode: single | |
trigger: | |
- platform: homeassistant | |
event: start | |
action: | |
- service: mqtt.publish | |
data: | |
topic: homeassistant/start | |
payload: "{{ now()|as_timestamp }}" | |
retain: true | |
- id: restart_time_shutdown | |
alias: Publish Shutdown Time | |
description: Publish current timestamp to MQTT broker on shutdown. | |
mode: single | |
trigger: | |
- platform: homeassistant | |
event: shutdown | |
action: | |
- service: mqtt.publish | |
data: | |
topic: homeassistant/shutdown | |
payload: "{{ now()|as_timestamp }}" | |
retain: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################################ | |
# Sensor / Restart Time | |
################################################################ | |
# Sensor for Home Assistant start timestamp. | |
- platform: mqtt | |
name: Start Timestamp | |
unique_id: 120a114d-a8a1-4364-8d43-a35954b19239 | |
icon: mdi:timer-outline | |
state_topic: homeassistant/start | |
# Sensor for Home Assistant shutdown timestamp. | |
- platform: mqtt | |
name: Shutdown Timestamp | |
unique_id: affce05d-153b-48f2-af61-1333e50c2163 | |
icon: mdi:timer-outline | |
state_topic: homeassistant/shutdown | |
# Sensor for Home Assistant difference between start and shutdown times. | |
- platform: template | |
sensors: | |
restart_time: | |
friendly_name: Restart Time | |
unique_id: c252bb03-374f-41a9-9e41-d1e1e02b9d90 | |
icon_template: mdi:timer-outline | |
unit_of_measurement: s | |
device_class: timestamp | |
value_template: "{{ (states('sensor.start_timestamp')|float(0) - states('sensor.shutdown_timestamp')|float(0))|round(1) }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment