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