I just started using mqtt and its been an uphill journey. I’m close to getting what I want. The big issue was preserving the time since a sensor changed after an HA reboot. I have the time coming back correctly and surviving reboot. I just cannot take the time stamp and turn it into the duration of time from the current time.
I have a sensor that is giving me the time that an event happened:
2021-03-08 05:57:30.267209-06:00
How do I turn this into hours minutes from current time? If the time stamp was for 10 minutes ago, I want the output to say 10 minutes ago or something similar. I’m flexible I just need this time since that timestamp and have it update when I use on a card. I’ve spent so much time figuring this out using mqtt. I just cannot take it home. I think it has to do with adding the .last_updated but not sure. I might be going completely in the wrong direction. Any help would be greatly appreciated. Thanks in advance!
Here is the rest of my code:
sensor:
- platform: mqtt
state_topic: "events/clarkmeowspace/on"
name: "MQTT ClarkMeowSpace"
- platform: template
sensors:
clark_meowspace_last_timestamp:
value_template: >-
{{ strptime(states('sensor.mqtt_clarkmeowspace'),"%d/%m/%Y") }}
clark_meowspace_timesince_timestamp:
value_template: '{{ relative_time(states.sensor.clark_meowspace_last_timestamp.last_changed)}}'