Is there a way to switch PC ON Wake On LAN using Smarthub?

@mannyfresh2500, did you ever get this working?

Last night I tried to create another WOL handler for another pc using my Boot Me Up app and it failed as well. To test further, I removed and readded my previously working instance for my original pc and it also failed to work…huh?

While trying to fix, I am seeing a lot of inconsistencies with how the app was subscribing to the switch events and it would work at one moment and not work after changing an insignificant piece of text in the code. Really strange behavior. Especially the inconsistent logging.

In any event, I completely deleted the old app from my IDE and rewrote it and instead passing the “return result” from another method and it appears to work. I no longer try to figure out why things work the way they do with ST anymore. As soon as my Hubitat adds this WOL feature I plan to port this over and rely on ST for one less thing. See code below and I hope you have better luck with it. DON"T FORGET TO COMPLETELY REMOVE THE OLD APP. DO NOT TRY TO REPLACE THE CODE IN PLACE.

definition(
    name: "Boot Me Up Scottie",
    namespace: "stephack",
    author: "Stephan Hackett",
    description: "Activate WOL Magic Packet",
    category: "Convenience",
    iconUrl: "https://raw.githubusercontent.com/stephack/Virtual/master/resources/images/power.png",
    iconX2Url: "https://raw.githubusercontent.com/stephack/Virtual/master/resources/images/power.png",
    iconX3Url: "https://raw.githubusercontent.com/stephack/Virtual/master/resources/images/power.png")

preferences {    
    section("Choose Switch") {
    	input "myDevice", "capability.switch", required: true, title: "Choose a Switch"
        input "myMac", "text", required: true, title: "MAC of workstation"
    }
}

def installed() {
	log.debug "Installed with settings: ${settings}"
	initialize()
}

def updated() {
	log.debug "Updated with settings: ${settings}"
	unsubscribe()
	initialize()
}

def initialize() {
	subscribe(myDevice, "switch.on", myHandler)
}

def myHandler(evt) {
	log.info "${myDevice} activated"
    sendHubCommand(createWOL())
}

def createWOL(evt) {
    log.debug "Sending Magic Packet to: $myMac"
    def result = new physicalgraph.device.HubAction (
       	"wake on lan $myMac",
       	physicalgraph.device.Protocol.LAN,
       	null
    )    
    return result
}
1 Like