Particle + SmartThings app (new)

Hi all!

Are you able to control Particle (Photon) via SmartThings app (new)? I have modified DH that works pretty well in Classic app. In new app it shows as disconnected contact sensor.

DH is included. Any help appreciated.

    /*
 *  GarageControl edited by Davor
 *
 *  Copyright 2018 by Jared Shearer
 *
 *  This SmartThings device handler integrates a Particle (Photon in my case) with a Relay Shield with SmartThings
 *	to open and monitor the state of garage doors.
 *
 *  A WebCoRE piston calls the refresh() function to update the door statuses in SmartThings when a state change 
 *  is published from the Particle Sketch.
*/


  
// user input preferences  
  preferences {
    input name: "deviceId", type: "text", title: "Device ID", required: true
    input name: "token", type: "password", title: "Access Token", required: true
    input name: "contactVar", type: "text", title: "Contact Variable Name", required: true, defaultValue: "GarageStatus"
}

// name the capabilities app author etc
 metadata {
	definition (name: "Status garaznih vrata", namespace: "Davor", author: "dibriks") {      
        // capability "actuator"
        capability "contact sensor"
        capability "Switch"
        capability "Polling"
        capability "Sensor"
        capability "Refresh"
        
        attribute "Status", "string"  // Defines a container to hold the state of your garage door
     
        command "garageRelay"  // Defines a command to trigger the garage door we want opened
         }

// make the tiles for the device handler		
	tiles {
		standardTile("contact", "device.contact", width: 2, height: 2) {
			state "Open",   label: '${name}', action: "garageRelay", icon: "st.Transportation.transportation12",   backgroundColor: "#44b621"
			state "Closed", label: '${name}', action: "garageRelay",icon: "st.Transportation.transportation14", backgroundColor: "#bc2323	"
			state "In motion", label: '${name}', action: "garageRelay", icon: "st.Transportation.transportation13", backgroundColor: "##e86d13"
            state "Ventilation", label: '${name}', action: "garageRelay",icon: "st.Weather.weather10", backgroundColor: "#153591"
		}
        standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 1, height: 1) {
            state "", action:"refresh.refresh", icon:"st.secondary.refresh"
        }
		
		main(["contact"])										
		details(["contact", "refresh"])						
	}
    
    
}
// Refresh value

def refresh() {
    log.debug "Executing 'refresh'"
//execute get value command on refresh
    getvalue() 
}
// Get value of contact sensor variable from particle
private getvalue() {
    def closure = { response ->
        log.debug "Contact request was successful, $response.data"
        // This is the line that sends the contact sensors response value of either open or closed to the contact sensor
        sendEvent(name: "contact", value: response.data.result)
        }
// part that gets sent to particle to get the value of the variable
    httpGet("https://api.particle.io/v1/devices/${deviceId}/${contactVar}?access_token=${token}", closure)
}

def contact() {  // This is what happens when tile contact is pushed.
	log.debug "Executing 'garage1'"
	put 'open'  // Calls put(garageRelay) and sends it a "pokreni_otvaranje" which tells the Particle sketch to run GarageRelay with command == open
}


/////////////////////////////////////////////////////////////
def garageRelay() {  // This is what happens when tile g1Status is pushed.
	log.debug "Executing 'garage1'"
	put 'open'  // Calls put(GarageRelay) and sends it a "1" which tells the Particle sketch to run GarageRelay with command == open
}




// How we push commands from the device handler to the Particle
private put(garageRelay) {
	log.debug "sending post";
		httpPost(
			uri: "https://api.particle.io/v1/devices/${deviceId}/GarageRelay",
	        body: [access_token: token, command: garageRelay],  
		) {response -> log.debug (response.data)}
	log.debug "post sent";
    }

Not sure of exactly what you are describing, but you don’t seem to be using the Switch capability so I’d recommend removing that for starters. The new app isn’t keen on capabilities being declared but their attributes not having values.

Ok, removed Switch capability.
I want to see value of contactVar/contatct in new app…

I just copied your device handler, removed the Switch status, and created a device. It appeared in my app with a contact sensor icon. The tile showed ‘Getting status’ and the device details showed a crossed out cloud for the contact, but that just means the ‘contact’ attribute didn’t have a value. I added the following and updated the device:

    def installed()
    {
        sendEvent( name: 'contact', value: 'closed' )
    }

That seeded the contact attribute with a valid value so the app could find it. If the device has been working with the Classic app then ‘contact’ should presumably already have a value of ‘open’ or ‘closed’ so the app should be able to find it already. However this way helps new installations.

So in the dashboard I see a tile with a contact sensor icon and ‘Closed’ as the status. In the device details I see a single Contact Sensor panel, again reporting ‘Closed’.

So in my case contactVar is doorStatus (string) with possible values “OPEN”, “MID”, “CLOSED”, and device icon changes with it.

and this is .ino part that pulls value from contact sensors and combines it into one value:
void loop() {

// loop over Reed switchs status to see if doors are open / closed / mid and send when changed to IFTTT

const char* message = STATUS_MESSAGE_UNAVAILABLE;

if(digitalRead(pinReedSensorClosed) ==1 and digitalRead(pinReedSensorOpen) ==0){
pinState = 1; 
}

if(digitalRead(pinReedSensorClosed) ==0 and digitalRead(pinReedSensorOpen) ==1){
pinState = 3; 
}

if(digitalRead(pinReedSensorClosed) ==0 and digitalRead(pinReedSensorOpen) ==0){
pinState = 2; 
}

if(pinState == 1 ) message = CLOSED;
if(pinState == 2 ) message = MID;
if(pinState == 3 ) message = OPEN;

if(pinState != pinStatePrevious) {
Spark.variable("doorStatus", message , STRING);
 delay(5000); 
pinStatePrevious = pinState;
}
else{
pinStatePrevious = pinStatePrevious;
}

}

Ah right, I think I misread a previous post. At the moment the app just doesn’t cope with any custom attributes and commands. Custom Capabilities are said to be coming but without a time scale at the moment.

1 Like

This DTH doesn’t use any custom attributes. It just used “contact” which is a perfectly valid attribute for the Contact Sensor capability.

The handler is using ‘in motion’ and ‘ventilation’ values for ‘contact’ as well as ‘open’ and ‘closed’. Those are custom values. When I pointed out that the handler (once the Switch capability which was originally include was removed) already seemed to use ‘contact’ for the tile status, the OP mentioned needing a ‘mid’ value and to be able to see different icons.

You can do that sort of thing in the Classic app, but the new app expects the attribute values to be as defined by the capability. So the new app seems unlikely to do the job until custom capabilities come along.

I reserve the right to have misunderstood exactly what is required, but if you use any value for ‘contact’ other than ‘open’ or ‘closed’ you are using a custom attribute in my book.

They are using custom values within the attribute, yes. But it is not using a custom attribute or capability. Have to be careful about what terms you use for what. The attribute is contact. The value for the attribute is closed/open. The capability is Contact Sensor.