Change value when number decreases

Hi there,

I am struggling with my automation: the climate entity should set the temperature in case it has been set a lower value compared to the previous one:

alias: Sync Wohnraum Thermostats
description: ""
trigger:
  - platform: state
    entity_id:
      - climate.arbeitszimmer_2
    attribute: temperature
  - platform: state
    entity_id:
      - climate.badezimmer_2
    attribute: temperature
condition:
  - condition: template
    value_template: "{{ trigger.to_state.state|float > trigger.from_state.state|float }}"
action:
  - service: climate.set_temperature
    data:
      temperature: "{{trigger.to_state.attributes.temperature}}"
    target:
      entity_id: climate.wohnzimmer_2
    enabled: true
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
mode: queued
max: 2

What am I missing?

If you want to set the temperature to its previous value use:

trigger.from_state.attributes.temperature

Your condition is checking if the new value is higher than the previous value.

Change this:

temperature: "{{trigger.to_state.attributes.temperature}}"

To this:

temperature: "{{trigger.from_state.attributes.temperature}}"

At the moment you are setting the thermostat to the temperature it changed to. i.e. no change.

When what you want to set the temperature to is the the temperature it changed from.

EDIT: scooped by 123 again!

to > from means increasing, nor decreasing, maybe thats the reason?

1 Like

Yeah there is that as well. Should be:

condition:
  - condition: template
    value_template: "{{ trigger.to_state.state|float < trigger.from_state.state|float }}"

Also to avoid errors the triggers should be changed to:

trigger:
  - platform: state
    entity_id:
      - climate.arbeitszimmer_2
    not_to:
      - unavailable
      - unknown
    attribute: temperature
  - platform: state
    entity_id:
      - climate.badezimmer_2
    attribute: temperature
    not_to:
      - unavailable
      - unknown

This will still allow triggering on any change of the temperature attribute but will not trigger on changing to an unknown or unavailable value which will cause errors with the template condition.