Skip to content

Instantly share code, notes, and snippets.

@haberda
Last active August 27, 2022 13:58
Show Gist options
  • Save haberda/f80691db034bc16e64f9069c96ca170d to your computer and use it in GitHub Desktop.
Save haberda/f80691db034bc16e64f9069c96ca170d to your computer and use it in GitHub Desktop.
Fan Blueprint - with occupancy and temperature
blueprint:
name: Fan - with occupancy and temperature
description: Turn on a fan when occupancy is detected and temperature is above a set level.
domain: automation
input:
occupancy_entity:
name: Occupancy Sensor
selector:
entity:
domain: binary_sensor
device_class: occupancy
temperature_entity:
name: Temperature Sensor
selector:
entity:
domain: sensor
device_class: temperature
temperature_high:
name: High Temperature
description: The temperature above which the fan will be set to high.
default: 80
selector:
number:
min: 0
max: 100
temperature_medium:
name: Medium Temperature
description: The temperature above which the fan will be set to medium.
default: 78
selector:
number:
min: 0
max: 100
temperature_low:
name: Low Temperature
description: The temperature above which the fan will be set to low.
default: 76
selector:
number:
min: 0
max: 100
fan_high:
name: High fan percentage
description: The percentage for high fan speed.
default: 100
selector:
number:
min: 0
max: 100
fan_med:
name: Medium fan percentage
description: The percentage for medium fan speed.
default: 66
selector:
number:
min: 0
max: 100
fan_low:
name: Low fan percentage
description: The percentage for low fan speed.
default: 33
selector:
number:
min: 0
max: 100
fan_target:
name: Fan(s)
description: A single or comma seperated list of fan(s) to act on.
selector:
entity:
domain: fan
no_occupancy_wait:
name: Wait time
description: Time to leave the fan on after unoccupied.
default: 300
selector:
number:
min: 0
max: 3600
unit_of_measurement: seconds
time_based:
name: "Restrict by time"
description: "Only turn on fan(s) between the start and end times."
default: false
selector:
boolean: {}
start_time:
name: Start Time
default: "22:00"
selector:
time: {}
end_time:
name: End Time
default: "08:00"
selector:
time: {}
disable_entity:
name: Disable entity
description: Binary sensor or input boolean that when on disables the updating of fans.
selector:
entity:
variables:
time_based: !input time_based
trigger:
- platform: state
entity_id: !input temperature_entity
id: 'temp_change'
- platform: state
entity_id: !input occupancy_entity
to: 'on'
id: 'occupancy_on'
- platform: state
entity_id: !input disable_entity
to: 'off'
id: 'disable_entity_off'
- platform: state
entity_id: !input occupancy_entity
to: 'off'
for: !input no_occupancy_wait
id: 'occupancy_off'
condition:
- condition: or
conditions:
- condition: not
conditions:
- condition: template
value_template: '{{ time_based }}'
- condition: and
conditions:
- condition: template
value_template: '{{ time_based }}'
- condition: time
after: !input start_time
before: !input end_time
- condition: state
entity_id: !input disable_entity
state: 'off'
action:
- if:
- condition: state
entity_id: !input occupancy_entity
state: 'on'
- condition: numeric_state
entity_id: !input temperature_entity
above: !input temperature_low
then:
- choose:
- conditions:
- condition: numeric_state
entity_id: !input temperature_entity
above: !input temperature_high
sequence:
- condition: not
conditions:
- alias: "Not already set to high"
condition: state
entity_id: !input fan_target
attribute: percentage
state: !input fan_high
- service: fan.turn_on
data:
percentage: !input fan_high
target:
entity_id: !input fan_target
- conditions:
- condition: numeric_state
entity_id: !input temperature_entity
above: !input temperature_medium
sequence:
- condition: not
conditions:
- alias: "Not already set to medium"
condition: state
entity_id: !input fan_target
attribute: percentage
state: !input fan_med
- service: fan.turn_on
data:
percentage: !input fan_med
target:
entity_id: !input fan_target
default:
- condition: not
conditions:
- alias: "Not already set to low"
condition: state
entity_id: !input fan_target
attribute: percentage
state: !input fan_low
- service: fan.turn_on
data:
percentage: !input fan_low
target:
entity_id: !input fan_target
else:
- condition: state
entity_id: !input fan_target
state: 'on'
- service: fan.turn_off
target:
entity_id: !input fan_target
mode: restart
max_exceeded: silent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment