Hello!
I have one of these old bad boy.
I hate running it all the time, hate getting up and turning it on and off all the time… I also like to run it at night just to get the air moving a bit. But keeping it on for all night is a waste and gets me sick.
So i made the only logical solution… i integrated it into HASS
i hade a basic Sonoff device that i used to control the fan.
The fan has 4 button to adjust the speed, but i always run it in the slowest option.
Heres the finished control panel:
You can:
- Manually turn the fan On or OFF from hass webUI or from a Telegram bot button.
- Turn it ON and set an automatic and an adjustable turn off timer. Timer range is 0-24hours + 0-60mins with 15min incremental
- Turn it On with adjustable automatic OFF, adjustable automatic ON and how long should it loop.
Think about this option like: You want the fan to be on for 15minutes, then it should be off for 45mins before it turns on again. Do this cycle for 6 hours.
You need to have a basic SONOFF device and working hass MQTT
So anyway, heres the yamls:
# #
##### ####
# Configuration.yaml #
##### ####
# #
switch:
- platform: mqtt
name: "Sonoff - Room Fan"
command_topic: "cmnd/sonoff/power"
state_topic: "stat/sonoff/POWER"
payload_on: "ON"
payload_off: "OFF"
qos: 1
retain: true
#
sensor:
- platform: time_date
display_options:
- 'time'
- 'date_time'
- platform: template
sensors:
bedroom_fan_state_timer:
value_template: "{% if is_state('input_boolean.enable_timer', 'on') and is_state('switch.sonoff__room_fan', 'on')%}turning off in: {{ (((states.input_number.bedroomfan_timer_hours.state |int *3600) + (states.input_number.bedroomfan_timer_minutes.state |int *60) - (as_timestamp(strptime(states('sensor.date__time'),'%Y-%m-%d, %H:%M'))-as_timestamp(states.input_boolean.enable_timer.last_updated)))| timestamp_utc).split(' ')[1]}}{% endif %}{% if is_state('input_boolean.enable_timer', 'off') and is_state('input_boolean.enable_circulation', 'on') %} turning on in: {{(((states.input_number.bedroomfan_air_circulation_hours.state |int *3600)+(states.input_number.bedroomfan_air_circulation_minutes.state |int *60)-(as_timestamp(strptime(states('sensor.date__time'),'%Y-%m-%d, %H:%M'))-as_timestamp(states.input_boolean.enable_timer.last_updated)))| timestamp_utc).split(' ')[1]}}{% endif %}"
friendly_name: Current program
#
input_number:
bedroomfan_timer_hours:
name: Keep on - Hours
icon: mdi:timer
initial: 0
min: 0
max: 24
step: 1
bedroomfan_timer_minutes:
name: Keep on - Minutes
icon: mdi:timer
initial: 30
min: 0
max: 60
step: 15
#
bedroomfan_air_circulation_hours:
name: Keep off - Hours
icon: mdi:timer
initial: 0
min: 0
max: 24
step: 1
#
bedroomfan_air_circulation_minutes:
name: Keep off - Minutes
icon: mdi:timer
initial: 15
min: 0
max: 60
step: 15
#
bedroomfan_air_circulation_active_for:
name: Active for - Hours
icon: mdi:timer
initial: 1
min: 0
max: 24
step: 1
# #
##### ####
# Automation.yaml #
##### ####
# #
- alias: Fan - Air Circulation turned on
hide_entity: false
trigger:
- platform: state
entity_id: 'input_boolean.enable_circulation'
to: "on"
action:
- service: input_boolean.turn_on
entity_id: input_boolean.enable_timer
- service: switch.turn_on
entity_id: switch.sonoff__room_fan
# Circulation OFF
- alias: Fan - Air Circulation turned off
hide_entity: false
trigger:
- platform: state
entity_id: 'input_boolean.enable_circulation'
to: "off"
action:
- service: input_boolean.turn_off
entity_id: input_boolean.enable_timer
- service: switch.turn_off
entity_id: switch.sonoff__room_fan
#
- alias: Fan - all off
hide_entity: false
trigger:
- platform: state
entity_id: 'switch.sonoff__room_fan'
to: "off"
action:
- service: input_boolean.turn_off
entity_id: input_boolean.enable_timer
#
#
- alias: Timer on, so turn the fan on
hide_entity: false
trigger:
- platform: state
entity_id: input_boolean.enable_timer
to: "on"
action:
- service: switch.turn_on
entity_id: switch.sonoff__room_fan
#
- alias: Fan - Air Circulation
hide_entity: false
trigger:
- platform: template
value_template: "{% if (as_timestamp(strptime(states('sensor.date__time'),'%Y-%m-%d, %H:%M'))-as_timestamp(states.switch.sonoff__room_fan.last_updated)) >(states.input_number.bedroomfan_air_circulation_hours.state |int *3600) + (states.input_number.bedroomfan_air_circulation_minutes.state |int *60) %}true{% else %}false{% endif %}"
- platform: template
value_template: "{% if (as_timestamp(strptime(states('sensor.date__time'),'%Y-%m-%d, %H:%M'))-as_timestamp(states.input_boolean.enable_circulation.last_updated)) >(states.input_number.bedroomfan_air_circulation_hours.state |int *3600) + (states.input_number.bedroomfan_air_circulation_minutes.state |int *60) %}true{% else %}false{% endif %}"
condition:
condition: and
conditions:
- condition: state
entity_id: 'switch.sonoff__room_fan'
state: "off"
- condition: state
entity_id: 'input_boolean.enable_circulation'
state: "on"
action:
- service: switch.turn_on
entity_id: switch.sonoff__room_fan
- service: input_boolean.turn_on
entity_id: input_boolean.enable_timer
#
- alias: Fan - Air Circulation Ative for x Hours
hide_entity: false
trigger:
- platform: template
value_template: "{% if (as_timestamp(strptime(states('sensor.date__time'),'%Y-%m-%d, %H:%M'))-as_timestamp(states.switch.sonoff__room_fan.last_updated)) >(states.input_number.bedroomfan_air_circulation_active_for.state |int *3600) %}true{% else %}false{% endif %}"
condition:
condition: and
conditions:
- condition: state
entity_id: 'input_boolean.enable_circulation'
state: "on"
action:
- service: switch.turn_off
entity_id: switch.sonoff__room_fan
- service: input_boolean.turn_off
entity_id: input_boolean.enable_timer
# #
##### ####
# Groups.yaml #
##### ####
# #
bedroomfan:
name: Bedroom Fan
entities:
- switch.sonoff__room_fan
- input_boolean.enable_timer
- sensor.bedroom_fan_state_timer
- input_number.bedroomfan_timer_hours
- input_number.bedroomfan_timer_minutes
- input_boolean.enable_circulation
- input_number.bedroomfan_air_circulation_hours
- input_number.bedroomfan_air_circulation_minutes
- input_number.bedroomfan_air_circulation_active_for
# #
##### ####
# Input_boolean.yaml #
##### ####
# #
enable_timer:
name: "Enable Timer"
initial: off
icon: mdi:robot
enable_circulation:
name: "Enable Air Circulation"
initial: off
icon: mdi:robot
FYI: The “Current program” text updates every minute.
You can spicey it up and if HASS knows when you arrived home, you can set it up to auto turn on the fan for x minutes or auto turn off when you open the door, PIR sensor detection…
I bet you can set up an “old” room humidifier with this config too.