/** * PHOTON FAN CONTROL * Date: 2016-11-25 */ preferences { section("Your Particle credentials and device Id:") { input("token", "text", title: "Access Token") input("deviceId", "text", title: "Device ID") } } // for the UI metadata { definition (name: "Photon Fan Control", author: "tareker") { capability "Switch" } // tile definitions tiles { standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) { state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821" state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff" } main "switch" details "switch" } } def parse(String description) { log.error "This device does not support incoming events" return null } def on() { sendToDevice '2' sendEvent(name: 'switch', value: 'on') } def off() { sendToDevice '0' sendEvent(name: 'switch', value: 'off') } private sendToDevice(cmd) { // Particle API call to our photon device // "deviceId" will be replaced with our actual device name // FanControl is the name of our published function exposed by the device // state is our input parameter: 'on' or 'off' httpPost( uri: "https://api.particle.io/v1/devices/${deviceId}/FanControl", body: [access_token: token, command: cmd], ) {response -> log.debug (response.data)} }