Delayed or earlier sensor value

I can detect taking a shower by a steep rise in bathroom temperature. I want to switch on the floor heating to dry the room out afterward, but only if it was relatively cool beforehand. Is there a way to get the temperature value of e.g. ten minutes ago?
If HA can’t do that I might construct a temperature sensor in Esphome to provide two values, temperature and earlier temperature.

You could use ‘trend’ below or (less nice) run a SQL to check temp of 10mins ago

Trend - Home Assistant (home-assistant.io)

You could create something like this:

template:
  - trigger:
      - platform: time_pattern
        minutes: "/1"
    sensor:
      - name: bathroom temperature history
        state: "{{ states('sensor.bathroom_temperature') }}"
        attributes:
          min0: "{{ states('sensor.bathroom_temperature')|float(0) }}"
          min1: "{{ this.attributes['min0'] }}"
          min2: "{{ this.attributes['min1'] }}"
          min3: "{{ this.attributes['min2'] }}"
          min4: "{{ this.attributes['min3'] }}"
          min5: "{{ this.attributes['min4'] }}"
          min6: "{{ this.attributes['min5'] }}"
          min7: "{{ this.attributes['min6'] }}"
          min8: "{{ this.attributes['min7'] }}"
          min9: "{{ this.attributes['min8'] }}"
          min10: "{{ this.attributes['min9'] }}"

Then the temperature as of ten minutes ago is in:

{{ state_attr('sensor.bathroom_temperature_history', 'min10') }}

Obviously, it’ll take ten minutes to populate fully as the values cascade down.

You could just use minutes: "/10" and two attributes, but this way you get more data…

1 Like

Thank you. I’ll try to understand that. HA documentation is really bad, nearly nonexistant, but the community makes up for it. Thank you all for your patience.

That’s not true at all. It may not cover this specific case, and I recognise it’s very English-centric but in general the documentation is good compared with some other open-source projects.

Trigger-based template sensors are here:

My suggestion simply cascades prior values down a “ladder” of attributes, updating once per minute.

Sorry, took me a while to find out how to update HA insider docker and do it. Your solution looks perfect, but if I understand the doc right, it can only be done in yaml. No problem as such. Unfortunately the “Helpers” tab is the only area where I can’t find a “use yaml editor” switch. How do I add this time_pattern one to my other helpers?
N.B: What does “float(0)” mean? Only full degrees without decimals? If so do I want “float(2)”?
Danke

Convert to a float if possible; otherwise return 0.

Thank you. Could you please also help with how and where to define that helper? I tried and failed.
Danke

It goes in configuration.yaml. See here:

Sorry for being thick, but where are all the other helpers kept, that I already have? And how can I look at their yaml?
Won’t adding one helper directly to the configuration affect all the others?
Danke.

Internally in the “registry”.

As of 2024.1, you cannot as far as I know.

No.

1 Like

Thanks. I’ll try and give feedback.
N.B: After taking part in UseNet for thirty years, your terse first answer was quite sufficient. Your edit might help later readers of this thread, though.
Danke

1 Like

Just make sure you only have one template: line in your file.

Let me first thank you. I’ve done it just like you suggested and it seems to work. The automation lets me choose entity and attribute in its conditions. Now I’d like to watch the output just for checking. In history I can’t choose an attribute. The entity shows a a coloured bar like on/off or home/away with states like “21.35” written in. To be able to graph it I’ve created a sensor helper (in UI) as “°C” with the template

{{ r5_temp_alt.attributes['m15'] }}

which yields unavailable. The helper in yaml is

- trigger:
    - platform: time_pattern
      minutes: "/5"
  sensor:
    - name: R5-temp-alt
      state: "{{ states('sensor.r5_temperature') }}"
      attributes:
        m00: "{{ states('sensor.r5_temperature')|float(0) }}"
        m05: "{{ this.attributes['m00'] }}"
        m10: "{{ this.attributes['m05'] }}"
        m15: "{{ this.attributes['m10'] }}"
        m20: "{{ this.attributes['m15'] }}"
        m25: "{{ this.attributes['m20'] }}"

That should be correctly copied from you with my sensor name. What am I doing wrong? N.B: I use an external file with

template: !include templates.yaml

but that works as intended as far as I can tell.
Danke

{{ state_attr('sensor.r5_temp_alt', 'm15') }}
1 Like

sensor.r5_temp_alt :wink:

1 Like

Yeah, just spotted that :thinking:. Fixed quickly enough that it doesn’t show in the post edit history and I can deny all knowledge.

1 Like

Troon, you’re not only knowlegeable but very, very patient. Thanks a lot for that. Works perfectly and a thin line is beginning to grow in the history graph. Now, beginning tomorrow, I can watch the timing and fine tune things if necessary.

1 Like

And I am being thick. You already had it in your first post and I failed to copy it correctly.

1 Like