# Best way to switch device based on multiple (depending) rules

**URL:** <https://community.homey.app/t/best-way-to-switch-device-based-on-multiple-depending-rules/62745>\
**Category:** Questions & Help\
**Created:** [April 16, 2022, 1:55pm UTC](https://community.homey.app/t/best-way-to-switch-device-based-on-multiple-depending-rules/62745 "2022-04-16T13:55:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![FKey](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/fkey/32/14793_2.png) [@FKey](https://community.homey.app/u/FKey)\
**Post date:** [April 16, 2022, 1:55pm UTC](https://community.homey.app/t/best-way-to-switch-device-based-on-multiple-depending-rules/62745/1 "2022-04-16T13:55:50Z")

</div>

I am strugling with my flows to to switch on a device (in my case a fan but could be any device).

The problem is I have multiple rules that are sometimes even dependend.

**Problem** :  
Determine the correct trigger to switch _ **On** _ the fan  
Determine the correct trigger to switch _ **Off** _ the fan

**Rules**  
The ON rules:

- when the CO2 level \> “extremely high” the fan should always go on
- when the CO2 level \> “high” the fan should go on
- the fan should not go on when the outside temperature is \> 20. (Except when CO2 \> extremely high)
- the fan should go on when outside temp \< inside temp AND expected temp the next day os \>19degrees (cooling down in summer)
- the fan should not go on when inside temp \< 14 (prevent going below dew point)

THE off Rules

- when the CO2 level \> “extremely high” the fan should not turn off
- when CO2 \< “normal” the fan should go off
- when the inside temp \< outside temp AND the expected temp is below 19 the fan should go off

Probably more rules to Add.

Making a lot of seperate flow could become very complex.  
I was thinking about the [bayesian probability](https://community.homey.app/t/aggregating-sensor-stats-into-a-single-virtual-device/6642/4)

Any other suggestions???

---

<div class="post-metadata">

**Author:** ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)\
**Post date:** [April 16, 2022, 3:56pm UTC](https://community.homey.app/t/best-way-to-switch-device-based-on-multiple-depending-rules/62745/2 "2022-04-16T15:56:20Z")

</div>

Nice puzzling again! Not easy to keep it simple.  
I think this comes close, FKey…

```auto
- Flow F1-5 (CO2 level > “extremely high”)
If..
CO2 level changed
And..
  [CO2 level] > "extremely high"
Then..
Turn fan on
  Else..
  Start flow F5-5 (Fan Off if CO2 level < "normal")

***
- Flow F2-5 (CO2 level > “high”)
If..
CO2 level changed
And..
  [CO2 level] > "high"
And..
  [outside temp] =< 20
And..
  [inside temp] > 14
Then..
Turn fan on
  Else..
  Start flow F5-5 (Fan Off if CO2 level < "normal")

- Flow F3-5 (CO2 level < “normal”)
If..
CO2 level changed
And..
  [CO2 level] < "normal"
Then..
Start flow F5-5 (Fan Off if CO2 level < "normal")

***
- Flow F4-5 (Outside temp < Inside temp)
If..
[Outside temp] changed
And..
  [Outside temp] < [Inside temp]
And..
  [Expected temp the next day] > 19
And..
  [Inside temp] > 14  
Then..
Turn fan on
  Else..
  Start flow F5-5 (Fan Off if CO2 level < "normal")

***
- Flow F5-5 (Fan Off if CO2 level < "normal")
If..
This flow is started
  And..
  [CO2 level] < "normal"
Then..
Turn fan off

```
