How can I create a temporary variable of a dynamic sensor to compare values in an automation?

I’m trying to create an automation to switch on and off heating in a room when it goes above or below the set-value (using a tado smart heating system). The problem is that once it goes above the set value and the automation turns it off, this alters the set value. I want to temporarily create a variables with the set value at the point of turning it off, and then when the temperature drops below that prior value, turn it back on.

Any ideas?

My difficulty looks to hinge on the problem of creating temporary variables within an automation. I’ve looked at tens of thread on this and have not found it less confusing!

My automation is currently like this:

alias: zack not too hot
description: ""
trigger:
  - platform: numeric_state
    entity_id: sensor.zacks_bedroom_temp_temperature
    above: sensor.zacks_target_temp
condition:
  - condition: state
    entity_id: climate.zacks_room
    state: heat
  - condition: time
    after: "18:00:00"
    before: "08:00:00"
action:
  - service: climate.turn_off
    data: {}
    target:
      device_id: b8d32efe8c4e381d4ff2234eec5d1163
  - service: notify.mobile_app_pixel_6
    data:
      message: zacks room thermocomparison ran
  - wait_for_trigger:
      - platform: numeric_state
        entity_id: sensor.zacks_bedroom_temp_temperature
        below: input_number.zacks_original_target
  - service: climate.turn_on
    data: {}
    target:
      device_id: b8d32efe8c4e381d4ff2234eec5d1163
mode: single

I tried to use input_number.zacks_original_target, a helper I created, to be set in the first part of the automation to the value of sensor.zacks_target_temp, but can’t find the right syntax.

Can someone help me?

Hi @markdevine

I think a service call like this should store your temperature in your helper:

service: input_number.set_value
data:
  value: "{{ states('sensor.zacks_bedroom_temp_temperature') }}"
target:
  entity_id: input_number.zacks_original_target
1 Like

That should indeed.

Op also if you can target the climate entity by entity not by device if you can help it to save yourself edit time later if you ever replace the device.

Wonderful- thanks.
I’ll make the edit and report back

All worked as expected - many thanks