Trigger Automation when Temp Change is Greater than 1 Degree

I have a very simple automation to send temperature change to a remote device.

automation 500:
  alias: 'AC Temp'
  trigger:
    platform: state
    entity_id: climate.sunroom
  action:
    - service: shell_command.maker
      data_template:
        message: 'setTemperature'
        state: "{{ state_attr('climate.sunroom', 'current_temperature') + 0.5}},0,99"

This works fine except it sends any change even less than 1 degree. I would like to prevent this and have it only trigger the action only when the temperature change is at least 1 degree or more. How can I do this?

condition:
  - "{{ trigger.from_state.state < trigger.to_state.state }}"

You lost me here I’m afraid :blush: I don’t understand how this equates to a 1 degree temp change.
I am assuming that trigger.from_state.state is not what is really placed under the condition but changed to some numeric vale just dont understand what that change would look like :blush:

Can you clarify what it is you are trying to get out of your sensor? If you simply want to know if the sensor’s state value increase more than 1 degree during a single update you could do that using a template condition as in the example below.

Also, you should limit your trigger to the attribute you are interested in. By not declaring a to:, from:, or attribute: variables you have created a trigger that will fire on every change of climate.sunroom's state as well as any change of any of its attributes.

automation 500:
  alias: 'AC Temp'
  trigger:
    platform: state
    entity_id: climate.sunroom
    attribute: current_temperature 
  condition:
    - condition: template
      value_template: "{{ (trigger.to_state.state - trigger.from_state.state)|abs > 1 }}"
  action:
    - service: shell_command.maker
      data_template:
        message: 'setTemperature'
        state: "{{ state_attr('climate.sunroom', 'current_temperature') + 0.5}},0,99"

However, this is not a great method because it relies on a large temp change between reporting cycles. Better options are the Trend and Threshold/Derivative sensor platforms.

2 Likes

They stated they only want a positive going change.

Oops. My mistake on not being clear enough. It is any change amount greater than (-/+)1 degree whether the temperature is rising or going down. (i.e from 22 to 23.1 or from 23.1 to 22. Either case should trigger the action)

Reading it again it looks like I misinterpreted your post. My mistake. Sorry.

Drew’s answer is the one you want.

1 Like

Aha. I was wondering if there was and abs function available. This will work fine. Thanks a lot

I was wrong. For some reason when the condition is enabled this no longer works

automation 500:
  alias: 'AC Temp'
  trigger:
    platform: state
    entity_id: climate.sunroom
    attribute: current_temperature 
##  condition:
##    - condition: template
##      value_template: "{{ (trigger.to_state.state - trigger.from_state.state)|abs > 1 }}"
  action:
    - service: shell_command.maker
      data_template:
        message: 'setTemperature'
        state: "{{ state_attr('climate.sunroom', 'current_temperature') }},0,99"

I thought maybe it was the abs but I tried different combinations (i.e float) with only a 0.1 change to make it trigger when I knew the temperature was rising/declining. Nothing I tried worked.

The log confirmed that the above automation works (albeit every 0.1 degeer change) but once the condition is enabled nothing shows up in this log.

My gut feeling is that it is related to the trigger.to_state.state and trigger.from_state.state. Correct me if I am wrong but does the from state value not change as soon as there is a temperature change. For example:
From = 24.1
A change occurs and
To = 24.2
Another change occurs and
To = 24.3
At this point does From not equal 24.2??

If that is correct then value_template: "{{ (trigger.to_state.state - trigger.from_state.state)|abs > 1 }} will never occur

The answer to your question is totally dependent on how your temperature sensor’s reporting works. Some sensor report every change, some report at a specific time interval, others do a combination… for example I tried the automation with a Xiaomi sensor warmed up to 85F and allowed it to drop to 65F and only had two executions of the action.

Which is why I included the following in my original comment:

2 Likes

Yeah, the sensor in question reports every 0.1 change and I am trying to avoid sending such small change to the remote device. I think I’ll look at my shell_command and change it to send these frequent changes to my local server, process it there and send only when it meets my criteria.

Thanks for your input

Just throttle filter your sensor if all you want to do is limit updates.