How to Retrieve Last Sensor Data and Timestamps in Home Assistant

Hi everyone! I’ve been diving into the world of Home Assistant and have a question that I’m hoping you all can help with. I’m trying to figure out how to get the last recorded value and timestamp for a sensor from the history database. I’ve noticed that the last_updated attribute resets to now() whenever I restart Home Assistant, which isn’t what I need. I really want to know the last time a sensor was actually seen, not just when it was last updated after a restart.

I’ve tried looking into templates and using JavaScript within button-card, but I’m not quite sure how to pull the historical data I need. If anyone has any tips or workarounds, I’d be super grateful!

On a related note, I’ve also been dealing with some Mosquitto broker issues after rebooting my Raspberry Pi. It seems like all my Tasmota devices get stuck in a loop of disconnecting and reconnecting, which is a bit frustrating. I’ve managed to fix it by turning off MQTT for each device and then re-enabling it one by one, but I’d love to find a more permanent solution. Any advice on Mosquitto or Tasmota settings that might help would be amazing!

Thanks in advance for all your help and insights. I’m really enjoying this community and all the knowledge shared here! :blush: