Update bathroom-fan.yaml

Changed to use a Script for updating Fan Speed/State
This commit is contained in:
nc
2025-10-24 14:55:15 +02:00
parent f16bf4b12b
commit bc61ef6c01

View File

@@ -69,7 +69,6 @@ light:
disabled_by_default: True # No need to reflect in Home Assistant disabled_by_default: True # No need to reflect in Home Assistant
##################################################### #####################################################
## Setup of Fan ## ## Setup of Fan ##
## ## ## ##
@@ -84,7 +83,7 @@ output: # PMW control of fan using the LEDC platform
pin: ${pinWS28xx} pin: ${pinWS28xx}
id: fanPin id: fanPin
power_supply: fanPower # Which pin to use to turn off Fan completely power_supply: fanPower # Which pin to use to turn off Fan completely
frequency: 19531Hz # Higher frequency, but only 12-bit resolution (4096 gradiant steps) frequency: 19531Hz # Higher frequency, but "only" 12-bit resolution (4096 gradiant steps)
fan: # Very basic fan with no oscilation etc control fan: # Very basic fan with no oscilation etc control
- platform: speed - platform: speed
@@ -114,7 +113,7 @@ i2c:
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
name: "Motion" # IR Presense detection, halves fan speed name: "Motion" # IR Presense detection, halves fan speed
id: pirSensor # ToDo: Call script to trigger immediately id: pirSensor
pin: pin:
number: ${pinPIR} number: ${pinPIR}
mode: mode:
@@ -123,6 +122,9 @@ binary_sensor:
device_class: motion device_class: motion
filters: filters:
- delayed_off: 180s - delayed_off: 180s
on_state: # Update fan if Presence changes
then:
- script.execute: update_fan
sensor: sensor:
- platform: pulse_meter # Warning: Not been tested, TACHO impulses fried ESP32 somehow - platform: pulse_meter # Warning: Not been tested, TACHO impulses fried ESP32 somehow
@@ -160,27 +162,33 @@ sensor:
- delta: 2.0 # Don't react to every small change - delta: 2.0 # Don't react to every small change
on_value: on_value:
then: then:
if: - script.execute: update_fan
condition:
sensor.in_range: # We're always in range due to the Clamp above
id: humid #####################################################
above: 0 ## Setup of Scripts ##
below: 100 ## "update_fan" - set fan speeds ##
#####################################################
script:
- id: update_fan
mode: single
then: then:
- lambda: |- # ToDo: Convert to script and call it - lambda: |- # Lets call this every time we need to update
float cutoff = id(lowHumCutoff).state; float cutoff = id(lowHumCutoff).state;
int humidity = id(humid).state;
// Doing linear transform here because we need the id(lowHumCutoff) variable // Doing linear transform here because we need the id(lowHumCutoff) variable
// Max is 100 at 80% // Max is 100 at 80%
// Min is 25 at cutoff% // Min is 25 at cutoff%
// linear equation y = mx + c // linear equation y = mx + c
// = ((100-25) / (80 - $C$5)) * B8 + (100 - (((100-25) / (80 - $C$5))*80)) // = ((100-25) / (80 - $C$5)) * B8 + (100 - (((100-25) / (80 - $C$5))*80))
float speed = (75/(80-cutoff)) * x + (100-((75/ (80-cutoff))*80)); float speed = (75/(80-cutoff)) * humidity + (100-((75/ (80-cutoff))*80));
// Clamp between 25 and 100 // Clamp between 25 and 100
if( x <= cutoff ) if( humidity <= cutoff )
speed = 25; speed = 25;
if( x >= 80) if( humidity >= 80)
speed = 100; speed = 100;
// Test if we need to go slow // Test if we need to go slow
@@ -188,7 +196,7 @@ sensor:
speed = speed / 2; speed = speed / 2;
// Turn the fan on and set the speed, or turn off // Turn the fan on and set the speed, or turn off
if( x >= cutoff ) if( humidity >= cutoff )
{ {
auto call = id(Extractor).turn_on(); auto call = id(Extractor).turn_on();
call.set_speed(speed); call.set_speed(speed);