Storing a snapshot of the current temperature upon an Automation trigger

The summer is coming and Home Assistant got me completely crazy about measuring everything that I can. So, I’ve bought a wood heater for the inflatable pool and have a series of temperature sensors (DS18B20 with ESPHOME) all ready to measure the water temperature. In addition, I have a POWR2 with Tasmota to detect if the pump is running, to make sure the water in the wood heater doesn’t overheat, etc. etc. All big fun!

I detect that the heating has started by seeing the pump power exceeding a threshold and measuring the difference in the actual temperature between water from the pool and water going back to the pool.
The only thing missing, is that I want to calculate how much the temperature increased since I started this session of heating.
In order to do so, I need to ‘store’ the temperature of the water when I started heating as the reference… And that’s where my knowledge runs short.

So, what I’m looking for, is a way to create a sensor in configuration.yaml of which I only update the value when a certain automation in automations.yaml is being triggered.
The idea is, that when I detect the start of heating the pool, I copy the current water temperature value of a sensor to this self-made variable and then simply subtract this stored value from the current temperature to know how much the water heated-up since the start of this heating cycle.

I have an idea how to do all of this, except for copying the current value of a sensor only when it was triggered by an automation. I can’t declare a sensor in configuration.yaml without the value_template included. So, if I do it that way, it keeps overwriting the value with the actual value of the sensor.

Can anyone help me in the right direction to find a solution for this?

Trigger based sensors may be what you are after, e.g.

template:
  - trigger:
      - platform: state
        entity_id: switch.pool_heater
        from: 'off'
        to: 'on'
    sensor:
      - name: 'Stored Water Temperature'
        state: " {{ states('sensor.your_current_water_temp_sensor_here') }}"
        entity_id: switch.pool_heater

perhaps?

1 Like

Thanks Troon. Fixed.

1 Like

Wow! This Works!
Thank you very much for your quick help; wouldn’t have found this any time soon by myself! :wink:

It copies the value of the sensor when the trigger is given.
I’ve added unit_of_measurement: ‘°C’ and it works like a charm.

Thanks again!

1 Like