Power Pin to ground to switch PC power on

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
simon2023
New user
Posts: 4
Joined: 18 Aug 2023, 19:43

Power Pin to ground to switch PC power on

#1 Post by simon2023 » 18 Aug 2023, 19:48

I found a nice project how to switch a pc from remote by hardware switch via ESP8266.
I think it should be quite simple. A connection is made by a transistor. So I have to power the transistor to make it connect two cables.

In the project, the trigger is activated via home-assistant. I want to be able to trigger it an easier way, p.ex. by logging in to espeasy and trigger it. How do I manage this? Should be quite simple, I just have no idea.

User avatar
Ath
Normal user
Posts: 3519
Joined: 10 Jun 2018, 12:06
Location: NL

Re: Power Pin to ground to switch PC power on

#2 Post by Ath » 18 Aug 2023, 20:56

Via Home Assistant you can send an MQTT command to the ESPEasy unit that has a HA Controller configured and enabled, to send a gpio,<pin>,<state> command to set the pin to state 0 or 1 to switch your PC. Probably it should only use a pulse (longpulse_ms,<pin>,<state<,<duration>) ,of several hundreds of milliseconds to switch the PC on, that should be enough. 'Pressing' it again will, by default put it in sleep mode, and pressing it long (> 6 seconds) will forcefully switch it off.
/Ton (PayPal.me)

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Power Pin to ground to switch PC power on

#3 Post by TD-er » 19 Aug 2023, 02:25

Maybe better to use WakeOnLan.
When trying to turn on the PC via a transistor, you must be quite sure this switch isn't toggled by accident or else your PC may turn off when you don't want to.

Also you must make sure there isn't a (large or fixed) potential difference between the ESP and the GND pin (or the other power pin on the main board) or else you may fry your main board

simon2023
New user
Posts: 4
Joined: 18 Aug 2023, 19:43

Re: Power Pin to ground to switch PC power on

#4 Post by simon2023 » 19 Aug 2023, 10:51

Ath wrote: 18 Aug 2023, 20:56 Via Home Assistant ....
As I said, I want to do it without Homeassistant, but thanks.
TD-er wrote: 19 Aug 2023, 02:25 Maybe better to use WakeOnLan.
I do not want to use WakeOnLan because I want to be able to remotely start my server when it freezes. WakeOnLan does not work then.

It should be rather easy for someone who knows ESP easy.

The important part is this here:

Code: Select all

switch:
  - platform: gpio
    name: "PC Power Toggle"
    icon: "mdi:electric-switch"
    pin: D2   # Power button output pin
    id: power_short_press
    inverted: no
    on_turn_on:
    - delay: 150ms
    - switch.turn_off: power_short_press
Is there a chance to program this manually into espeasy or esphome. So I flash it, but in my wifi credentials and then somehow program this part?

TD-er
Core team member
Posts: 8756
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Power Pin to ground to switch PC power on

#5 Post by TD-er » 19 Aug 2023, 11:08

Sure, you can simply add some rules block and then you only need to trigger an event in ESPEasy to perform this action.

Something like this:

Code: Select all

On pcpower Do 
  LogEntry,'Send pulse to power button PC'
  LongPulse_ms,4,1,150 // Activate GPIO-4, active high, for 150 milli seconds
Endon
See: https://espeasy.readthedocs.io/en/lates ... ernal-gpio

So whenever you trigger the event "pcpower", it will send a pulse of 150 msec to that pin.

Code: Select all

event,pcpower
I strongly advice you to check this table: https://espeasy.readthedocs.io/en/lates ... on-esp8266
GPIO-4 is perhaps the best pin for this as it will not toggle during boot of the ESP.
However, in ESPEasy it is set as default for one of the I2C pins, so you may need to remove that assignment on the Hardware tab.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 25 guests