Here is an idea to get you started.
I have a system set up to calculate the estimated time that the food I’m cooking in my smoker will be done. For that I need to calculate the rate of change of the food temperature and it’s “averaged” over 5 minutes (not exactly but close enough) by taking a temp reading every 5 minutes and storing the previous 5 minute reading in a variable attribute then comparing the current food temp to that 5 minute old reading. Then I divide by 5 to get the “degrees per minute” rate of change.
to do this you could change the trigger time to every 5 seconds and save the current value as the previous value. Then if positive (>0) turn on the boolean. if 0 or negative (<=0) then either turn off the boolean or do nothing.
I use the custom “hass-variables” integration (available in HACS - if you go that route make sure you get the “hass-variables” integration, tho. there is another variables integration that doesn’t support attributes).
Or you could do the same using input_number to store the previous reading.
here is the automation to set the variable current and history values:
- alias: Calc Rate of Change Smoker Food Temp
trigger:
- platform: time_pattern
seconds: "/5"
action:
- service: variable.set_variable
data:
variable: smoker_food_temp_history
attributes:
history_01: "{{ states('variable.smoker_food_temp_history') | float }}"
- service: variable.set_variable
data:
variable: smoker_food_temp_history
value: "{{ states('sensor.smoker_food_temperature') | float}}"
then you can add the following to the action section to turn on the boolean if the value is positive:
- condition: "{{ (((states('variable.smoker_food_temp_history') | float - state_attr('variable.smoker_food_temp_history', 'history_01') | float) / 5)) > 0 }}"
- service: input_boolean.turn_on
entity_id: input_boolean.your_boolean
Or since you only care about the absolute value difference (>5 between readings) then it can be changed to this:
- condition: "{{ ((states('variable.smoker_food_temp_history') | float - state_attr('variable.smoker_food_temp_history', 'history_01') | float)) > 5 }}"
- service: input_boolean.turn_on
entity_id: input_boolean.your_boolean
so the whole thing together (using condition version 2 above) would be:
- alias: Calc Rate of Change Smoker Food Temp
trigger:
- platform: time_pattern
seconds: "/5"
action:
- service: variable.set_variable
data:
variable: smoker_food_temp_history
attributes:
history_01: "{{ states('variable.smoker_food_temp_history') | float }}"
- service: variable.set_variable
data:
variable: smoker_food_temp_history
value: "{{ states('sensor.smoker_food_temperature') | float}}"
- condition: "{{ ((states('variable.smoker_food_temp_history') | float - state_attr('variable.smoker_food_temp_history', 'history_01') | float)) > 5 }}"
- service: input_boolean.turn_on
entity_id: input_boolean.your_boolean