Each press of Button (in dashboard) to alternately call on/off entity

With a light switch it’s possible to toggle, on off on off with each press. But for more complicated functions like turning on/off a computer via Wake on Lan there are two separate identities.

Is it possible to have a button that with each press alternately calls one, then another entity. There doesn’t need to be conditions to this. Simply one press calls on, the next press calls off, the next press calls on.

It feels like something that should be very simple but may be complicated in practice since I haven’t found any other thread on this.

Thanks!

That is exactly what the toggle helper does.

1 Like

Hi welcome to the community…

Or you can set up a wol switch via configuration.YAML

switch:
  - platform: wake_on_lan
    mac: 74:d4:35:xx:xx:xx
    name: esxi
    host: 10.0.0.130
    turn_off:
      service: shell_command.turn_off_esxi
  - platform: wake_on_lan
    mac: D8:BB:C1:xx:xx:xx
    name: ryzen
    host: 10.0.0.69
    turn_off:
      service: shell_command.turn_off_ryzen

Switch on will send a WOL
Switching off with run a shell command of your choice

1 Like

Thank you very much for providing the above code I will attempt this immediately.

Regards to the post above, I found this link which appears to correspond to your suggestion.

But there is no explanation on how it’s actually set up, I guess if you already know what to do it would remind you, but it’s very much lacking otherwise unfortunately.

I’ve just checked, I actually have a separete switch to turn it off from a separate tutorial to turning it on.

I don’t know how to use a shell command to call a switch, I’m pretty useless at this right now, I just started on Friday with it all.

As you gain experience you’ll soon find that the helpers are a God send and much needed for solving more difficult problems :wink:

Good luck and don’t forget to share the love :heart: and mark threads you’ve created with a solution, this’ll help others like you in the future

1 Like

That’s cool, just remove the lines

    turn_off:
      service: shell_command.turn_off_esxi

That will leave you with a WOL button but you won’t be able to shutdown the machine unless you use some sort of service / shell command etc

At least you’ll be able to test the WOL functionality in the meantime
One thing about this WOL switch is that if the machine is already up it’ll detect it so the button registers as on

GL

1 Like

Thanks very much. I figured out how to do it via the Toggle Helper Switch.

  1. I set up an Entity via the Toggle Helper that can be “on” or “off”.
  2. Set up an automation that detects the change of state of the above entity.
  3. Used an advanced option “Building Block” to choose between two “options”.
  4. Option 1 the entity state is confirmed “on” and this will trigger WOL.
  5. Option 2 the entity state is confirmed “off” and this will call HASS.Agent device and turn it off.

I have no idea if this is a good way to do it or not but it works lol.

1 Like

To me it’s a perfectly acceptable way to do it. Yes you can do it in all the other ways described but if you are not used to yaml, your way will be easy to understand and create.

1 Like