#Bathroom fan

1 messages · Page 1 of 1 (latest)

harsh fulcrum
#

I have an automation like this ```alias: Bathroom Fan Auto Off
description: ""
triggers:

  • trigger: state
    entity_id:
    • switch.shelly1pmminig3_34b7dac8b960_switch_0
      from: "off"
      to: "on"
      conditions: []
      actions:
  • delay:
    hours: 0
    minutes: 30
    seconds: 0
    milliseconds: 0
  • if:
    • condition: numeric_state
      entity_id: sensor.sonoff_snzb_02d_humidity
      below: 55
      then:
    • type: turn_off
      device_id: 774040e8b793231cdc6816019edc0028
      entity_id: a54486eaa173b343b278536138f70a89
      domain: switch
      mode: single
The intent is when the fan comes on, it should wait 30 minutes, then test if humidity level has dropped below 55, if so, turn  fan off.

Question is, does this condition keep testing if it fails the first time? Or do I need some kind of loop?
lavish vessel
#

No. It will only wait 30 minutes once and then it is hit or miss.

harsh fulcrum
#

ahh, how would I go about it if I want it to keep testing?

modern patrol
#

While loop is one way with short delays

#

Or even better, make another trigger that triggerd when humidity goes below target?

lavish vessel
#

Either that or a time pattern trigger and conditions.

#

Or a wait for.

harsh fulcrum
#

let me see if my brain can process this

lavish vessel
#

Wait for or while loops wouldn't survive a HA restart though.

harsh fulcrum
#

why would HA restart?

lavish vessel
#

If you do an update which requires a restart for example, while that automation is running.

harsh fulcrum
#
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.shelly1pmminig3_34b7dac8b960_switch_0
    from: "off"
    to: "on"
conditions: []
actions:
  - delay:
      hours: 0
      minutes: 30
      seconds: 0
      milliseconds: 0
  - wait_for_trigger:
      - trigger: numeric_state
        entity_id:
          - sensor.sonoff_snzb_02d_humidity
        below: 55
  - type: turn_off
    device_id: 774040e8b793231cdc6816019edc0028
    entity_id: a54486eaa173b343b278536138f70a89
    domain: switch
mode: single
lavish vessel
#

In theory that might work. But there are some caveats.

#

a) If you need to restart HA, the automation will not resume.
b) If the humidity already is below 55 after the 30 minutes waiting time, it will not continue. It needs to cross the threshold.

harsh fulcrum
#

that second one is problematic

#

why would it do that though, instead of just checking the fixed value

lavish vessel
#
description: ""
mode: single
triggers:
  - trigger: state
    entity_id:
      - switch.shelly1pmminig3_34b7dac8b960_switch_0
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_snzb_02d_humidity
    below: 55
conditions:
  - condition: state
    entity_id: switch.shelly1pmminig3_34b7dac8b960_switch_0
    state: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - condition: numeric_state
    entity_id: sensor.sonoff_snzb_02d_humidity
    below: 55
actions:
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.shelly1pmminig3_34b7dac8b960_switch_0
#

I think this does what you want.

harsh fulcrum
#

so I'm putting the <55 trigger up to the "when"?

lavish vessel
#

30 minutes after turning on, it turns off - if the humidity is below 55.
Or it turns off when humidity is below 55 - if the switch was on for at least 30 minutes.

#

Both as triggers and conditions (when and if).

harsh fulcrum
#
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.shelly1pmminig3_34b7dac8b960_switch_0
    from: "off"
    to: "on"
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_snzb_02d_humidity
    below: 55
conditions:
  - condition: device
    type: is_on
    device_id: 774040e8b793231cdc6816019edc0028
    entity_id: a54486eaa173b343b278536138f70a89
    domain: switch
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - condition: numeric_state
    entity_id: sensor.sonoff_snzb_02d_humidity
    below: 55
actions:
  - type: turn_off
    device_id: 774040e8b793231cdc6816019edc0028
    entity_id: a54486eaa173b343b278536138f70a89
    domain: switch
mode: single
lavish vessel
#

The switch trigger needs the for 30 minutes as well.

harsh fulcrum
#
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.shelly1pmminig3_34b7dac8b960_switch_0
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_snzb_02d_humidity
    below: 55
conditions:
  - condition: device
    type: is_on
    device_id: 774040e8b793231cdc6816019edc0028
    entity_id: a54486eaa173b343b278536138f70a89
    domain: switch
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - condition: numeric_state
    entity_id: sensor.sonoff_snzb_02d_humidity
    below: 55
actions:
  - type: turn_off
    device_id: 774040e8b793231cdc6816019edc0028
    entity_id: a54486eaa173b343b278536138f70a89
    domain: switch
mode: single
lavish vessel
#

And I would generally recommend not to use device actions, but to use the state triggers and action calls instead.

harsh fulcrum
#

how do i do that?

lavish vessel
#

If you need to replace a device in the future, you would have to fix all devices in the automations. the action calls and state triggers just need the entities to be named the same way.

lavish vessel
#

Mine doesn't use devices.

harsh fulcrum
#
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.shelly1pmminig3_34b7dac8b960_switch_0
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_snzb_02d_humidity
    below: 55
conditions:
  - condition: device
    type: is_on
    device_id: 774040e8b793231cdc6816019edc0028
    entity_id: a54486eaa173b343b278536138f70a89
    domain: switch
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - condition: numeric_state
    entity_id: sensor.sonoff_snzb_02d_humidity
    below: 55
actions:
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      device_id: 774040e8b793231cdc6816019edc0028
mode: single
#

it's still device

#

hold on

#
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.shelly1pmminig3_34b7dac8b960_switch_0
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_snzb_02d_humidity
    below: 55
conditions:
  - condition: device
    type: is_on
    device_id: 774040e8b793231cdc6816019edc0028
    entity_id: a54486eaa173b343b278536138f70a89
    domain: switch
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - condition: numeric_state
    entity_id: sensor.sonoff_snzb_02d_humidity
    below: 55
actions:
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.shelly1pmminig3_34b7dac8b960_switch_0
mode: single
#

there we go

lavish vessel
#

There is still a device condition.

harsh fulcrum
#
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.shelly1pmminig3_34b7dac8b960_switch_0
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_snzb_02d_humidity
    below: 55
conditions:
  - condition: state
    entity_id: switch.shelly1pmminig3_34b7dac8b960_switch_0
    state: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - condition: numeric_state
    entity_id: sensor.sonoff_snzb_02d_humidity
    below: 55
actions:
  - action: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.shelly1pmminig3_34b7dac8b960_switch_0
mode: single
#

so don't use devices, use entities

lavish vessel
#

Yeah. It is less likely to bite you in the future.

#

And you often have more options, if you use the actions. Especially for lights.

#

It is no strict rule, just an advice from experience. shksD

harsh fulcrum
#

thanks!

#

so while i have you here

#

if i want to extend this automation a bit, let's say to have it turn on automatically without input, if humidity somehow goes above 60

#

i should put that on a separate automation shouldn't i

lavish vessel
#

You could go that way with a choose action and moving contitions to them. But it would complicate the automation.
Using a seperate automation keeps it easier in the beginning.

#

Finding problems is easier with multiple simpler automations.

harsh fulcrum
#
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.bathroom_fan_shelly_switch_0
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_snzb_02d_humidity
    below: 55
    id: humidity55
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_snzb_02d_humidity
    above: 60
    id: humidity60
conditions:
  - condition: state
    entity_id: switch.bathroom_fan_shelly_switch_0
    state: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: sensor.sonoff_snzb_02d_humidity
        below: 55
      - condition: numeric_state
        entity_id: sensor.sonoff_snzb_02d_humidity
        above: 60
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - humidity60
          - condition: state
            entity_id: switch.bathroom_fan_shelly_switch_0
            state: "off"
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: switch.bathroom_fan_shelly_switch_0
      - conditions:
          - condition: trigger
            id:
              - humidity55
          - condition: state
            entity_id: switch.bathroom_fan_shelly_switch_0
            state: "on"
        sequence:
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.bathroom_fan_shelly_switch_0
mode: single
#

would something like that work?

lavish vessel
#

No.

harsh fulcrum
#

i need to get rid of the conditions on top huh

lavish vessel
#

And it wouldn't turn off after 30 minutes.

#
alias: Bathroom Fan Auto Off
description: ""
triggers:
  - trigger: state
    entity_id:
      - switch.bathroom_fan_shelly_switch_0
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 30
      seconds: 0
    id: 30minutes
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_snzb_02d_humidity
    below: 55
    id: humidity55
  - trigger: numeric_state
    entity_id:
      - sensor.sonoff_snzb_02d_humidity
    above: 60
    id: humidity60
conditions: []
actions:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - humidity60
          - condition: state
            entity_id: switch.bathroom_fan_shelly_switch_0
            state: "off"
        sequence:
          - action: switch.turn_on
            metadata: {}
            data: {}
            target:
              entity_id: switch.bathroom_fan_shelly_switch_0
      - conditions:
          - condition: trigger
            id:
              - humidity55
          - condition: state
            entity_id: switch.bathroom_fan_shelly_switch_0
            state: "on"
            for:
              hours: 0
              minutes: 30
              seconds: 0
        sequence:
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.bathroom_fan_shelly_switch_0
      - conditions:
          - condition: trigger
            id:
              - 30minutes
          - condition: numeric_state
            entity_id: sensor.sonoff_snzb_02d_humidity
            below: 55
        sequence:
          - action: switch.turn_off
            metadata: {}
            data: {}
            target:
              entity_id: switch.bathroom_fan_shelly_switch_0

-# on the first glympse

#

You see: the more complex it becomes, the harder to read and understand it is.

harsh fulcrum
lavish vessel
#

That would turn off immediately when it is below 55 and not wait for the 30 minutes to complete.

harsh fulcrum
#

not ideal but i'd be ok with that l ol

lavish vessel
#

The example I posted should work.

harsh fulcrum
#

i see what you did, after pasting it and looking at visual editor lol