One switch for WoL and PC shutdown

Hi,
so I tried this for a while now and can’t get it working properly:
I want one switch, that if off, triggers wake on lan, if on triggers shutdown through hass agent and also recognizes if the pc is on or off, by a sensor from hass agent.
so i tried something like this:

  - platform: template
    switches:
      strix_toggle:
        value_template: > 
            {% if is_state("sensor.strix_home_lastsystemstatechange", "ApplicationStarted") %}on{% else %}off{% endif %}
        turn_on:
            service: wake_on_lan.send_magic_packet
            data:
              mac: xx:xx:xx:xx:xx:xx
        turn_off:
            service: button.press
            target:
                entity_id: button.strix_home_shutdown

problems:
1: apperantly data: [mac] is missing, but it might be just a formatting error on my side, i can’t figure out

2: the state of “sensor.strix_home_lastsystemstatechange” is either “ApplicationStarted” or “Unavailable” and the switch always resets to it’s “on” state, even when the state check in the developer tools say “Unavailable”

not much more hair left to pull out here :confounded:

You can simplify the value template to be

{{ is_state("sensor.strix_home_lastsystemstatechange", "ApplicationStarted") }}

Try putting quotes around the MAC address. That’s what is shown in documentation.

  - platform: template
    switches:
      strix_toggle:
        value_template: > 
            {{ is_state("sensor.strix_home_lastsystemstatechange", "ApplicationStarted") }}
        turn_on:
            service: wake_on_lan.send_magic_packet
            data:
              mac: "xx:xx:xx:xx:xx:xx"
        turn_off:
            service: button.press
            target:
                entity_id: button.strix_home_shutdown 

WoL does work, now thx

but for the switch, it didn’t help

I also checked multiple times that the value changes properly, but the switch doesn’t refresh afterwards. So I guess, the issue is that the switch only changes state on being activated/deactivated, but doesn’t checking it’s state/value, when untouched. And it makes sense, that the switch would reset itself, when the value doesn’t change when its touched, because bothe actions take some time to be executed.
but how do I make the switch checking it’s value?

value_template: '{% if states("sensor.strix_home_sessionstate")=="Unlocked" %}on{% else %}off{% endif %}' 

that was the line, I needed. found in a german yt-tutorial. now it works properly

now need to find a way to keep the switch from refreshing too early so it looks better