Starting point hubAction

Hi there,
i’m brand new to ST and trying to build a test device handler, that will just ask an HTTP web site. for now i’m not even able to get the hubaction to execute. and show anything in the log.
is there anything missing/or I need activated to see something coming to the parse, or ensure hubaction iis executed ?

etadata {

definition (name: "Test HTTP Site", namespace: "Salim", author: "Salim") {
		capability "Image Capture"
		command "doSomething"

preferences {
section(“When the following is turned on and off…”) {
input name: “master”, title: “Which Switch?”, type: “capability.switch”, required: true

def doSomething() {
def ip = “"
log.debug “doSomething executed"
sendHubCommand(new physicalgraph.device.HubAction(””“GET /test.htm HTTP/1.1\r\nHOST: $ip\r\n\r\n”"", physicalgraph.device.Protocol.LAN))

def parse(String description) {
log.debug “Parsing ‘${description}’”

Parse is called when a real device is communicating something, that will not happen. You need to invoke doSomething from on or off or something similar. The best way to have control is to specify a callback handler on the sendhubcommand.

tried it, the thing is I don’t get any single packet flowing from the hub to the web server. can you share an absolutely basic request to get a response from a web server ?

this webserver is in your local network, right?

rooPath = "/json.htm?type=command&param=setcolbrightnessvalue&idx=${addr}&hex=${level}&iswhite=true&brightness=${xBri}&saturation=${xSat}" // "SetColBrightnessValue"

hubAction = new physicalgraph.device.HubAction(method: “GET”, path: rooPath, headers: [HOST: “${settings.domoticzIpAddress}:${settings.domoticzTcpPort}”], null, [callback: onLocation] )


This used in a smartapp, but should be comparable.

yep, on the same physical switch.
I tried this:
metadata {
definition(name: “My Camera Device”, namespace: “MyNamespace”, author: “My Name”) {
capability “Image Capture”
// other definition metadata…
command “test”

def test(){
def rooPath = “/auto.jpg” // "SetColBrightnessValue"
def ip = ""
def port = "80"
def hubAction = new physicalgraph.device.HubAction(method: “GET”, path: rooPath, headers: [HOST: “${ip}:${port}”], null, [callback: onLocation] )

log.debug “got there”

log.debug “and there”

private onLocation(){
log.debug “here”

and still can’t see any ppacket flowing from the hub, getting to my web server.
is there any basic ting i’m missing? like enabling dev. mode or something similar ?

At the end of your sendHubCommand you are missing one final important parameter, the IP and Port in Hex. So after …LAN, HexIP:HexPort))

At least that worked for me a long time ago. Thus is the old post that helped me:

Edit: search the community for the Java toHexString method that can help you convert the IP. Here is an example from one SmartApp. Remember both IP and Port need to be in Hex.

private String convertIPToHex(ipAddress) {
return Long.toHexString(convertIntToLong(ipAddress));

tested as well by adding the ipaddress in hex, but seems nothing can get out of this hub. the weird thing is that I tried through Internet (after publishing the server on the web), by using httpget. and everything works perfectly.

you have defined onLocation as private…could you remove the private? onLocation will not be avail as an external ref.

Thanks mate,
changed it. but didn’t get anything.
for now I just want to see hubaction send a GET command. and see it reaching my web server.

httpget works perfectly, if I point it to my public IP.

also for info i’m using ST V2 with firmware version 000.017.00014 just in case this makes any sense :slight_smile:

You need to set the dni in hex to be either Mac address or ip:port.

can you share a small working example as basic as possible. I just need it to send this GET on the LAN.

No. Setting the dni is done when setting up the device. It’s in the device settings in ide. I believe setting dni via code is currently broken.

Typically devices are created via a smartapp that sets this stuff up programmatically.

Lots of examples in the St public GitHub repo

oh no, never noticed that setting DNI programatically is broken. i’ll have a look at it later today.


seems i’m completely lost. i’m gonna abandon this thing is turning me crazy :@

Will do some test when at home in a device handler…

met vriendelijke groeten,


Op 30 jun. 2017 13:28 schreef “Salim Mekliche” <>:

worked in one go…in this case the IP is not a hex IP adress but normal…

def callbackList(evt) { evt

// handle commands
def test() { parent.settings.domoticzIpAddress
    def hubAction = new physicalgraph.device.HubAction(
        method: "GET",
        path: "/json.htm?type=devices&filter=all&used=true&order=Name",
        headers: [HOST: "${parent.settings.domoticzIpAddress}:${parent.settings.domoticzTcpPort}"],
        [callback: callbackList] )



is this implemented in device handler or through smartapp ?

Device handler.

met vriendelijke groeten,


Op 1 jul. 2017 12:17 schreef “Salim Mekliche” <

You can still set the DNI in code, however it takes a little work if you’re trying to do so from within the “updated()” routine in a Device Handler. Here is my workaround for setting the DNI. I have to schedule the DNI to be updated using the “runIn” command. Must be either a race condition or a calling context issue.

Note, the “updated()” routine gets called twice every time you save the settings of the device, thus there is a workaround for that as well to prevent it running if it already ran within the last 5 seconds.

Note: “mac” is set as a “preference” as follows:

	preferences {
		input "ip", "text", title: "Arduino IP Address", description: "IP Address in form", required: true, displayDuringSetup: true
		input "port", "text", title: "Arduino Port", description: "port in form of 8090", required: true, displayDuringSetup: true
		input "mac", "text", title: "Arduino MAC Addr", description: "MAC Address in form of 02A1B2C3D4E5", required: true, displayDuringSetup: true 

def updated() {
	if (!state.updatedLastRanAt || now() >= state.updatedLastRanAt + 5000) {
		state.updatedLastRanAt = now()
		log.debug "Executing 'updated()'"
    	runIn(3, "updateDeviceNetworkID")
		sendEvent(name: "numberOfButtons", value: numButtons)
	else {
//		log.trace "updated(): Ran within last 5 seconds so aborting."

def updateDeviceNetworkID() {
	log.debug "Executing 'updateDeviceNetworkID'"
    if(device.deviceNetworkId!=mac) {
    	log.debug "setting deviceNetworkID = ${mac}"
    //Need deviceNetworkID updated BEFORE we can create Child Devices
	//Have the Arduino send an updated value for every device attached.  This will auto-created child devices!

To see my full Device Handler example for communicating with an Arduino via the hub, see below. Please note that I am not communicating with a standard web server, but rather a custom app running on an Arduino.