Problems with automation and conditions [SOLVED]

Hello,

I’ve been slowly migrating from SmartThings+CoRE over to Home Assistant. Most of the automations have been migrated, except for one that I haven’t been able to get right. Thanks to the previous owners, our dryer vents into the garage. I’ve got a SmartThings outlet hooked up to the dryer that basically says “if the power is greater than 10, open the garage”. This is working as expected. However, the automation to close the garage is where I’m getting stuck.

There’s a few conditions in place that I’d like it to check before closing the garage: verify there’s been no motion, the laundry room door has remained closed, and the garage door is in the “open” position, all for 15 minutes each. It looks like this:

alias: Close garage door on inactivity
trigger:
  - platform: numeric_state
    entity_id: sensor.dryer_power
    below: 10
condition:
  - condition: and
    conditions:
      - condition: state
        entity_id: binary_sensor.fyc_motion
        state: 'off'
        for:
          minutes: 15
      - condition: state
        entity_id: sensor.laundry_room_door_contact
        state: 'closed'
        for:
          minutes: 15
      - condition: state
        entity_id: sensor.garage_door_contact
        state: 'open'
        for:
          minutes: 15
action:
  service: cover.close_cover
  entity_id: cover.garage_door

It works as expected if I remove the conditions, i.e. the garage door closes as soon as the dryer is turned off. Any ideas on what the issue might be? Everything appears to be correct with the formatting, so I’m guessing it’s an issue with the logic around the conditions.

Thanks much!

Could you us any errors you are getting from the logs?

I think I might have figured out the issue, although I haven’t figured out the workaround.

It look like the dryer outlet just sends the power usage when it changes, e.g. 600W -> 200W -> 300W. It’s basically a constant stream of data. The automation seems to works when (1) all of the conditions are already true and (2) the dryer outlet drops below 10W, i.e. it might get a 3W reading so the trigger and conditions are all true.

However, once the dryer power hits 0W, it stops sending any additional power data. In that case, (1) if the conditions are not true and (2) the dryer hits 0W, it’ll never trigger since the dryer doesn’t have a value while the conditions are true. If it magically sent another 0W it’d trigger the automation.

As a solution, would it make send to make a value template switch? For example, if it’s over 10W it’s ‘on’ otherwise it’s ‘off’ regardless of the 0W data?

Figured it out! It seems obvious in retrospect, but it was only triggering when the status of the dryer actually changed. I was thinking it just checked the state. I used a template to turn the power measurement of the sensor into a binary sensor so “for” could be used in the condition. I then just set the trigger to basically fire every 15 minutes with a bunch of conditions.

The binary sensor:

- platform: template
  sensors:
    dryer_power_template:
      friendly_name: 'Dryer Power Status'
      device_class: 'power'
      entity_id: sensor.dryer_power
      value_template: "{{ states('sensor.dryer_power') | int > 50 }}"

The automation:

alias: Close garage door on inactivity
trigger:
  platform: time
  minutes: '/15'
condition:
  - condition: and
conditions:
  - condition: state
    entity_id: binary_sensor.dryer_power_template
    state: 'off'
    for:
      minutes: 15
  - condition: state
    entity_id: binary_sensor.fyc_motion
    state: 'off'
    for:
      minutes: 15
  - condition: state
    entity_id: sensor.laundry_room_door_contact
    state: 'closed'
    for:
      minutes: 15
  - condition: state
    entity_id: sensor.garage_door_contact
    state: 'open'
    for:
      minutes: 15
action:
  service: cover.close_cover
  entity_id: cover.garage_door