House ventilation system acting on humidity and hot water usage

My house has a ventilation unit which I can control with a homebrew ESP/C1101 868 MHz module. I wanted to have it automatically switch on when I take a shower.

Sensors:

I am sensing high humidity with a Wemos D1 mini with DHT22 sensor and sensing hot water usage via my Nefit Easy thermostat. The bathroom is the only user of hot water in my house (close-in boiler in kitchen)

Humidity:

Humidity is varying, so how do you baseline the measurement? Humidity data is stored in an InfluxDB database via MQTT. So I’ve made a sensor in HASS that retrieves the lowest absolute humidity value in the past two hours:

  - platform: influxdb
    host: localhost
    username: xxx
    password: xxx
    queries:
      - name: "minhum"
        unit_of_measurement: 'mg/m3'
        value_template: '{{ value | round(1) }}'
        group_function: min
        where: '"property" = ''abshumidity'' AND "sublocation" = ''bathroom'' and time > now() - 2h'
        measurement: 'sensors'
        database: sensors

If I compare this value with the current value, I can easily sense an increase in humidity. Why absolute humidity? Because at higher temperature (happens when shower is on), the increase in relative humidity is less pronounced.
[/details]

  - platform: template
    sensors:
      humdelta:
        value_template: '{{ (float(states.sensor.badkamer_abshumidity.state) - float(states.sensor.minhum.state)) | round(1) }}'
        unit_of_measurement: 'mg/m3'

Now, define the thresholds, via an automation:

- id: hum_high
  alias: high humidity
  trigger:
    platform: numeric_state
    entity_id: sensor.humdelta
    above: 4
  action:
  - service: input_select.select_option
    data:
      entity_id: input_select.humidity
      option: high

This sets an input selector to high. Similar for medium and low

Hot Water:

The smart thermostate script spits out a mqtt status topic few times per minute.

  - platform: mqtt
    name: "wk_boilerstatus"
    state_topic: "/woonkamer/woonkamer/thermostaat/boilerstatus"

Combining the two

If the humidity is high, or if Hot Water is on for more than a minute, or when a selector in the interface is changed to high, the fan is set to high via an mqtt topic, and the input selector is set to high.

- id: fan_01
  alias: Fan Speed high
  trigger:
  - platform: state
    entity_id: input_select.humidity
    to: high
  - platform: state
    entity_id: sensor.wk_boilerstatus
    to: HW
    for:
      minutes: 1
  - platform: state
    entity_id: input_select.fanstate
    to: high
  action:
  - service: mqtt.publish
    data:
      topic: /hass/itho
      payload: high
  - service: input_select.select_option
    data:
      entity_id: input_select.fanstate
      option: high

Similar for low humidity. Difference is that I want to turn down the fan with a delay of 15 minutes. The condition makes sure I am not issuing a low topic all day long. I should build a similar condition for high :slight_smile:

- id: fan_05
  alias: Fan Speed low
  trigger:
  - platform: state
    entity_id: input_select.humidity
    to: low
    for:
      minutes: 15
  - platform: state
    entity_id: sensor.wk_boilerstatus
    to: 'No'
    for:
      minutes: 15
  - platform: state
    entity_id: input_select.fanstate
    to: low
  condition:
    condition: state
    entity_id: input_boolean.itho_not_low
    state: 'on'
  action:
  - service: mqtt.publish
    data:
      topic: /hass/itho
      payload: low
  - service: input_select.select_option
    data:
      entity_id: input_select.fanstate
      option: low

Lessons learned:

Numeric state doesn’t work with for
  - platform: numeric_state
    entity_id: sensor.humidity.state
    above: 4
    for:
      minutes: 15

gives an error

Value_template sensor with calculation

At first I made a value_template sensor with if statements to select the required fan state. Although it did work in the template editor http://192.168.0.9:8123/dev-template, it did not work in reality.

  - platform: template
    sensors:
      bkfanhumidity:
        friendly_name: Fan status for BK humidity
        entity_id:
          - sensor.bkfanhumidity
        icon_template: mdi:water-percent
        value_template: >-
          {%- if float(states.sensor.humdelta.state) > 4 -%}
          high
          {%- elif float(states.sensor.humdelta.state) < 4 and float(states.sensor.humdelta.state) > 1 -%}
          medium
          {%- else -%}
          low
          {%- endif -%}

did not work (properly). It was high or undefined (or low, I forgot)

Cleaning up

I need to clean up my code, I realized while writing this post

What is next?

Tie CO2 measurement to the automation

4 Likes