Setting Up History Stats Sensor for Past Temperature using MQTT

I was searching through the forum but was not able to find a solution for my problem. Could you guys please help out?

I’ve got a Shelly Switch via MQTT that registers the temperature of my hot water tank. I would like to build a kind of “trending indicator”. To do this I need to know temperatures from now and from the past (e.g.: 1, 5, 10 min ago) - and then do some math. As far as I understand I need to use the History Stat Sensor, however I did not find a solution to get back the sensor’s value in a given point in date and time.

Below is the MQTT sensor (that works for months now). The value itself seens to be a bit messy, because the Shelly device does not trim the string correctly so I needed to do that with regex.

  - platform: mqtt
    name: "Return Temperature"
    unit_of_measurement: "°C"
    state_topic: "shellies/shelly1-98F4ABD0C7A0/ext_temperature/0"
    value_template: "{{ value|regex_replace(find=':', replace='', ignorecase=False)|round(1) }}"

Thank you very much!

Hi, do you find a solution?