this post was submitted on 20 Jun 2024
54 points (95.0% liked)

homeassistant

12129 readers
10 users here now

Home Assistant is open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. Available for free at home-assistant.io

founded 2 years ago
MODERATORS
 

No major question here, just thought you might find this interesting. It's an example of the kind of (off-the-wall) things you can do with HA that aren't immediately obvious. When I was starting out with HA, I enjoyed reading these examples, because it gave me ideas for my own setup. And, I wrote many automations that should really be scripts, so hopefully this will help someone avoid that and recognize the power of scripts early.

At home, my laptop from work sits (closed) on a stand under the monitors. I have a docking station for it, but the docking station doesn't have a power button to start the laptop (the official Dell docking stations have a power button, but other brand of docking stations don't). So, since I got that stand a few weeks ago, I've been pulling the laptop out and opening juuuuuuust enough that I could reach the power button, then closing it and sliding it back into the stand. There had to be a better way that didn't involve buying an expensive Dell docking station.

The docking station power is on a Sonoff S31 outlet (flashed with Tasmota, not that that's important here) that is remotely controllable. Long ago, I set up HA automations that turned on the S31 when the laptop was detected on the network, and shut off the S31 after the laptop dropped off the network at the end of the day (leaving in a time delay so it didn't shut off if there was a momentary network glitch). So, I'd boot the laptop, and a moment later the docking station would kick on and connect the mouse and monitors to it. And the end of the day, I shut down the laptop, and a few minutes later the docking station shuts off automatically.

I recently discovered the Wake on LAN integration. So, after setting that up, I wrote a script that turns on the S31, waits a while*, then triggers the Wake-on-LAN for the laptop...and it boots up! With HA, I can start the boot process while I'm still relaxing in the living room before starting work; in theory I'll go into the office and it'll be ready for me to log in.

Heck, if HA knew for certain it was a workday, it could boot the laptop for me.....hmmm. Maybe something to think about for the future.

*How long? Well, 30 seconds seems to be too short; the laptop doesn't respond to the WoL command after just 30 seconds with power applied. It did work this morning when I waited several minutes to try it again. I just changed the delay to 1 minute and will see how that works tomorrow.

I also added a repeat loop (starting after that 1 minute timer) with three components:

  • A condition that looks for the laptop being "Away" on the network. (If it is "Home" on the network, the condition will end the script.)
  • If it is, then it tries the WoL command again.
  • Then waits 30 seconds and repeat.

The repeat loop counter is set to 3, for a total of 4 attempts to start the laptop. I'll check the traces and see when it starts working, and set the initial delay accordingly, so that in general it shouldn't need the repeat loop.

If people want, I can post (sanitized) YAML. But I do like explaining the process rather than just posting code.

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 3 points 5 months ago (1 children)

Yeah WOL was one of the first things I looked for in HA because I just didn't have all that much in the way of Smart stuff.

Anyway nowadays I have an automation you may like. I have set up a little wireless dock for my phone on my desk. It's the only wireless charger I use, so using the Companion app sensors (namely the charger type) I have set up an automation that turns on my PC when I dock my phone.

Meaning I literally flop down on my chair and put my phone on the charging stand and the PC turns on.

Now when that PC is picked up on the network HA will turn on my monitor (via a smart plug) and my desk lamp.

I also have a program on the PC that detects what I'm doing, and can switch the PC off!

So I can add switching the PC off to my automations, like my Goodnight automation