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
#####################################################
## Setup of Fan ##
## ##
@@ -84,7 +83,7 @@ output: # PMW control of fan using the LEDC platform
pin: ${pinWS28xx}
id: fanPin
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
- platform: speed
@@ -114,7 +113,7 @@ i2c:
binary_sensor:
- platform: gpio
name: "Motion" # IR Presense detection, halves fan speed
id: pirSensor # ToDo: Call script to trigger immediately
id: pirSensor
pin:
number: ${pinPIR}
mode:
@@ -123,6 +122,9 @@ binary_sensor:
device_class: motion
filters:
- delayed_off: 180s
on_state: # Update fan if Presence changes
then:
- script.execute: update_fan
sensor:
- 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
on_value:
then:
if:
condition:
sensor.in_range: # We're always in range due to the Clamp above
id: humid
above: 0
below: 100
- script.execute: update_fan
#####################################################
## Setup of Scripts ##
## "update_fan" - set fan speeds ##
#####################################################
script:
- id: update_fan
mode: single
then:
- lambda: |- # ToDo: Convert to script and call it
- lambda: |- # Lets call this every time we need to update
float cutoff = id(lowHumCutoff).state;
int humidity = id(humid).state;
// Doing linear transform here because we need the id(lowHumCutoff) variable
// Max is 100 at 80%
// Min is 25 at cutoff%
// linear equation y = mx + c
// = ((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
if( x <= cutoff )
if( humidity <= cutoff )
speed = 25;
if( x >= 80)
if( humidity >= 80)
speed = 100;
// Test if we need to go slow
@@ -188,7 +196,7 @@ sensor:
speed = speed / 2;
// Turn the fan on and set the speed, or turn off
if( x >= cutoff )
if( humidity >= cutoff )
{
auto call = id(Extractor).turn_on();
call.set_speed(speed);