Trying to build a template switch for my pc, but can I do it smarter?

With the ‘on’ function from WOL and the ‘off’ function from rpc shutdown I can build a switch for my PC.

So I have a switch for the ‘turn_on’ function and I can call the rpc shutdown from the template switch. Finally I’ve made a binary_sensor for showing the state of the switch.

binary_sensor:
  - platform: ping
    name: kennethspc
    host: !secret kennethspcip
    scan_interval: 15
switch:
  - platform: wake_on_lan
    name: 'Turn on Kenneths PC'  
    mac: !secret kennethspc
    host: !secret kennethspcip
  - platform: template
    switches:
      kenneths_pc:
        friendly_name: "Kenneths PC"
        value_template: "{{ is_state('binary_sensor.kennethspc', 'on') }}"
        icon_template:  mdi:desktop-classic
        turn_on:
          service: switch.turn_on
          data:
            entity_id: switch.turn_on_kenneths_pc
        turn_off:
          service: hassio.addon_stdin
          data:
            addon: core_rpc_shutdown
            input: KennethsPC

This seems to work nicely, but is it possible to have the wake_on_lan switch inside the template switch so I could skip that one as a seperate switch?

I think you can omit the template switch and use the turn_off action from the wake_on_lan switch?

Oh, yes, I can see that would be a possibility, but then I don’t have a switch state, would I?

Hey, I just tested it, it does give a state, so I guess I could make it work…

From the docs,

It’s required that the binary ping is in your $PATH .

so i think the device is pinged for the state.