Composite Device Handler with ThingShield


(Dan) #1

@bflorian, @rajk


Quick question… I know the ThingShield is no longer supported. However, it still works pretty well for the users who already have them, like myself. I have been working on porting my ST_Anything project over to use the new Composite Device Handlers. This works great with my LAN-to-HUB connected devices. However, I appear to have an issue using the ThingShield in conjunction with the Composite DH.

The ThingShield is able to send updates to ST which are handled properly by my Parent DH’s parse() routine, which in turn updates the child devices. So far, so good…

The issue I have is when I try to use a Child Device (like a Switch) to call a Parent function to send data to ThingShield. The Parent function is called properly by the child device, however the zigbee.smartShield() function appears to do absolutely nothing, as the Arduino never receives any data.

Here is an example that does not work. (Note: I even tried commenting out all of the lines below, and uncommenting the one one line that is commented to determine if the issue was related to passing the string into the call. Still, no joy.)

void childOn(String dni) {
    def name = dni.split("-")[-1]
	log.debug "childOn($dni), name = ${name}"
    zigbee.smartShield(text: "${name} on").format()
    //zigbee.smartShield(text: "switch1 on").format()

And here is another function, in the same Parent DH, that only works if called by Parent Refresh Tile.

def refresh() {
	log.debug "Executing 'refresh()'"
	zigbee.smartShield(text: "refresh").format()

Am I doing something wrong? Or is the zigbee.smartShield() function just not compatible with the new Composite Device Handlers? I am hoping it is something simple that is easily corrected on my end.



(Bob Florian) #2

Hi Dan,

What you need to do is explicitly send the result of the zigbee.smartShield(text: "${name} on").format() call to the hub using sendHubCommand(). Something like this:

void childOn(String dni) {
    def name = dni.split("-")[-1]
    def cmd = zigbee.smartShield(text: "${name} on").format()
    sendHubCommand(new physicalgraph.device.HubAction(cmd))

You don’t need to do that in the case of refresh() being called by the tile because the platform API automatically sends the return value of the method to the hub when that method is called in response to tapping a tile. But when the child device calls a method of it’s parent nothing special happens to the return value because the API is not involved. The result of the method is simply returned to the child.

(Dan) #3


Thank you very much! That was easy and makes perfect sense. I really appreciate the very quick response!