Can a device type do a hub action?


(Linda Thomas-Fowler) #1

I’ve run into a bit of a snag trying to send a command from ST into my mac server.

I’m getting the following error:

    926255bc-d2e9-473e-bac8-22c8f8df55ae 8:55:47 PM EST: error groovy.lang.MissingMethodException: No signature of method: script14156709476291769450883.sendHubCommand() is applicable for argument types: (physicalgraph.device.HubAction, java.lang.String) values: [GET /toggleChime HTTP/1.1 
Accept: */* 
User-Agent: Linux UPnP/1.0 SmartThings 
HOST: 192.168.1.16:9876 

, ...] @ line 82

I’m doing the following in the device:

def action = new physicalgraph.device.HubAction([
	method: "GET",
	path: "/toggleChime",
	headers: [
		HOST: "192.168.1.16:9876"
	]
])
sendHubCommand(action,"192.168.1.16:9876")

I’m wondering if a device is allowed to do a hub command or have I just misinterpreted sample code and gone into the weeds?


(Geko) #2

Device can request hub action by simply returning HubAction object, but cannot call sendHubCommand. See for example https://github.com/statusbits/radiothermostat


(Linda Thomas-Fowler) #3

Got it! I see that all I need to do is return the HubAction return value and it will get executed. Thanks, again!


(www.rboyapps.com - Make your home your butler!) #4

Kinda old thread but I’m struggling with this a little, I understand that hubAction is executed from the command handler as long as the hub action is returned.

Works great so far, now comes the kicker. I need to constantly poll the device every x seconds to get it’s current status and update the device tiles/notify smart apps etc.

So I setup a scheduler to call a polling function that uses hubAction to connect to the device via a REST call. hubAction never executes! the same hubAction function when called from a command function works, when called from a scheduled function it never executes.

How does one call hubAction from a scheduled function in a device? ie. how do I poll my device?


(John S) #5

One would set up a command in the device that returns the hubAction, expose that command in the metadata section to a SmartApp, write a SmartApp that works with the device capability this device supports, and which calls said command via a schedule.


(www.rboyapps.com - Make your home your butler!) #6

thanks I thought about that but it’ a bit hacky - so no direct way within the device code itself?


(John S) #7

[quote=“RBoy, post:6, topic:6816”]
so no direct way within the device code itself?
[/quote]I’d think if there was, they’d have used it for the Hue integration (which uses local hubactions)

Actually, you could pretty much do what they do For Hue bulbs - a SmartApp that creates Devices that represent stuff only visible via a hubAction…