Update number to "from_state" value

Hello all,

I am trying to update a number helper called “Previous Temperature” from a trigger change.

I have an automation that looks like this (in YAML):

alias: AutoTempMath
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.main_temp_room1
condition: []
action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.previous_temperature
      value: "{{states('trigger.main_temp_room1.from_state') }}"
mode: single

The trigger is working… but the number is not getting updated.

This entity automatically updates every 15 minutes, and ultimately what I am trying to do is show the difference between the previous value and the current value. If there is a different way to do this than setting the previous value to a number, then having a card that does math (subtracting the current from the previous to show the change).

I did some searching in the forums here, but other similar things are around energy and utilize a meter (which I don’t think will work in this example).

{{ trigger.from_state.state|float(0) }}

That did it. Final code:

alias: AutoTempMath
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.main_temp_room1
condition: []
action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.previous_temperature
      value: "{{trigger.from_state.state | float(0) }}"
mode: single
1 Like