Automation with device trigger and time condition doesn't start

I have a water recirculation pump controlled via Shelly1 with an addon (DS18B20).
I finally added this device to Ha and I want to replace the scheduler from the device with proper automation.

The idea is to turn the pump for max 5 minutes if the sensor temperature drops below 23 celsius.
I’ve also added two conditions, first is time, I want the automation to run between 6 and 21.

My automation:

alias: Cyrkulacja - automat
description: Automatyczne sterowanie cyrkulacją
trigger:
  - type: temperature
    platform: device
    device_id: a90d71363fc3b2832806ff7948b51819
    entity_id: sensor.cyrkulacja_temperature
    domain: sensor
    below: 23
condition:
  - condition: time
    after: "06:00:00"
    before: "21:00:00"
  - condition: device
    type: is_off
    device_id: a90d71363fc3b2832806ff7948b51819
    entity_id: switch.cyrkulacja
    domain: switch
action:
  - type: turn_on
    device_id: a90d71363fc3b2832806ff7948b51819
    entity_id: switch.cyrkulacja
    domain: switch
  - wait_for_trigger:
      - type: temperature
        platform: device
        device_id: a90d71363fc3b2832806ff7948b51819
        entity_id: sensor.cyrkulacja_temperature
        domain: sensor
        above: 30
    timeout:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: a90d71363fc3b2832806ff7948b51819
    entity_id: switch.cyrkulacja
    domain: switch
mode: single

but sadly the automation doesn’t start as I would like it to start:

At the night the sensor temperature is way below 23 so at 6 the automation should start.
Now to trigger the automation I must warm water above 23, wait till it gets cold and then the automation starts and works till evening.

I’ve checked the traces and I have two:


and

nothing in between.

I think the issue is that the initial trigger isn’t fired if the temperature is already below 23 celsius, so in the morning if the temperature is 20 I won’t get the event, but if I heat the water up above 23 and the temperature drops below 23 the event fires.

My first idea is to add a second trigger (time trigger at 6) and another condition (if the temperature is below 23), but maybe there is a better (simpler) way?

that is pretty much the only way to do it.

My version: removed all the device cruft, added a 6am and a restart trigger and a temperature condition, and moved the “off” action to a separate automation. Random unique IDs allow you to use the trace feature.

alias: Cyrkulacja - automat on
id: bf7d44e6-cba7-467b-b43f-7e2bacc9d057
description: Automatyczne sterowanie cyrkulacją on
trigger:
  - platform: numeric_state
    entity_id: sensor.cyrkulacja_temperature
    below: 23
  - platform: time
    at: "06:00:00"
  - platform: homeassistant
    event: start
  - platform: event
    event_type: automation_reloaded
condition:
  - condition: time
    after: "05:59:59"
    before: "21:00:00"
  - condition: numeric_state
    entity_id: sensor.cyrkulacja_temperature
    below: 23
action:
  - service: switch.turn_on
    entity_id: switch.cyrkulacja

alias: Cyrkulacja - automat off
id: 240e6496-92c6-4800-9de9-640dbadd89df
description: Automatyczne sterowanie cyrkulacją off
trigger:
  - platform: state
    entity_id: switch.cyrkulacja
    to: 'on'
    for:
      minutes: 5
  - platform: numeric_state
    entity_id: sensor.cyrkulacja_temperature
    above: 30
action:
  - service: switch.turn_off
    entity_id: switch.cyrkulacja
2 Likes

Thank you for the suggestion, I’ll try it in the evening.
I used the device triggers because it was easier (HA suggests those when you visit the device).
I also noticed that we can’t use helpers when we use device triggers and conditions (for example, the water is colder than the value of my input).
I forgot about home assistant start event automation_reloaded events, thank you for that :slight_smile: