Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JohnNeville/93e00d74e493e310f29998da5afc6e2b to your computer and use it in GitHub Desktop.
Save JohnNeville/93e00d74e493e310f29998da5afc6e2b to your computer and use it in GitHub Desktop.
# This is a fork of https://community.home-assistant.io/t/turn-a-fan-on-and-off-based-on-the-difference-between-a-humidity-sensor-and-a-baseline/255999
blueprint:
name: Humidity Management (Fork)
description: Turn a fan on and off based on the difference between a humidity sensor and a baseline
domain: automation
input:
humidity_sensor:
name: Humidity Sensor
description: A sensor that measures the humidity of the area
selector:
entity:
domain: sensor
reference_humidity:
name: Reference Humidity
description: A percentage point value that indicates the baseline humidity if there is no reference sensor available
default: 60
reference_humidity_sensor:
name: Reference Humidity Sensor
description: A sensor that indicates the baseline humidity of the location
selector:
entity:
domain: sensor
default: []
fan_switch:
name: Fan Switch
description: A switch that turns the fan on and off
selector:
entity:
domain: switch
rising_threshold:
name: Rising Threshold
description: How many percentage points above the reference humidity the sensor can rise before the fan is turned on
selector:
number:
min: 0
max: 100
default: 8
falling_threshold:
name: Falling Threshold
description: How many percentage points above the reference humidity the sensor must fall to before the fan is turned off
selector:
number:
min: 0
max: 100
default: 3
related_scripts:
name: Related Scripts
description: Scripts that will also manage this fan in single mode (with delay) to prevent this from running
selector:
target:
entity:
domain: script
trigger:
- entity_id: !input humidity_sensor
platform: state
- entity_id: !input reference_humidity_sensor
platform: state
condition:
- condition: template
value_template: '{{ mode != switch_state }}'
- condition: state
entity_id: !input related_scripts
attribute: current
state: "0"
action:
- choose:
- conditions:
- condition: template
value_template: "{{mode}} == 'on'"
sequence:
- service: switch.turn_on
entity_id: !input fan_switch
- conditions:
- condition: template
value_template: "{{mode}} == 'off'"
sequence:
- service: switch.turn_off
entity_id: !input fan_switch
variables:
reference_humidity: !input reference_humidity
humidity_sensor: !input humidity_sensor
reference_humidity_sensor: !input reference_humidity_sensor
fan_switch: !input fan_switch
switch_state: '{{ states(fan_switch) }}'
rising_threshold: !input rising_threshold
falling_threshold: !input falling_threshold
difference: '{{ states(humidity_sensor)|float - (states(reference_humidity_sensor)|float
or reference_humidity|float) }}'
mode: '{% if switch_state == ''off'' and difference|float > rising_threshold|float %}on{%
elif switch_state == ''on'' and difference|float > falling_threshold|float %}on{% else %}off{%
endif %}'
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment