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.


fredag 30. november 2018

My first script in home assistant

The first post here. And my first script in Home Assistant. I have installed Mopidy and Snapcast on my server and have a couple of orange pi's to run snapcastclient to get multiroom audio.

On the bathroom I have this orange pi with a 433mhz plug switch connected to the Aux in on my Pinell Supersound II Radio. I want to have a switch on the Home Assistant UI to turn the orange pi and pinell on and select the right source on the radio.

Some googling and trial and error.. I found that this is working:

I have this in the scripts.yaml file:

musikk_bad_on:

    alias: musikk bad on
    sequence:
      - service: media_player.turn_on
        entity_id:
          - media_player.pinell_supersound_002261086da2
      - service: switch.turn_on
        entity_id:
          - switch.musikk_bad_switch
      - service: media_player.select_source
        data:
           entity_id: media_player.pinell_supersound_002261086da2
           source: 'AUX inngang'

musikk_bad_off:
         
    alias: musikk bad off
    sequence:
      - service: media_player.turn_off
        entity_id:
         - media_player.pinell_supersound_002261086da2
      - service: switch.turn_off
        entity_id:
          - switch.musikk_bad_switch

And I did put this under switch in my configuration.yaml file.

  - platform: template
    switches:
      musikkbad:
        friendly_name: "Musikk bad"
        value_template: "{{ is_state('switch.musikk_bad_switch', 'on') }}"
        turn_on:
          service: script.turn_on
          entity_id: script.musikk_bad_on
        turn_off:
          service: script.turn_on
          entity_id: script.musikk_bad_off