Best way to determine if PC is turned off

So I’ve got an automation that controls the outlet my PC stuff is on. It either checks for presence or if the PC was turned off. Since there are a few ways to determine this, I’d like your input on what the “safest” way is as to not cut the power while the PC is still turned on. Available to me currently are:

  • power consumption of the outlet switch, though it might be hard to find a threshold depending on the devices connected to it
  • switch entity from wake_on_lan integration which pings the PC (using that to turn the PC on automatically)
  • device_tracker entity from my FRITZ!Box, kinda slow though. Currently using that for the trigger as you can see below
  • entity from ping integration? haven’t tried that
---
alias: "Office: PC Outlet"
description: >-
  Controls the power outlet for the PC stuff to save energy.

id: cd367e79-bcd1-4914-90d9-dbff51ea0ccf
mode: queued

trigger:
  - alias: office was entered
    platform: state
    entity_id: binary_sensor.office_presence_sensor_occupancy
    id: &entered office entered
    from: "off"
    to: "on"

  - alias: office is unoccupied
    platform: state
    entity_id: binary_sensor.office_presence_sensor_occupancy
    id: &unoccupied office unoccupied
    from: "on"
    to: "off"
    for: "00:10:00"

  - alias: pc was turned off
    platform: state
    entity_id: device_tracker.pc_main
    id: &shutdown pc turned off
    from: home
    to: not_home
    for: "00:10:00"

action:
  - choose:
      - alias: turn on the power outlet
        conditions:
          - alias: office was entered
            condition: trigger
            id: *entered

          - alias: i am home
            condition: zone
            entity_id: person.roman
            zone: zone.home

          - alias: power outlet is not already on
            condition: state
            entity_id: switch.office_pc_area
            state: "off"
        sequence:
          - alias: turn on pc area power
            service: switch.turn_on
            target:
              entity_id: switch.office_pc_area

      - alias: turn off the power outlet
        conditions:
          - alias: i'm not in the office or the pc was turned off
            condition: trigger
            id:
              - *unoccupied
              - *shutdown

          - alias: pc is turned off
            condition: state
            entity_id: switch.office_pc
            state: "off"

          - alias: power outlet is on
            condition: state
            entity_id: switch.office_pc_area
            state: "on"
        sequence:
          - alias: turn off pc area power
            service: switch.turn_off
            target:
              entity_id: switch.office_pc_area

Use the WoL switch. It works perfectly for me.

2 Likes

You can probably stay with the router-based device_tracker, as long as you don’t mind the wait time for it to go off (can actually be beneficial in some cases). I use this to override heating controls (if PC is on), works just fine (or I’d quickly notice!).


Something of interest: You can get a UPS with a master plug (Eaton calls it EcoControl), that turns off specific plugs automatically whenever it stops detecting power consumption (threshold in the UPS settings). Pretty nice feature to have, on top of the battery backup!

1 Like