How Can I Put Computer to sleep and Wake Computer with SmartThings

What can I buy, or what can I use to wake my computer with SmartThings? Then what can I use to put it back to sleep?

In a perfect world I think it would be great to have a “things” interface that can also tell if my computer is on or off. So that I can change its state by pressing it!

1 Like

Although I don’t have a hub yet (lurking until I find the blockbuster thing that gets wife approval), this is easy if thr hub has the functionality. Almost all network cards have Wake On LAN (WOL) capability. It is a “magic packet” (that’s actually what it’s called) that can wake up a computer if the NIC is set with that option. I don’t think the hub has the ability to send them.

However, I think you should add it as a feature request. It’s a great function to add that is useful and goes along with the green side of the equation here. :slight_smile:

WOL is great, I use it with Tasker on Android to wake my computer. However, you cannot tell if the computer is on or not with a magic packet, or worse, cannot turn it off with the same “app.”

I hope there is a solution like a lock in SmartThings. “Unlocked” = Computer On , “Locked” = Computer Off , and tapping the icon toggles it.

Thank you though for the thought. Maybe there is more to magic packets that I don’t know about that could answer the above?

I only know of the wake feature in WOL. I don’t think there are any other features within that protocol. I think it is just wake…hence the name. :slight_smile:

For status like you are looking for, there would need to be a client app installed that communicates status back to the Hub. That same, in theory app could also shutdown the system if it had rights to do so.

So, someone needs to create a ST client for PC and Mac, enable it to communicate with the Hub, and create a SmartApp to control it.

Of course, if someone is going to create an app, I can see all sorts of other uses for the app, such as controlling an audio app, such as iTunes, to stream music to AirPlay devices, etc.

I can see adding WOL to the hub, and also a PC client app. I’d also like to to work as a motion sensor, if I’m using the PC I’d like the lights to stay on even if I don;t move much.

1 Like

If you wanted to get a relay switch, you could connect it to the power button on your PC and have ST give it a Normally Open momentary connection to simulate a button push. On most PCs the power button connects to a jumper-style connector, so connecting the relay would be pretty easy.

You’d need to power the relay externally, instead of from inside the PC.

Also, if you are using windows, you can configure what a power button press does in your Power Management settings in the control panel.

1 Like

Just found this and thought I’d add what I just did for my server today.

I bought one of the Aeon Labs smart energy switches which handles up to 1800 watts of power. My server is connected to a UPS (which is plugged into the PC via USB and monitored via the UPS monitoring software). The UPS is plugged into the Aeon switch which is plugged into the wall.

When I want to turn off the server or turn it on I simply toggle the Aeon switch via smart things. I do this manually now but I could certainly set it up via various rules such as schedule, power consumption, home/away, etc.

I set the BIOS to start the computer on power restore.

I set the UPS configuration to shut down the PC after 1 minute of no power.

Shutdown event:
So when I turn OFF the switch the UPS monitoring software will execute a “graceful” shutdown of the server after 1 minute. After about another 2 minutes the UPS itself shuts down.

Turn on:
When I turn the switch ON the UPS starts and then power is restored to the server which powers up and I am back in business.

So far this has worked very well and allows me to reduce power consumption in the home by quite a bit since my server and drive arrays consume about 1000 watts of power. I can turn the server off when I’m not watching shows via plex or any other reason. Generally I turn it off at night.

This should work with any UPS from Cyberpower or APC.

I highly recommend the Aeon Smart Energy Switch as well. It lets me see power consumption as well as remotely turn on and off. Keep in mind that you should use a UPS with monitoring capability for this so that you can be sure you are getting a graceful shutdown to avoid loss of data or data corruption.

Hi, this thread got bumped so it caught my attention for the first time.

Basically, I’m using WOL to turn it on and a custom windows service to shutdown. The WOL is actually done with the help of my router. I couldn t figure out how to send the magic packet from the smartthings hub, so instead smartthings makes a request from the internet to my desktop through the port forwarding on the router. The router will send if a request is made to it and the desktop doesnt respond to the routers ping. This works on ASUS Merlin, but I think it might work on any router running some variant of dd-wrt.

after replacing MAC with your desktop mac address, and TARGET with your desktop’s IP address, add the script to your jffs directory and call it from your routers start up script

#!/bin/sh

INTERVAL=5
NUMP=1
OLD=""
TARGET=192.168.0.128 
IFACE=br0
MAC=FF:FF:FF:FF:FF:FF
WOL=/usr/bin/ether-wake
LOGFILE="/var/log/ether-wake.log"

while sleep $INTERVAL;do
NEW=`dmesg | awk '/ACCEPT/ && /DST='"$TARGET"'/ {print }' | tail -1`
SRC=`echo $NEW | awk -F'[=| ]' '{print $8}'`
DPORT=`echo $NEW | awk -F'[=| ]' '{print $27}'`
PROTO=`echo $NEW | awk -F'[=| ]' '{print $23}'`

if [ "$NEW" != "" -a "$NEW" != "$OLD" ]; then
if ! ping -qc $NUMP $TARGET >/dev/null; then
# echo "NOWAKE $TARGET was accessed by $SRC, port $DPORT, protocol $PROTO and is already alive at" `date`>> $LOGFILE
# else
echo "WAKE $TARGET requested by $SRC, port $DPORT, protocol $PROTO at" `date`>> $LOGFILE
$WOL -i $IFACE $MAC
sleep 5
fi
OLD=$NEW
fi
done

If you need help with the windows service that accepts the shutdown request I can give you my C#/dotnet code. And lastly, the device type that Im using for smartthings is as follows. Go easy on me since I threw it together just for my purposes and might have some hard coded paths. Also it was a learning exercise for me with groovy

/**
 *  Desktop
 *
 *  Copyright 2015 Herbert Carroll
 *
 */
 preferences {
    input("confIpAddr", "string", title:"IP Address of the desktop",
        defaultValue: "192.168.0.195", required:true, displayDuringSetup: true)
    input("dnsName", "string", title:"Public DNS name or IP",
        defaultValue: "192.168.0.195", required:true, displayDuringSetup: true)
    input("confTcpPort", "number", title:"TCP Port the shutdown service is running on",
        defaultValue:"9080", required:true, displayDuringSetup:true)
}
 
metadata {
	definition (name: "Desktop", namespace: "herbcarroll", author: "Herbert Carroll") {
		capability "Polling"
        capability "Refresh"
		capability "Switch"
	}

	simulator {
		// TODO: define status and reply messages here
	}

	tiles {
		
       standardTile("mainTile", "device.switch") {
	        
            state "off", label: 'Off', action:"polling.poll", icon: "st.Electronics.electronics18", backgroundColor: "#ffffff"
			state "on", label: 'On', action:"polling.poll", icon: "st.Electronics.electronics18", backgroundColor: "#ffa81e"

		}
            
        standardTile("switchOn", "device.switch", inactiveLabel: false, decoration: "flat") {
	        
            state "off", label: '', action: "switch.on", icon: "st.sonos.play-btn", backgroundColor: "#ffffff"
			state "on", label: '', action: "switch.on", icon: "st.sonos.play-btn", backgroundColor: "#79b821"

		}
        
        standardTile("switchOff", "device.switch", inactiveLabel: false, decoration: "flat") {
	        
            state "off", label: '', action: "switch.off", icon: "st.sonos.stop-btn", backgroundColor: "#ffffff"
			state "on", label: '', action: "switch.off", icon: "st.sonos.stop-btn", backgroundColor: "#79b821"

		}
        
		standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
			state "default", action:"polling.poll", icon:"st.secondary.refresh"
		}
		

        main ("mainTile");
        details(["switchOn", "switchOff", "mainTile", "refresh"]);
	}
	
}


// parse events into attributes
def parse(String description) {
	log.debug "Parsing '${description}'"
	
    def map = [:]
    def retResult = []
    def descMap = parseDescriptionAsMap(description)

    def body = new String(descMap["body"].decodeBase64());
    log.debug body;
    
    if  ( body.startsWith("ping"))
    	sendEvent(name: "switch", value: "on");
}

def parseDescriptionAsMap(description) {
	description.split(",").inject([:]) { map, param ->
		def nameAndValue = param.split(":")
		map += [(nameAndValue[0].trim()):nameAndValue[1].trim()]
	}
}

def on() {
	log.debug "Executing 'on'"
	
    sendEvent(name: "switch", value: "on")
    
    sendWOL();
}

def off() {
	log.debug "Executing 'off'"
	
    sendEvent(name: "switch", value: "off");
   
    return apiGet("/smartshutdown");
}

def poll() {
	log.debug "Executing 'poll'"
	sendEvent(name: "switch", value: "off");
    
    return apiGet("/ping");
    
}

def sendWOL(evt)
{
	log.debug "wake via router!";

	def params = [
    	uri: "http://${dnsName}:${confTcpPort}/ping"
	]

	try {
    	httpGet(params) { resp ->
        	
            log.debug("looks like the box is already up!");
        	log.debug( "response : ${resp}");
    	}
        return;
        
	} 
    catch (e){
    	log.debug("sent a WOL!");
    	log.debug("Its expected something went wrong: $e");
	}
}

private apiGet(String path) {
    TRACE("apiGet(${path})")
    
    setNetworkId(confIpAddr, confTcpPort);
    

    def headers = [
        HOST:       "${confIpAddr}:${confTcpPort}",
        Accept:     "*/*"
    ]

    def httpRequest = [
        method:     'GET',
        path:       path,
        headers:    headers
    ]

    return new physicalgraph.device.HubAction(httpRequest)
}

private def TRACE(message) {
    log.debug message
}

private String setNetworkId(ipaddr, port) { 
    TRACE("setNetworkId(${ipaddr}, ${port})")

    def hexIp = ipaddr.tokenize('.').collect {
        String.format('%02X', it.toInteger())
    }.join()

    def hexPort = String.format('%04X', port.toInteger())
    device.deviceNetworkId = "${hexIp}:${hexPort}"
    log.debug "device.deviceNetworkId = ${device.deviceNetworkId}"
}

The best part of this is I am able to have my HTPC automatically turn on amongst other things as I open the door to my media room

1 Like

Hello,

how do i take the code and put it in the smartapps?

This should help:

A friend of mine is writing a Windows service for the shutdown part for me, and I already use a Raspberry Pi with a WoL website integrated into it.

I have yet to find a good way to link current PC status into SmartThings, or provide live feedback so that I can add a PC Status button to my dashboard.

Have you done anything with that at all?

I can’t program to save my life, sadly, so all I can do is ask others if they can bring my ideas to life.

Edit: Here is the WoL server for Pi that I am using… http://www.jeremyblum.com/2013/07/14/rpi-wol-server/

If it is still of any interest to anyone I achieved it this way :

One arduino + Ethernet Shield programmed to send on/off signal on digital port connected to the power button port of the PC which is configured to put computer sleep or wake it up once pressed.

Http request from smarthings to the Arduino + Ethernet shield config.

And Aeon Power Switch which sends power status : if power status is higher than 20 watts it means the computer is awake.

And that’s it.

1 Like