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.

  • TedZanzibar@feddit.uk
    link
    fedilink
    English
    arrow-up
    1
    ·
    vor 5 Monaten

    I have my dock plugged into a smart plug and the laptop set in the BIOS to turn on when it receives power. I have an NFC tag on my coffee machine that I bloop while I’m making my morning brew, and that turns the dock on so that everything’s ready when I move into the office.

    For turning things off I have HASS.Agent installed and sending state updates (locked, unlocked, etc, which is useful for other automations) and when that sensor goes unavailable for 15 minutes it turns the plug off. I find that’s long enough to allow it to reboot for updates and what not.

    The sensor does report shutdown, reboot, and sleep states but I found that it often happens too quickly to get the change sent, so the unavailable state is more reliable.

    • limelight79@lemm.eeOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      vor 4 Monaten

      Yeah, unfortunately, I do not have access to the BIOS, nor can I install things on it - security restrictions. What you have done would have been a lot easier and more reliable though!