Update bathroom-fan.yaml

Update: 
 - Faster response to changes from HASS
 - Faster response to PIR detection
 - Few temperature updates sent to HASS
 - Better clamping and control of fan-speed
This commit is contained in:
nc
2025-10-28 19:35:56 +01:00
parent bc61ef6c01
commit 593b6dee25

View File

@@ -113,7 +113,7 @@ i2c:
binary_sensor:
- platform: gpio
name: "Motion" # IR Presense detection, halves fan speed
id: pirSensor
id: pirSensor
pin:
number: ${pinPIR}
mode:
@@ -151,6 +151,8 @@ sensor:
temperature:
name: "Temperature" # We only use Temp for information. SHT3x uses it for Relative Humidity
id: temp
filters:
- delta: 0.6 # Don't react to every small change
humidity:
name: "Humidity"
id: humid
@@ -159,7 +161,7 @@ sensor:
min_value: 0.1
max_value: 99.9
ignore_out_of_range: true
- delta: 2.0 # Don't react to every small change
- delta: 1.0 # Don't react to every small change
on_value:
then:
- script.execute: update_fan
@@ -185,9 +187,9 @@ script:
// = ((100-25) / (80 - $C$5)) * B8 + (100 - (((100-25) / (80 - $C$5))*80))
float speed = (75/(80-cutoff)) * humidity + (100-((75/ (80-cutoff))*80));
// Clamp between 25 and 100
// Clamp between 20% and 100% duty-cycle
if( humidity <= cutoff )
speed = 25;
speed = 20;
if( humidity >= 80)
speed = 100;
@@ -196,7 +198,8 @@ script:
speed = speed / 2;
// Turn the fan on and set the speed, or turn off
if( humidity >= cutoff )
// Test for both cutoff, and minimum speed.
if( humidity >= cutoff && speed >= 10)
{
auto call = id(Extractor).turn_on();
call.set_speed(speed);
@@ -223,6 +226,9 @@ switch:
# - switch.turn_on: switch2
# turn_off_action:
# - switch.turn_on: switch1
on_state:
then:
- script.execute: update_fan # Update fan to reflect quiet-mode state
number:
- platform: template # Control in Home Assistant to set point where fan should turn off
@@ -237,3 +243,6 @@ number:
step: 1
initial_value: 35 # 35% rel humidity is slightly high as low cutoff
restore_value: True
on_value:
then:
- script.execute: update_fan # Update fan to reflect new cut-off and range