Waking up at 2am to adjust a ceiling fan is a small frustration — but a completely avoidable one. This Home Assistant automation watches your bedroom temperature all night and sets the fan speed automatically across four comfort tiers. Once it's running, you never touch the fan again.
What You'll Need
- Home Assistant (any recent version)
- A smart ceiling fan that supports percentage-based speed control
- A temperature sensor — a thermostat with a current temperature reading works perfectly
If your fan only supports on/off or preset speeds (low/medium/high), check whether your integration maps those to percentages — many do. The automation targets 25%, 50%, 75%, and 100%, which correspond to the four standard speed steps on most smart fans.
Step 1: Create a Sleeping Helper
The automation only manages the fan when you're actually in bed. A toggle helper (called an input boolean in Home Assistant) acts as the switch that tells the automation you're sleeping.
To create it, go to Settings → Devices & Services → Helpers and click Create helper. Choose Toggle and name it Sleeping. Home Assistant will create an entity called input_boolean.sleeping.
Add this toggle to your bedroom dashboard or a bedside button — one tap before bed hands control to the automation, one tap in the morning gives it back.
Step 2: Create the Temperature Threshold Helpers
The automation uses four temperature thresholds to decide which fan speed to run. Storing them as number helpers means you can adjust them from your dashboard without touching the automation itself.
Go back to Settings → Devices & Services → Helpers → Create helper and choose Number. Create four helpers with these names (Home Assistant will generate the entity IDs automatically):
- Master Bedroom Limit 25 →
input_number.master_bedroom_limit_25 - Master Bedroom Limit 50 →
input_number.master_bedroom_limit_50 - Master Bedroom Limit 75 →
input_number.master_bedroom_limit_75 - Master Bedroom Limit 100 →
input_number.master_bedroom_limit_100
Set the minimum to 60, maximum to 85, step to 0.5, and unit of measurement to °F for each one. You'll set the actual values in Step 4 once everything is wired up.
Step 3: Add the Automation
Go to Settings → Automations & Scenes → Create Automation, then click the three-dot menu in the top right and choose Edit in YAML. Replace the contents with the following:
alias: Master Bedroom Auto Fan
description: Adjusts fan speed based on temperature while sleeping
triggers:
- trigger: state
entity_id:
- input_boolean.sleeping
to: "on"
id: "on"
- trigger: time_pattern
minutes: /5
id: time
- trigger: state
entity_id:
- input_boolean.sleeping
to: "off"
id: "off"
conditions: []
actions:
- if:
- condition: state
entity_id: input_boolean.sleeping
state: "off"
then:
- action: fan.turn_off
target:
entity_id: fan.master_bedroom_ceiling_fan
- stop: Not sleeping
- choose:
- conditions:
- condition: numeric_state
entity_id: sensor.thermostat_current_temperature
above: input_number.master_bedroom_limit_100
sequence:
- action: fan.set_percentage
target:
entity_id: fan.master_bedroom_ceiling_fan
data:
percentage: 100
- stop: ""
- conditions:
- condition: numeric_state
entity_id: sensor.thermostat_current_temperature
above: input_number.master_bedroom_limit_75
sequence:
- action: fan.set_percentage
target:
entity_id: fan.master_bedroom_ceiling_fan
data:
percentage: 75
- stop: ""
- conditions:
- condition: numeric_state
entity_id: sensor.thermostat_current_temperature
above: input_number.master_bedroom_limit_50
sequence:
- action: fan.set_percentage
target:
entity_id: fan.master_bedroom_ceiling_fan
data:
percentage: 50
- stop: ""
- conditions:
- condition: numeric_state
entity_id: sensor.thermostat_current_temperature
above: input_number.master_bedroom_limit_25
sequence:
- action: fan.set_percentage
target:
entity_id: fan.master_bedroom_ceiling_fan
data:
percentage: 25
- stop: ""
default:
- action: fan.turn_off
target:
entity_id: fan.master_bedroom_ceiling_fan
mode: singleEntity IDs: Replace fan.master_bedroom_ceiling_fan with your fan's entity ID, and sensor.thermostat_current_temperature with your temperature sensor's entity ID. You can find both under Settings → Devices & Services.
Save the automation. Home Assistant will immediately start listening for the triggers — but nothing will happen until you set your thresholds in the next step.
Step 4: Tune Your Thresholds
Open your dashboard and find the four number helpers you created. Set them to temperatures that match your comfort — these are the values that work well as a starting point:
- 25% threshold — 68°F (fan turns on at a gentle hum)
- 50% threshold — 71°F
- 75% threshold — 74°F
- 100% threshold — 77°F (full power for hot nights)
The automation checks every five minutes, so after a night or two you'll have a feel for whether to shift the numbers up or down. If you wake up cold, raise the thresholds. If you're still warm, lower them. No need to touch the automation — just slide the numbers.
What It Feels Like
After a few nights the automation disappears into the background. The fan is just right — not because you set it, but because the room settled and the fan tracked it. You stop noticing the fan exists, which is exactly the point.
Flip Sleeping off in the morning, and the fan stops. The rest of the day is yours to manage however you like. One automation, one toggle, and a bedroom that takes care of itself.