Trying to build a simple Particle Photon Motion Sensor

Hello,

I’m working on my first sensor that I’d like to integrate into SmartThings. I am close, but somewhat challenged by the Device Handler for it.

I’ve taken a Particle Photon and have a motion sensor hooked to it. I have code on that that detects motion. That’s all good. I post the variable for what the current status of motion is into the Particle cloud. That all seems to be working ok.

The problem is how to get the device handler to poll for the data (or somehow register for updates).

I’ve tried a number of things and have gotten “some” data to show up “sometimes”. I’ve Googled, and searched and read various posts, checked out both the current and classic documentation.

I don’t care if there isn’t an app page. I’m just trying to have a simple motion detector… that doesn’t take any user input, etc.

I’ve included the latest Device Handler below. Can anybody give me some pointers to any simple code that does something like this. I’ve found a lot “more complicated” examples and tried to rip them down, but that hasn’t been all that productive. From this “basic” set up, I will be trying to build more complicated sensors, but I thought this would be a “good” simple “hello, world” type exercise. (and I could use the motion sensor as well… I’ve got all the parts to build 2 or 3 of them…

Thanks in advance,

Earl

/**
 *  Earl Particle Motion Sensor
 *
 */
 
metadata {
	definition (name: "Particle Motion Sensor", namespace: "", author: "Earl Baugh") {
        capability "Sensor"  //Best practice to include if it has attributes
		capability "Polling"
		capability "Refresh"

		attribute "motion", "string"

	}

    preferences {
        input("deviceId", "text", title: "Device ID", description: "Particle Device ID", required: false, displayDuringSetup: true)
        input("token", "text", title: "Access Token", description: "Particle User Access Token", required: false, displayDuringSetup: true)
    }
}

// handle commands
def poll() {
	log.debug "Executing 'poll'"
	getValue()
}

def refresh() {
	log.debug "Executing 'refresh'"
	getValue()
}


private getValue(){
	
	httpGet(uri: "https://api.particle.io/v1/devices/${deviceId}/motionStatus?access_token=${token}",
    	contentType: 'application/json')
    {resp ->
            log.debug "resp data: ${resp.data}"
            log.debug "result: ${resp.data.result}"
        state.motion = ${resp.data.result}
		sendEvent(name: "motion", value: "${resp.data.result}")
	}
}