torsdag 13. desember 2018

Make bathroom fan start and stop automatically when showering.

I have a bathroom fan that I want to start automatically when the shower turns on and the humidity rises. Then to automatically turn off again when the humidity level has fallen again. After some googling, asking and testing then trial and error, I found out after several days that the following setup works.

First I create two new binary trend sensors based on the humidity sensor I got on the bathroom.

This is the sensors written in the configuration.yaml file:

binary_sensor:
 - platform: trend
   sensors:
      bad_fukt_rising:
        entity_id: sensor.bad_inne_fukt_humidity
        min_gradient: 0.008
        max_samples: 4
       
        
      bad_fukt_falling:
        entity_id: sensor.bad_inne_fukt_humidity
        min_gradient: -0.004
        max_samples: 10

The first one turns on when the humidity is rising, I found out that I had to set the "max_samples" values. before I entered anything in the rising sensor it sometimes turned on when it shouldn't

And before I entered the value in the falling sensor It stopped earlier than I wanted it too.


The sensors dont do anything on their own.. So i had to make some automations too.

This is what I have in the automations.yaml file:

  - alias: 'Badevifte auto on'
    trigger:
      - platform: state
        entity_id: binary_sensor.bad_fukt_rising
        from: 'off'
        to: 'on'
    action:
        service: switch.turn_on
        entity_id: switch.bad_oppe_vifte

  - alias: 'Badevifte auto off'
    trigger:
      platform: state
      entity_id: binary_sensor.bad_fukt_falling
      from: 'on'
      to: 'off'
    action:
        service: switch.turn_off
        entity_id: switch.bad_oppe_vifte

This is what happens, when the shower is turned on the humidity is rising. This turn the rising sensor on, which then triggers the auto on automation. Then when the humidity stop rising, and the rising sensor turns off, nothing happens, because that is not set to trigger anything.

When the humidity starts to fall the falling sensor turns on. This stays on until the humidity stops falling, then triggers the auto off automation when the sensor goes to state "off"

It might need some more tweaking and so. But so far this is working good.