Wake on Lan with PC status

Hello,

I am very new to home assistant and i am not sure how to set up a switch that turns on my windows PC and get the status of that PC.

I have tried the following:

In configuration.yaml:

wake_on_lan:

I have then tried to add the following code in the configuration UI, manual code:

switch: 
  - platform: wake_on_lan
  mac_address: "xx:xx:xx:xx:xx:xx"
  name: "Desktop"
  host: "192.168.1.X"
  broadcast_address: "192.168.1.255"

However i get a No card type error or SetConfig error. I have also tried adding it to the configuration.yaml but to no avail.

I must be missing something or doing something wrong but i have no idea what.

Kind regards

Wrong place. That code goes in your configuration.yaml file under switch:. Also your indentation is incorrect. Should be:

switch: 
  - platform: wake_on_lan
    mac_address: "xx:xx:xx:xx:xx:xx"
    name: "Desktop"
    host: "192.168.1.X"
    broadcast_address: "192.168.1.255"

So i now have my configuration.yaml as follows:

wake_on_lan:

switch: 
  - platform: wake_on_lan
    mac_address: "xx:xx:xx:xx:xx:xx"
    name: "Desktop"
    host: "192.168.1.X"
    broadcast_address: "192.168.1.255"

I have rebooted and i get this error:

Invalid config

The following integrations and platforms could not be set up:

  • switch.wake_on_lan

Please check your config.

Should the switch just automatically show up on my home assistant or do i have to add it somewhere…

Many thanks for your help

mac_address: "xx:xx:xx:xx:xx:xx"

Should be:

mac: "xx:xx:xx:xx:xx:xx"

Hi, sorry to bring an old subject back up. I manage to turn my PC on via a switch on HA but the switch does not show if the PC is on or off. As i flick the switch it toggles to on then after a few seconds it toggles back to off (even though the PC is on)

I have the following setup:

in my configutation.yaml

wake_on_lan:

In my switches.yaml

- platform: wake_on_lan
  mac: "xx:xx:xx:xx:xx:xx"
  name: "Desktop"
  host: "192.168.1.40"
  broadcast_address: "255.255.255.255"

How can i get the switch to check if the PC is on or off?

Any help appreciated

I am using the official addon RPC Shutdown, the Samba addon and this line:

- platform: wake_on_lan
  mac: "xx-xx-xx-xx-xx-xx"
  name: "corei7"
  host: 192.168.0.124
  turn_off:
    service: hassio.addon_stdin
    data:
      addon: core_rpc_shutdown
      input: corei7

There is an explanation of all the steps somewhere in the docs.

Thanks for the response. I am not looking to shutdown the PC though, i simply want to get its status to hold on the switch that i have already.

I use a template switch for this:

switch:
  - platform: template
    switches:
      pc:
        friendly_name: PC
        value_template: "{{ is_state('device_tracker.pc', 'home') }}"
        icon_template: mdi:desktop-tower
        turn_on:
          service: wake_on_lan.send_magic_packet
          data:
            mac: !secret computer_mac
            broadcast_address: !secret fritzbox_broadcast
            broadcast_port: 9
        turn_off:
          service: mqtt.publish
          data:
            topic: "iotlink/workgroup/computer/commands/hibernate"
            payload: ""

I use IOTLink for the state for my computer but you could use ping as well.

device_tracker:
  - platform: ping
    hosts:
      pc: 192.168.2.100
1 Like

Many thanks for your reply. I have tried to implement this but i cant get the switch to show up.

In my configuration.yaml i have the following:

switch: !include switches.yaml

And in the switches.yaml i have this:

- platform: mqtt
  name: "Main House - General Heating"
  command_topic: "cmnd/Tasmota_Sonoff_R3_Switch_1/power"
  state_topic: "stat/Tasmota_Sonoff_R3_Switch_1/POWER"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  retain: true
    
- platform: mqtt
  name: "Main House - Hot Water"
  command_topic: "cmnd/Tasmota_Sonoff_R3_Switch_2/power"
  state_topic: "stat/Tasmota_Sonoff_R3_Switch_2/POWER"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  retain: true
    
- platform: mqtt
  name: "Unassigned 1"
  command_topic: "cmnd/Tasmota_Sonoff_R3_Switch_3/power"
  state_topic: "stat/Tasmota_Sonoff_R3_Switch_3/POWER"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  retain: true
  
- platform: mqtt
  name: "Unassigned 2"
  command_topic: "cmnd/Tasmota_Sonoff_R3_Switch_4/power"
  state_topic: "stat/Tasmota_Sonoff_R3_Switch_4/POWER"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  retain: true
    
- platform: mqtt
  name: "Unassigned 3"
  command_topic: "cmnd/Tasmota_Sonoff_R3_Switch_5/power"
  state_topic: "stat/Tasmota_Sonoff_R3_Switch_5/POWER"
  qos: 1
  payload_on: "ON"
  payload_off: "OFF"
  retain: true
  
- platform: template
  switch:
    pc:
      friendly_name: PC
      value_template: '{{ is_state(''device_tracker.pc'', ''home'') }}'
      icon_template: 'mdi:desktop-tower'
      turn_on:
        service: wake_on_lan.send_magic_packet
        data:
            mac: 'xx:xx:xx:xx:xx:xx'
            host: 192.168.1.xx
            broadcast_address: 255.255.255.255
            broadcast_port: 7`

device_tracker:
  - platform: ping
    scan_interval: 60
    hosts:
      pc: 192.168.1.XX

Any suggestions?

It seems your device_tracker is in our switches.yaml file. This would create an indentation issue. Maybe that’ll help?

I cannot make working the status check. The wake on lan integration contains text: " It’s required that the binary ping is in your $PATH ." which si not explained properly. Is this requirement related to the status check by adding the config variable “host”?

1 Like

You have to allow ping response in Windows firewall…
How to Allow Ping in Windows Firewall (Client or Server OS) - Active Directory Pro