Setting up a trend sensor with conditions - clothes dryer automation from vent temperature

Hi all,

I have an automation that right now, works but doesn’t work well because of the trigger points. Simply creating an above or below numeric state trigger, makes it a bit sloppy in terms of start and stop times. The trend sensor has come up.

The automation is for a clothes dryer notification system, that also estimates time to completion. I simply put a temperature probe in the dryer vent and that data is being fed to HA via MQTT.

Here’s how the temperature changes for 2 loads of clothes drying.

The sensor updates every 61 seconds, and the gateway can take upto 16 seconds to send that to my mqtt server. So reporting time is 77 seconds at most.

One thing I’ve been able to calculate is that the temperature increases by at least 2 oC (when starting to dry) within a reporting interval (ie. max 77 seconds), so I would like to use this as my minimum gradient BUT what makes this more complicated is that even when the dryer temperature is plateauing, there is still ups and down temperature.

So, I’m thinking that I have to make some conditions where the information from the binary sensor is accepted for a warming process if the temperature is below 27oC and a second condition, accepted for a cooling process if the temperature is above 40oC.

Creating the conditions is easy, but I wanted to confirm that the below setup for the binary sensor makes sense that for:

temp_falling, means a temperature drop of at least 2oC over the 320 second duration
temp_rising is a temperature increase of at least 2oC over 120 seconds.

With the conditions mentioned above, I might be able to exclude the fluctuations of temperature during a drying cycles. OR maybe there is a better way for doing this?

binary_sensor:
  - platform: trend
    sensors:
      temp_falling:
        entity_id: sensor.dryer_vent
        sample_duration: 320
        max_samples: 4
        min_gradient: -0.0111
        device_class: cold

      temp_rising:
        entity_id: sensor.dryer_vent
        sample_duration: 180
        max_samples: 2
        min_gradient: 0.0111
        device_class: heat

Quick update here, was able to determine the trend values and have set up the automation here:

### Dryer Vent Temperature ###
- platform: trend
  sensors:
    temp_falling:
      friendly_name: "Dryer Temperature Decreasing"
      entity_id: sensor.temp1_2
      sample_duration: 180
      max_samples: 2
      min_gradient: -0.0259
      device_class: cold

    temp_rising:
      friendly_name: "Dryer Temperature Increasing"
      entity_id: sensor.temp1_2
      sample_duration: 180
      max_samples: 2
      min_gradient: 0.0259
      device_class: heat

and automation here

alias: Clothes Drying Status
description: For clothes drying notification system
trigger:
  - platform: state
    entity_id:
      - binary_sensor.temp_rising
    to: "on"
    id: drying_started
  - platform: numeric_state
    entity_id: sensor.temp1_2
    below: 45
    id: drying_stopped
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: drying_started
          - condition: numeric_state
            entity_id: sensor.temp1_2
            below: 45
        sequence:
          - service: input_datetime.set_datetime
            data:
              datetime: "{{ now() }}"
            target:
              entity_id: input_datetime.drying_started
          - service: input_datetime.set_datetime
            data:
              datetime: >-
                {{ (now().timestamp() +
                states('input_number.drying_expected_runtime') | float(0)) |
                timestamp_local() }}
            target:
              entity_id: input_datetime.drying_expected_time_to_stop
      - conditions:
          - condition: trigger
            id: drying_stopped
          - condition: state
            entity_id: binary_sensor.temp_falling
            state: "on"
        sequence:
          - service: input_datetime.set_datetime
            data:
              datetime: "{{ now() }}"
            target:
              entity_id: input_datetime.drying_stopped
          - service: input_number.set_value
            data:
              value: >-
                {{ (as_timestamp(states('input_datetime.drying_stopped')) -
                as_timestamp(states('input_datetime.drying_started'))) |
                float(0) }}
            target:
              entity_id: input_number.drying_expected_runtime
          - service: notify.mobile_app_sony_xperia_zx1
            data:
              message: Clothes drying machine is done!
              title: Clothes Drying Machine Status
          - service: notify.mobile_app_iphone
            data:
              message: Clothes drying machine is done!
              title: Clothes Drying Machine Status
          - service: tts.cloud_say
            data:
              entity_id: media_player.fire_tablet
              message: Clothes drying machine is done!
mode: single

Not sure why this happens, but the automations starts off perfectly, but then when it’s done drying and the temperature starts to drop, it doesn’t actually take the second choose option.

According to the trance, as the temperature went below 45, the condition triggered (i.e. drying_stopped), but then it says no action taken

and step detail:

and temp profile

why is it completely by-passing the second choose action? The condition for falling temp was on or true…or maybe it wasn’t, but shouldn’t it say the condition failed if that is the case?

EDIT: it must be the gradient when cooling. Now I lowered it to 1oC/min vs 1.3oC/min. I’ll see if that works.