Wxam
June 19, 2023, 12:23pm
1
Dear reader,
I’m trying to make a switch that makes my pc up via a WOL, and turns it off via a script.
Both of those work perfectly. Now i’m trying to create 1 switch that stays in an “on” state when my PC is online and when I click it it goes in an “off” state and turns my PC off.
the binary sensor goes in a “connected” state when my PC is online but even changing the ‘on’ to ‘connected’ doesn’t keep the switch in an on state.
This worked since the latest update here is the code I used hope someone can help me out on this one.
switch:
- platform: wake_on_lan
name: abyyswatcher
host:
mac:
- platform: template
switches:
matthew_pc:
value_template: "{{ is_state('binary_sensor.pc_matthew', 'on') }}"
turn_on:
service: switch.turn_on
target:
entity_id: switch.abyyswatcher
turn_off:
service: switch.turn_off
target:
entity_id: switch.abysswatcher_off'
Kind regards,
Wxam
Is the ’ at the end a copy-paste error ?
Also, you say you have a script to turn off your PC, why not just run that for the turn_off
section ?
koying
(Chris B)
June 19, 2023, 12:35pm
3
Not sure what you are trying to achieve, here…
The wake_on_lan
switch platform supports a turn_off
command, and will be on or off depending on a ping on its host
.
That seems to do what you’re looking for, does it not?
E.g.:
- platform: wake_on_lan
name: "URANUS WOL"
mac: "xx:xx:xx:xx:xx:xx"
host: uranus.lan
broadcast_address: 192.168.3.255
turn_off:
service: remote_command_line.uranus_turn_off_command_shell
Wxam
June 19, 2023, 12:42pm
4
the ’ is indeed a copy-paste error.
I could also run the turn off as that yeah, what it does is a curl on my PC that shuts down my PC.
Looking at mine, they are configured as @koying above, so no need for a template switch
Wxam
June 19, 2023, 12:50pm
6
How can I implement the curl into the turn_off for the wake on lan.
switch:
- platform: wake_on_lan
name: abyyswatcher
host: xxx.xxx.xxx.xxx
mac: XX:XX:XX:XX:XX:XX
turn_off:
service:
To turn_off my PC I call a curl (url) but this doesn’t work as a service.
Wxam
June 19, 2023, 1:06pm
8
Thanks! so this should be working?
shell_command:
abysswatcher_off: curl http://xxx.xxx.xxx.xxx:55001/shutdown
switch:
- platform: wake_on_lan
name: abyyswatcher
host: xxx.xxx.xxx.xxx
mac: XX:XX:XX:XX:XX:XX
turn_off:
service: shell_command.abysswatcher_off
koying
(Chris B)
June 19, 2023, 1:13pm
9
Unless your curl is very specific, use a rest command instead, it’s more efficient.
rest_command:
abysswatcher_off:
url: http://xxx.xxx.xxx.xxx:55001/shutdown
[...]
turn_off:
service: rest_command.abysswatcher_off
Wxam
June 19, 2023, 1:23pm
10
Thanks!
The rest_command works as it should. I can now turn my PC on and off with just 1 switch
Thanks so much!
rest_command:
abysswatcher_off:
url: http://xxx.xxx.xxx.xxx:55001/shutdown
switch:
- platform: wake_on_lan
name: abyyswatcher
host: xxx.xxx.xxx.xxx
mac: XX:XX:XX:XX:XX:XX
turn_off:
service: rest_command.abysswatcher_off
Above command is what I use now and this works as it should.
1 Like