Wake on Lan

It was just by luck that I caught this post before it got lost in the weeds. In the future please reply directly to me or "@" me so I can respond. Otherwise I have no way of knowing you were asking me a question.

Wake On Lan is a one way protocol that sends a packet to turn on you pc. It does not know it the computer actually turns on and has no way of sending a shut down command. The virtual switch is designed to act like a momentary button (on for a sec and then back to off). This way it can be reactivated when needed. There are ways to shut your pc down through HE but for many it's too complicated so I designed the app to cover the most likely use case...turning the pc on.

2 Likes

This is a feature of the virtual switch that you have assigned to work with the boot me up scottie child app instance. It can be set to auto-off. See partial screenshot below from one of my switch’s settings page:

@stephack just curious, are you using anything specific for any of your PCs?

I just started using EventGhost recently but I have it configured through HA. Not an intuitive application and I dont believe it is supported by the author anymore...but it works. It's probably harder to setup EG to turn off your pc than it is to write the driver to connect to it :man_shrugging:

Not that it's that hard but like I said...not intuitive. Took me a lot longer than necessary to figure it out.

1 Like

I have thought about eventghost but never pulled the trigger because, as you said, it seems a bit unintuitive to get setup.

I think the simplest way is to connect a PC to harmony (need a Windows media center USB IR receiver) then use @ogiewon's harmony integration to send an off command.

1 Like

Forgot to mention that there is a driver for this already.

This will allow you to shutdown the pc in Eventghost (amongst other things). Getting one device that could shutdown and turn on the pc would be the tricky part.

1 Like

And of course your pc would have to be in range of the IR blaster as well.

1 Like

Yup. I use it for a gaming PC in my living room, where the harmony hub is. Works pretty well, but line of sight for IR is a limitation and going through harmony just isn't ideal from a simplicity standpoint.

I considered expanding my Boot Me Up app to have an option to also send a turn off command (eventghost or otherwise) but there would be know way for the device to monitor on/off states and sync to the virtual device. Well, I'm sure they are ways, but it would get very complicated and require at least 3 different integrations working together. I can't even imagine the documentation needed for that one...lol. Simply don't have the time or motivation (already have this working in HA).

Makes sense. WoL is a great standard to work with for on, but there is no standard for off!

@stephack
awesome app thanks. appearantly WoL was already on in my bios (refurb pc)
i went thru all the steps mentioned using team viewer to access my pc.

its great not having to call home and ask for the roomie to turn on the pc.

just for fun i named the switch on the dashboard "init nuclear trigger" because bad things happen when i get bored........

Just installed this for two of my home computers and it works great with such few lines of code. Thanks a lot!

I also just set this up for my morning work routine. Super easy!

1 Like

Me too, tied it in with opening a roller blind, setting the lights to a specific scene and turning on my monitor (TV).

wol seems to have stopped working from my hub. it just suddenly stopped working other devices like my router can do wol but not my hubitat.

Just tested it and it still works for me. I haven't updated my hub firmware in a while though. What version of HE firmware are you on?

Edit:
Updated my firmware to the latest version and it still worked fine. Verify the MAC address is entered correctly. Also check the logs for any clues.

1 Like

Mac Is correct , debug log says it's send the magic packet. But nothing.

dev:1422021-03-26 11:03:35.243 pm infoBattlestation was turned off

app:1252021-03-26 11:03:33.780 pm debugSending Magic Packet to: 7085C2A4DA67

app:1252021-03-26 11:03:33.778 pm debugBattlestation activated

app:1252021-03-26 11:03:33.768 pm debugSending Magic Packet to: 7085C2A4DA67

app:1252021-03-26 11:03:33.764 pm debugBattlestation activated

app:1252021-03-26 11:03:33.734 pm debugSending Magic Packet to: 7085C2A4DA67

app:1252021-03-26 11:03:33.726 pm debugBattlestation activated

Seems like a network issue of some sort. Anything special on your end? Vlans etc?

2 Likes

I don't have any vlans, I check network settings on my hub they looked correct. I reset my hub network settings got the same information but now it works... Bit weird but thank you for the help.

1 Like

Hi @stephack,
Thanks for the code, your App works perfectly for me!

However, I'm trying to build it into a custom driver, and I really can't figure out what I'm doing wrong. As mentioned, it works flawlessly when I use the Boot Me Up Scottie/Child drivers, but when I copy+paste it into my driver, it doesn't.

I'm new to coding with Hubitat, but the driver code is as follows. There is a bunch of other stuff in there as well, but I guess the important bit is the on() and createWOL() functions. Including the rest in case I'm missing something.

metadata {
    definition (name: "PC Controller", namespace: "manke", author: "Andreas") {
        capability "Switch"
        capability "Momentary"
    }

    preferences {

        input(name:"myMac", type: "text", required: true, title: "MAC of workstation")
        //input "myMac", "text", required: true, title: "MAC of workstation"
        input(name: "EventGhostIP", type: "string", title:"Local IP Address", description: "", required: true, displayDuringSetup: true)
        input(name: "devicePort", type: "string", title:"Event Ghost Server Port", description: "", required: false, displayDuringSetup: true)
        input(name: "offCommand", type: "string", title:"Event Ghost off command", description: "Specify off command for Event Ghost", required: false, displayDuringSetup: true)
        input(name: "testCommand", type: "string", title:"Event Ghost test command", description: "Specify test command for Event Ghost when using push button", required: false, displayDuringSetup: true)
        input(name: "PetName", type: "string", title:"Pet Name", description: "You may assign a pet name", defaultValue: "69", required: false, displayDuringSetup: true)
        //input(name: "devicePath", type: "string", title:"URL Path", description: "Rest of the URL, include forward slash.", displayDuringSetup: true)
        input(name: "EnumFIeld", type: "enum", title: "Choose a value", options: ["This","THoSe","THAT"], defaultValue: "This", required: false, displayDuringSetup: true)
        //input(name: "deviceContent", type: "enum", title: "Content-Type", options: getCtype(), defaultValue: "application/x-www-form-urlencoded", required: true, displayDuringSetup: true)
        //input(name: "deviceBody", type: "string", title:"Body", description: "Body of message", displayDuringSetup: true)
    }
}

def parse(String description) {
    log.debug(description)
}

def getCtype() {
    def cType = []
    cType = ["application/x-www-form-urlencoded","application/json"]
}

def push() {
    //Send Event Ghost test command
    //sendEvent(name: "switch", value: "on", isStateChange: true)
    //runIn(1, toggleOff)
    //sendEvent(name: "switch", value: "off", isStateChange: true)
    sendEventghostCommand(testCommand)
}

def toggleOff() {
    sendEvent(name: "switch", value: "off", isStateChange: true)
}

def on() {
    createWOL()
    sendEvent(name: "switch", value: "on", isStateChange: true)
}

def off() {
    sendEventghostCommand(offCommand)
    sendEvent(name: "switch", value: "off", isStateChange: true)
}

def sendEventghostCommand(String eventGhostCommand) {
    def localDevicePort = (devicePort==null) ? "80" : devicePort
    def path = EventGhostIP + "/?" + eventGhostCommand
    def body = ""
    //if(deviceBody) body = deviceBody
    
    def deviceMethod = "GET"
    def deviceContent = "application/json"
    def headers = [:] 
    headers.put("HOST", "${EventGhostIP}:${localDevicePort}")
    headers.put("Content-Type", deviceContent)

    try {
        def hubAction = new hubitat.device.HubAction(
            method: deviceMethod,
            path: path,
            body: body,
            headers: headers
            )
        log.debug hubAction
        return hubAction
    }
    catch (Exception e) {
        log.debug "sendEventghostCommand hit exception ${e} on ${hubAction}"
    }  
}


//Send Wake on LAN package to PC
def createWOL() {
	def newMac = myMac.replaceAll(":","").replaceAll("-","")
    /*if(logEnable)*/ log.debug "Sending Magic Packet to: $newMac"
    def result = new hubitat.device.HubAction (
       	"wake on lan $newMac",
       	hubitat.device.Protocol.LAN,
       	null
    )    
    return result
}

Debug output for both the device and the app seems identical

[dev:140](http://192.168.0.57/logs#dev140)2021-03-30 09:19:35.113 [debug](http://192.168.0.57/device/edit/140)Sending Magic Packet to: 382C4A6DE77E

[app:262](http://192.168.0.57/logs#app262)2021-03-30 09:05:14.026 [debug](http://192.168.0.57/installedapp/configure/262)Sending Magic Packet to: 382C4A6DE77E

I'm kinda hitting a wall here, I hope you have some tip that can help me move forward.
Thanks for reading, and for the app anyway! I'll use it as a fallback if I cant get this to work :slight_smile: