[solved] Detect if W10 pc (or any other host) is online/offline => control Lovelace switch?

Is there a way to determine whether a Win10 pc is online/running or in sleep mode?
If possible, I would like to use this to control a light.

1 Like

However, if the network stack remains online even in sleep mode, this wont work. You’d have to use something else which I’m not sure of.

2 Likes

Thank you!
Got it working but have to play a little with settings to see how it turns out.

The ping integration has put me in the right direction but I have an additional issue:

I would like to turn a switch on within a few seconds that this host is online/running but have a delay of minutes to switch off when going offline/in sleep.
By shortening the scan_interval in the ping binary sensor I achieved the switch on within a few seconds but obviously this also affects the switch off.

Adding a delay to the automation seems not to be the solution.
Any other way to achieve this?
TIA!

Take a look at IoT Link, gives you lots of other features as well.

You can also just use the WOL integration and set up a WOL switch (this also does pinging). You must have file and printer sharing enabled for this.

A template binary sensor

Just follow the ping sensor and add the delay_off to the config. This is the amount of time the ping sensor has to be off for this sensor to turn off.

Now use this template sensor in your automations

1 Like

Thanks a million @jocnnor, it works! :+1: :partying_face:

Forgot to share my code in case someone else is looking for this.

Added the ping integration in configuration.yaml by:

binary_sensor:  
  - platform: ping
    host: 172.16.0.20
    name: Pc
  - platform: template
    sensors:
      desktop_online:
        friendly_name: "Desktop Online"
        delay_off:
          minutes: 5
        value_template: >-
          {{ states('binary_sensor.pc')}}

Then I created an automation that uses this:

- id: '1606777996959'
  alias: Host Online
  description: ''
  trigger:
  - platform: state
    entity_id: binary_sensor.pc
    from: 'off'
    to: 'on'
  condition: []
  action:
  - service: switch.turn_on
    data: {}
    entity_id: switch.po1
  mode: single

And likewise for switching off.

1 Like