Yet another Bathroom fan setup

Posting this if someone is doing a similar setup. I can post more if anyone is interested
After I was done I found this by @Blacky. Maby a better way to go.

Here is my take:

Hardware:

Fan with 0-10V control
0-10V controller(ex: Plejd crl-01)
2x temp/humidity sensors. (Aqara zigbee)
Shelly (Shelly Plus 2PM, for physical button)

Software in HA

Node-red Add-on
Node-RED companion Integration.
Thermal comfort (for Abs-humidity) Integration.
ZHA (for the sensors) Integration
HomeKit device (for Plejd) Integration
Shelly Integration

My setup for the bathroom exhaust fan.

It has worked great for a couple years now.
Probably not the smartest way to do this, but it is always nice to figure out stuff yourself.

I think this setup needs to have a strong fan for it to be useful.

I have two Aqara Zigbee sensors for humidity/temp, one outside and one inside of the bathroom(the inside one is close to the fan duct)
with Thermal comfort i make the readings in to Absolute humidity(this feels more useful than percentage over the year)
With a template sensor I calculate the difference between the two Aqara sensors in percentage.
Then I do the rest in Node-RED.

Helper-Template sensor for the Difference:

Unit of measurement: %
Device class: Humidity
State class: Measurement

{{ (states(‘sensor.thermal_comfort_absolute_humidity’)|float / states(‘sensor.thermal_comfort_absolute_humidity_2’)|float * 100 - 100 ) | round(2) }}

In Node-RED:

Since the plejd integration is not great HA thinks my fan is a Light. The command for the fan speed is therefor is “Light.turn_on” with data: {“brightness_pct”: xxx}

With some calibration I could find good values for the switch(sorting) node that works in my bathroom.
Below 10% the fan can be turned off. And over 50% difference it can be 100% speed. Then some stages in between.

These are the steps I took (after reading quite a few posts in the HA Forum):-

**Create a Derivative Helper** with Precision = 2, Time window = 1 min, Time unit = Minutes and Max sub-interval = 5 mins

**Create 3 Triggers:-**
When Fan_Bathroom changes to On for 10:00
When Bathroom Humidity is above 80 for 5 seconds
When Bathroom Humidity Derivative is above 1

**Create 3 Options:-**
If triggered by Bathroom Humidity High
If triggered by Bathroom Humidity Derivative above limit
If triggered by Bathroom Fan On for 10 minutes

Notes:
The option to turn the fan off when triggered avoids the problem if a “delay” is used instead.