When Your “Smart” Home Starts Acting Dumb
I know the feeling.
One morning last spring my bathroom fan refused to turn off—for six hours—because the out-of-the-box automation only understood humidity, not showers. My wife threatened to rip the sensor off the wall.
Sound familiar?
Here’s the truth:
Pre-made automations are like IKEA furniture. They look fine until you need a different-sized shelf. Then you’re stuck.
Python Is Just a Fancy Electric Drill
Think of Home Assistant as the house frame. Python is the drill that lets you add extra outlets, secret drawers, or—why not—an electric skateboard charger in the attic.
Three ways to plug the drill in
1) Shell Command → the “duct tape” method
Fastest way to run any Python file from an automation.
1-minute setup
- Make a folder:
/config/scripts - Drop your script inside
- Tell Home Assistant about it in one line of YAML
shell_command:
start_coffee_brewer: "python3 /config/scripts/brew_coffee.py"
Call it from any automation exactly like turning on a light.
2) Python Script → the “native tongue” method
Put python_script: in your configuration. Write tiny files that run inside Home Assistant and can see every sensor, switch, and weather report.
My ultra-simple movie-night script
# /config/python_scripts/movie_time.py
lights = "light.living_room"
projector_state = hass.states.get("switch.projector")
# Only dim if projector is on but lights are still bright
if projector_state == "on":
hass.services.call("light", "turn_on", {
"entity_id": lights,
"brightness": 30
})
I trigger it with one tap on my phone.
3) Custom Component → the “built-in renovation” method
When you need something permanent—like a sensor that fetches tide tables for your beach house—you build a small add-on that looks and acts like any official integration.
It’s more work, but you only do it once. Afterwards you update it like any other Home Assistant piece.
Copy-Paste Automations You Can Run Tonight
Presence faker that learns from you
# /config/python_scripts/presence_learning.py
"""
Turn on random lights while we're away, but only at the
exact same minutes we've been active over the past week.
"""
recent_on = hass.states.get("history_sensor.lights_last_on_times")
pick = random.choice(recent_on)
hass.services.call("light", "turn_on", {"entity_id": pick})
Savings alarm
# If power price is above 35 cents, kill the water heater switch
if current_electric_price > 0.35:
hass.services.call("switch", "turn_off", {"entity_id": "switch.water_heater"})
Run it every fifteen minutes and watch your bill drop.
Beginner Checklist (Use It While the Kettle Boils)
- Open your
configuration.yaml - Add one line:
python_script: - Restart Home Assistant
- Create
/config/python_scripts/your_name.py - Paste a tiny script from above
- Go to Developer Tools -> Services
- Type “python_script.your_name” and click “Call Service”
- Grin when something actually happens
Questions I Get Every Week
“Will I break the house?”
Probably not. My six-year-old once ran an infinite loop script; Home Assistant just logged an error and moved on. Worst case: restart.
“Do I need to know Python?”
If you can write an email, you can automate a light. Copy, tweak names, done. Build complexity later.
“Can I share stuff with friends?”
Sure. Zip your script or push your custom component to GitHub. I’ve forked colleagues’ integrations more times than I’ve ordered pizza.
The First Five Minutes After Reading
Open Home Assistant right now.
Pick one annoying task your house can’t do yet.
Paste the ten-line shell script tutorial.
Hit “reload automations.”
You’ll hear an unfamiliar sound: your house obeying you.







