The purpose of this automation is to ensure that my PC turns on. I use a Switchbot bot that presses on the PC power button every weekday at 8:45 am. However, sometimes the PC won’t turn on, so it takes a few more tries to get it to turn on.
I attempted to make this automation, but I think something is missing or it’s wrong? It didn’t fire correctly when it was time for it.
alias: Turn PC on
description: ''
trigger:
- platform: time
at: '08:44:00'
condition:
- condition: time
before: '08:46:00'
weekday:
- mon
- tue
- wed
- thu
- fri
after: '08:44:00'
- condition: and
conditions:
- condition: not
conditions:
- type: is_plugged_in
condition: device
device_id: 24b369d0bced7aa81e0ffd4a282977e2
entity_id: binary_sensor.desktop_93js9fs_power_status
domain: binary_sensor
for:
hours: 0
minutes: 0
seconds: 40
action:
- type: turn_on
device_id: 1708007650dbf521391a1821daf32932
entity_id: switch.pc_turner
domain: switch
mode: single
I added the 40 seconds in the end so that it can retry within a reasonable time, instead of spamming the turn on command, if the PC status is not plugged in.
I’m using IoTLink and MQTT Broker for establishing connections between HA and my PC.
This automation will only trigger once at exactly 0844 hours, there is no retry or repeat in the automation.
As there is only one trigger of 0844 hours there is no need to have before and after times here as it will always be true based on the initial time trigger, so this can be simplified somewhat by:
However as mentioned, there is no repeat action here so this will trigger once only at exactly 0844 hours.
If you want to have the automation repeat the action until a certain state is true, in this case the power_status of plugged in, then you need to use a repeat until, something like this
This will trigger once at exactly 0844 hours and action only if day is a weekday and will switch on the plug every 40 sec’s until the state of your binary sensor is on.
Its generally better practice to use states rather than devices, so you could set the condition to simply be:
- repeat:
until:
- condition: state
entity_id: binary_sensor.desktop_93js9fs_power_status
state: 'on'
I’m just wondering…doesn’t the PC support WakeOnLan??
Most PC’s do, and it would make things a lot easier… no additional hardware needed, only a magic WOL package to the MAC address…
no…wake on lan is for PC’s that are shutdown.
So unless the power is out, it will wake up.
(so the network’s led should show an orange light when in shutdown)
(at least the 1000+ pc’s at my customers work like that)
You might need to enable Wake on LAN in the BIOS first.
Also your conditions might prevent the automation from reaching the action part:
trigger:
- platform: time
at: '08:44:00'
condition:
- condition: time
before: '08:46:00'
after: '08:44:00'
So when it triggers at 08:44:00 for a whole second long the condition „after 08:44:00“ will not be met. (Only at 08:44:01 „after“ 08:44:00 will be true)
i concur…it needs to be enabled in the BIOS.
There are several tools available to generate the magic WOL package. F.e. you can use WOLcmd from Windows machines.
Powered-down or turned off computers capable of Wake-on-LAN will contain network devices able to “listen” to incoming packets in low-power mode while the system is powered down. If a magic packet is received that is directed to the device’s MAC address, the NIC signals the computer’s power supply or motherboard to initiate system wake-up, in the same way that pressing the power button would do.
But not all PC’s support WOL. Mine does, my son’s does not. Spent hours in the BIOS and in Windows, never got it to work. In the end, I bought this little gadget: