Update bathroom-fan.yaml
Changed to use a Script for updating Fan Speed/State
This commit is contained in:
@@ -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,45 +162,51 @@ 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
|
|
||||||
below: 100
|
|
||||||
then:
|
|
||||||
- lambda: |- # ToDo: Convert to script and call it
|
|
||||||
float cutoff = id(lowHumCutoff).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));
|
|
||||||
|
|
||||||
// Clamp between 25 and 100
|
|
||||||
if( x <= cutoff )
|
|
||||||
speed = 25;
|
|
||||||
if( x >= 80)
|
|
||||||
speed = 100;
|
|
||||||
|
|
||||||
// Test if we need to go slow
|
|
||||||
if( id(quietModeSwitch).state || id(pirSensor).state )
|
|
||||||
speed = speed / 2;
|
|
||||||
|
|
||||||
// Turn the fan on and set the speed, or turn off
|
#####################################################
|
||||||
if( x >= cutoff )
|
## Setup of Scripts ##
|
||||||
{
|
## "update_fan" - set fan speeds ##
|
||||||
auto call = id(Extractor).turn_on();
|
#####################################################
|
||||||
call.set_speed(speed);
|
|
||||||
call.perform();
|
script:
|
||||||
}
|
- id: update_fan
|
||||||
else
|
mode: single
|
||||||
{
|
then:
|
||||||
auto call = id(Extractor).turn_off();
|
- lambda: |- # Lets call this every time we need to update
|
||||||
call.perform();
|
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)) * humidity + (100-((75/ (80-cutoff))*80));
|
||||||
|
|
||||||
|
// Clamp between 25 and 100
|
||||||
|
if( humidity <= cutoff )
|
||||||
|
speed = 25;
|
||||||
|
if( humidity >= 80)
|
||||||
|
speed = 100;
|
||||||
|
|
||||||
|
// Test if we need to go slow
|
||||||
|
if( id(quietModeSwitch).state || id(pirSensor).state )
|
||||||
|
speed = speed / 2;
|
||||||
|
|
||||||
|
// Turn the fan on and set the speed, or turn off
|
||||||
|
if( humidity >= cutoff )
|
||||||
|
{
|
||||||
|
auto call = id(Extractor).turn_on();
|
||||||
|
call.set_speed(speed);
|
||||||
|
call.perform();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
auto call = id(Extractor).turn_off();
|
||||||
|
call.perform();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#####################################################
|
#####################################################
|
||||||
|
|||||||
Reference in New Issue
Block a user