Way to detect if PC is powered on

I am looking for a way to detect if my PC is powered on or recently went to sleep but unsure on the best method to achieve it.

My PC is set to sleep after 20 mins of idle and I essentially want to turn off my TV when the PC goes to sleep.

I don’t want to use anything that pings the PC else it will wake up which is not what I want to happen. Is there a way to poll what devices are connected to my router? I have an ASUS RT-AC66U. Home assistant is able to pick up some elements from the router via the UPnP integration but I was hoping it could also detect connected devices.

Another option would be a smart or a connected power meter. I have a ‘dumb’ one which merely reads the current energy usage. If this is easier can anyone recommend a brand that would do what was needed? I don’t mind making something as I have a number of ESP8266 boards.

Any help on this would be much appreciated.

I do similar using some software called eventghost with its mqtt plugin. Then use mqtt in ha to get events

EDIT: I use HASS.Agent now

2 Likes

Ah so essentially the pc posts an mqtt update if it’s up? What do you have doing the logic to detect when it isn’t?

I have MQTT set up as it’s what I use to push sensor status updates, but can you also use subscribers to send mqtt messages on response or lack there of an update from the PC? May be thinking too far into this.

No, eventghost can send an mqtt message for any PC event - on shutdown, on wakeup and on standby included.

Look into IOTLink. I think this could provide what you need.

1 Like

It’s not super clear from your post, but I think you are looking for something specific to Windows. If that isn’t the case I use this switch to detect if my monitor is on or not in linux:

- platform: command_line
  switches:
    monitor:
      friendly_name: Monitor State
      command_on: echo
      command_off: echo
      command_state: ssh user@ipaddress -i my-ssh.key -o StrictHostKeyChecking=no DISPLAY=:1 xset -q | grep 'Monitor is On'

I don’t care about turning it on or off, just want the state reported for automations to help determine if I am at my computer or not. That’s why I have commands that don’t do anything for on/off.

1 Like

Thanks. I was looking at something specifically for a Windows 10 machine. I have installed IOTLink and got it to send a load of data via MQTT to Home Assistant. I just have to work out the best way to create the automation now. I couldn’t work out how to get Eventghost to do what i wanted. I dont want to be able to control the PC just merely perform actions to the TV depending on what the PC is doing, i.e. turn the screen off when it isnt in use.

So, I’ve tried EventGhost and created two macros based on System.UnIdle and System.Idle which publish a topic: EventGhost/BRUNT-WIN10/status = active and EventGhost/BRUNT-WIN10/status = idle but I cannot figure out a binary_sensor for HA. My last try is:

  - platform: mqtt    
    name: "Brunt-Win10"
    state_topic: EventGhost/BRUNT-WIN10/status
    payload_on: "active"
    payload_off: "idle"
    device_class: "presence"

image
but that is not working.

Next I tried IOT Link…
I presume I need a json topic and value template like:

  - platform: mqtt
    name: ozw_network_status
    state_topic: OpenZWave/1/status/
    value_template: >
      {{ "ON" if value_json.Status in ["driverAwakeNodesQueried", "driverAllNodesQueriedSomeDead", "driverAllNodesQueried"] else "OFF" }}
    json_attributes_topic: OpenZWave/1/status/
    device_class: "connectivity"

but examining the iotlink item idle-time?
image

What are you using for a sensor/binary_sensor?

NM! I found a sh!t load of entities added via homeassistant discovery. Awesome!!

Created binary sensor:

binary_sensors:
  - platform: template
    sensors:
      my_pc_is_active:
        friendly_name: "My PC is Active"
        value_template: "{{ states('sensor.brunt_win10_system_idle_time')|float < 30 }}"

and it works! Just going to increase the < 30 now after testing. Yay!

The other approach would be to disable “wake-on-ping” if you don’t really need it. It would be much simpler.

The instruction how to allow only magic packet to wake up the PC can be found here: https://docs.microsoft.com/en-us/troubleshoot/windows-client/networking/unwanted-wake-up-events#:~:text=If%20the%20network%20adapter%20supports,box%2C%20and%20then%20click%20OK.

image

1 Like

For future noobs like me, this came in handy: https://www.reddit.com/r/homeassistant/comments/ge6koq/connecting_your_pc_to_home_assistant_with_iotlink/

1 Like

https://hassagent.readthedocs.io/en/latest/
this is the way to go!

2 Likes

I have to agree. Made the switch some time ago, struggled with getting iotlink stable.

Installed Hass.agent too. Even went over to EMQX as the broker, see all topics coming in.

But none do end up as entities in Home Assist :man_shrugging::man_shrugging::man_shrugging:
Only 3 manual 433 sensors do show up, because they are defined as binary sensors in configuration.yaml.

I have search hours and hours now, and do not know where to check or where a configuration is missing/wrong.

Who can help me out?