@baconface You can have device.contact see your particle variables. I’m not sure why we couldn’t get it to work when we were playing with this concept before it’s really quite simple. You posting this prompted me to try it out for my sake… I’ve gotten better since then with all the practice lately tinkering with my own. Here’s a video of the test setup working showing proof of the concept…
And some code…
Photon Code
int microswitch = D7; // define a pin for the microswitch
String garageContact = "unknown"; // on startup set the garageContact status to unknown and define the vaiable
void setup() {
Particle.variable("GarageStatus", garageContact); // register a particle cloud variable called garage status with the value of the garageContact variable
pinMode(microswitch, INPUT_PULLDOWN); // set pin on microswitch as input with the pulldown resistor engaged
}
void loop() {
int status = digitalRead(microswitch); // read the microswitch pin and store the value to status
if (status == HIGH){ // check status if its high store open in the garageContact string
garageContact = "open";
}
if (status == LOW){ // check status if its low store closed in the garageContact string
garageContact = "closed";
}
}
And the Device Handler I commented the crap out of the small blurb of code
/**
* garage contact from photon
*
Copyright 2014 SmartThings
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
// 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: "testgaragecontact", namespace: "Brennons Apps", author: "bscuderi") {
capability "Contact Sensor"
capability "Sensor"
capability "Refresh"
}
}
// make the tiles for the device handler
tiles {
standardTile("contact", "device.contact", width: 2, height: 2) {
state "open", label: '${name}', icon: "st.contact.contact.open", backgroundColor: "#e86d13"
state "closed", label: '${name}', icon: "st.contact.contact.closed", backgroundColor: "#00A0DC"
}
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)
}
Hope this helps bud be sure to report back if you get this thing working at the next level!