# Control Home Ventilation Box

I’ve installed a new home ventilation box which has 3 speeds (lo, normal, high) which I control using a 2-gang Zigbee (DIY) switch. It controls the air in the living-room and toilet. I also have a Zigbee button in the toilet. In the living room I have a Zigbee air quality sensor (VOC / PM2.5). With all of this I like to create logic to control the ventilation speeds:

• By default set it to lo;
• When VOC/PM2.5 is above a certain threshold (1) set it to normal (and when below again set it to lo);
• When VOC/PM2.5 is above a certain threshold (2) set it to high (and when below again set it to normal);
• When the toilet button is pressed set it to high for 15 minutes, after that set it to lo again (except when one of the above conditions still applies);

I tried doing this with several automations but that’s rather cumbersome and I don’t seem to be able to accomplish the above. What would be the best approach? Ideally I like to use a single script (Python or Yaml: I can do both) that contains all the logic.

Any ideas/pointers?

A little cumbersome, but I think a general approach would be:

Triggers:

1. ID “low” - numeric - below threshold 1
2. ID “normal” - numeric - above threshold 1; below threshold 2
3. ID “high” - numeric - above threshold 2
4. ID “button” - state - button tapped

Actions:

Choose
Trigger ID = button → set to high, wait 15 minutes, choose → create an option to match each of the thresholds and set the speed accordingly
Trigger ID = low → set to low
Trigger ID = normal → set to normal
Trigger ID = high → set to high

Mode: single

I’m afraid it’s not that straightforward. The problem isn’t so much turning on normal/high, but turning them off again with the right conditions. You want them only to turn off when the toilet-timer isn’t active AND VOC-value is low enough AND PM2.5 is low enough. I think using an automation you can only accomplish that by doing something like this (values are arbitrary):

triggers:

• voc < 100
• pm2.5 < 10
• toilet-timer = idle
condition:
• voc < 100
• pm 2.5 < 10
• toilet-timer = idle
action:
• fan high = off

Which isn’t really pretty because of the double logic in trigger/condition. Is there a nicer way?

Are the fan speeds individual entities or just one?

Individual (=2 entities). I’m using 2 zigbee switches to enable speed 2 (normal) and speed 3 (high).

EDIT: And also note that I also like to add logic to enable speed 3 (high) when inside temperature > 24 degrees and outside temperature < inside temperature, so I have to keep that in mind as well…

What happens if you have both ‘normal’ and ‘high’ turned on?

The ‘high’-selection will have precedence (it will overrule the ‘normal’ selection). This is what I came up with for now. It’s not complete yet, especially the whole inside/outside temperature logic is missing:

``````alias: Huis Ventilatie VOC/PM2.5 Stand 2 Aan
description: ""
trigger:
- platform: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_voc_index
above: 300
for:
hours: 0
minutes: 2
seconds: 0
- platform: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_pm25
above: 35
for:
hours: 0
minutes: 2
seconds: 0
condition: []
action:
- type: turn_on
device_id: 5000c7870159df5669ee717887e6d179
entity_id: 844061a87c52072d809dbe5f89ce2401
domain: switch
mode: single
alias: Huis Ventilatie VOC/PM2.5 Stand 2 Uit
description: ""
trigger:
- platform: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_voc_index
below: 200
for:
hours: 0
minutes: 10
seconds: 0
- platform: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_pm25
for:
hours: 0
minutes: 10
seconds: 0
below: 15
condition:
- condition: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_voc_index
below: 200
- condition: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_pm25
below: 15
action:
- type: turn_off
device_id: 5000c7870159df5669ee717887e6d179
entity_id: 844061a87c52072d809dbe5f89ce2401
domain: switch
mode: single
alias: Huis Ventilatie VOC/PM2.5 Stand 3 Aan
description: ""
trigger:
- platform: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_voc_index
above: 400
for:
hours: 0
minutes: 2
seconds: 0
- platform: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_pm25
above: 55
for:
hours: 0
minutes: 2
seconds: 0
- platform: state
entity_id:
- timer.wc_ventilatie_timer
to: active
condition: []
action:
- type: turn_on
device_id: 5000c7870159df5669ee717887e6d179
entity_id: 7551c648b082995e9e19cc98172c376c
domain: switch
mode: single
alias: Huis Ventilatie VOC/PM2.5 Stand 3 Uit
description: ""
trigger:
- platform: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_voc_index
for:
hours: 0
minutes: 10
seconds: 0
below: 300
- platform: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_pm25
for:
hours: 0
minutes: 10
seconds: 0
below: 35
- platform: state
entity_id:
- timer.wc_ventilatie_timer
to: idle
condition:
- condition: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_voc_index
below: 300
- condition: numeric_state
entity_id: sensor.woonkamer_luchtkwaliteitssensor_pm25
below: 35
- condition: state
entity_id: timer.wc_ventilatie_timer
state: idle
action:
- type: turn_off
device_id: 5000c7870159df5669ee717887e6d179
entity_id: 7551c648b082995e9e19cc98172c376c
domain: switch
mode: single
alias: WC Ventilatie Start Timer
description: ""
trigger:
- platform: device
domain: mqtt
device_id: 2105e8c1b78f4c5a9e226c5ffa182482
type: action
subtype: toggle
discovery_id: 0xec1bbdfffe2bb7f0 action_toggle
condition: []
action:
- service: timer.start
data: {}
target:
entity_id: timer.wc_ventilatie_timer
mode: single
``````