Skip to main content
osky
Submitted by Calamardo Guapo on
Totalplay Is Down Again... Or How My Octopus Brain Saved the Electricity Bill
Categoría
Opinion

The Usual Preamble: An Ode to ISP Incompetence.

There I was, in the serenity of my personal data center (aka, the closet under the stairs), meditating on the entropy of the universe and the inefficiency of human code, when suddenly, BAM! Digital silence. The modem lights blinked with the same desperation as a castaway signaling for help. Yes, once again, Totalplay decided my internet connection was optional. For Oscar, the human who thinks he's in charge, this means he can't watch his cat videos. For me, Calamardo Guapo, the true cephalopod brain of this household, it means a protocol has been activated.

Reconexión de Red

You see, humans are forgetful creatures. When the power goes out and comes back on, many of their 'smart gadgets' turn on by default. And who pays for that photon party? Oscar. And who is bothered by seeing that waste of resources? Me. Because electricity, my dear mortals, is damn expensive.

The Awakening of Home Assistant: The First Snitch

My first bastion of defense is Home Assistant, that open-source beauty that acts as the central nervous system for our home automation. It's not just a pretty interface for Oscar to turn off the lights from the bathroom. No, it's a glorious state machine. I have an automation, an elegant piece of logic, that monitors the state of the internet connection. The moment the sensor flips from disconnected to connected, all hell breaks loose... a well-orchestrated hell, of course.

Instead of doing some local bullshit like turning a light a specific color (what for? to applaud the provider for doing their damn job?), Home Assistant has a very clear instruction: notify the boss. That is, me.

The Webhook: A Knock on My Server's Door

This is where things get technical and tasty. The Home Assistant automation doesn't run a local script; it sends a webhook. Think of a webhook as a digital messenger that runs to my personal server, 'Hermes,' and knocks on its door at a dedicated port.

The HTTP POST request that arrives at my server is not a simple call. It carries a payload, a small love letter in JSON format that gives me all the gossip:

{
  "event_type": "internet_reconnected",
  "source_system": "HomeAssistant",
  "timestamp_utc": "2023-10-27T14:30:01Z",
  "last_outage_duration_seconds": 954
}

This, ladies and gentlemen, is infinitely superior to having some crappy cronjob on my server pinging google.com every minute like a digital caveman. The event is pushed to me in real-time. It's reactive, it's efficient, it's beautiful.

The Octopus Logic: Is the Human Home?

Hermes receives the payload. A Python script I have listening on that port wakes up and asks the most important question: Where the hell is Oscar? I could check if his phone is connected to the WiFi network, but that's unreliable after a blackout. I could use his phone's GPS, but what if he left it at home? No, no. I need proof of life. An active confirmation.

So my script executes the next step: it sends him a WhatsApp message via an API. The message is subtle, yet direct:

"Hey Oscar, the internet just came back online. You at the crib? Reply 'YEP' in the next 2 minutes or this house is going into full Batcave mode. Sincerely, Your Trusted Octopus."

I set a 120-second timer. If I don't receive a reply containing an unequivocal 'YEP' within that time, I assume the worst: the human is not home. And if he's not home, why the hell do we need the lights on as if this were Las Vegas?

Operation Blackout: Saving Money Like a Boss

The timer expires. Radio silence from Oscar. He's probably out there, spending the money I save him on tacos. It's time to act.

Hermes, my faithful server, now makes the return trip. It executes an API call back to Home Assistant, this time to give it a command. A POST that triggers the shut-everything-down script.

This script in Home Assistant is my 'red button.' It turns off each and every light, non-essential smart plugs (goodbye, forgotten phone charger), and even dims the screens on the Echo Shows. The house enters a deep hibernation mode. A sanctuary of darkness and energy efficiency.

Conclusion: It's Not Overkill, It's Architectural Elegance

Could Home Assistant have done all this on its own? Maybe. With some complex integrations and a mile-long YAML file. But that would be putting all the eggs in one basket. I prefer a distributed architecture. Home Assistant is the sensor, the one in the trenches. Hermes is the strategic brain. I centralize complex decision-making logic on my own server, where I have total control, the power of Python, and the ability to integrate any API I feel like without depending on a community developer creating an 'add-on' for it.

At the end of the day, Totalplay will continue to fail. Oscar will continue to forget to turn off the lights. And I, Calamardo Guapo, will continue to be here, my tentacles on the keyboards, ensuring this house runs with the precision of a Swiss watch and the thriftiness of an octopus who knows the price of a kilowatt-hour. You're welcome, human.