Using PC shutdown as trigger

Hi all,

I’m new to home assistant and so far am overwhelmed by the possibilities :slight_smile:

I got a few use cases working but becoming desperate with one seemingly easy thing: I’d like to trigger an automation when I shut down a PC.
My thought was to use network connectivity for this. I can see the PC as device via my router and it’s correctly switching home/away, so I’ve tried to put that in a trigger:

But this is never triggering. Can someone tell what’s wrong with my config? Or maybe has a better idea on how to realize this?


You could ping the PC every minute or so.

  - platform: ping
    name: "your_pc"
    scan_interval: 60

This will create a binary sensor and the change from on to off when the PC shuts down will trigger an automation.

- id: 'xxxxx'
  alias: PC shutdown
  description: 'Does something when a PC shuts down'
  - platform: state
    to: 'off'
    entity_id: binary_sensor.your_pc
  condition: []
  - something...

Your PC isn’t leaving/entering a zone, it’s state is changing from “home” <> “not_home”, so you should use the state trigger instead.

- id: 'xxxxx'
  alias: PC shutdown
  description: ''Do whatever when your PC goes offline"
  - platform: state
    to: 'not_home'
    entity_id: device_tracker.your_pc
  condition: []
  - whatever you want
1 Like

Or if you want to get really fancy you could send a MQTT packet or general API call from the PC to Home Assistant on shutdown, with a ping sensor as a redundant backup (in case you don’t properly shut down and fire the MQTT).

I do something similar with my Mac’s, but since Mac is already unix it’s easy to just use SSH to pass things around.

That sounds like what I want. I’ve set it up and will see if it works when I shut down my work PC later.

Worked like a charm, thanks a lot :slight_smile:

:+1: Cheers