/** * Spruce Controller wifi zone child * * Copyright 2019 Plaid Systems * * Author: NC * Date: 2019-11 * * 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. * -------------11-2019 update--------------- * zone child for wifi controller * ported to hubitat * */ metadata { definition (name: 'Spruce wifi zone', namespace: 'plaidsystems', author: 'Plaid Systems') { capability "Switch" capability "Switch Level" command "refresh" attribute "zone number", "string" attribute "soil", "string" attribute "landscape", "string" attribute "nozzle", "string" attribute "gpm", "string" attribute "amp", "string" } preferences { input (description: "Use Level to set zone watering time. This setting does not effect scheduled water times.", displayDuringSetup: false, type: "paragraph", element: "paragraph", title: "Set Level") input (description: "Refresh the zone attributes.", displayDuringSetup: false, type: "paragraph", element: "paragraph", title: "Refresh") } } def installed(){ setLevel(10) //default zone on time sendEvent(name: "switch", value: "off", isStateChange: true) //initialize switch to off refresh() } def refresh(){ log.debug "device updated" parent.child_zones(device.deviceNetworkId) //get child zone settings } def generateEvent(Map results) { log.debug "zone event: ${results}" sendEvent(name: "${results.name}", value: "${results.value}", descriptionText: "${results.descriptionText}", isStateChange: true, displayed: "${results.displayed}") return null } void on(){ def runtime = device.latestValue('level') log.debug runtime parent.zoneOnOff(device.deviceNetworkId, 1, runtime) } void off(){ parent.zoneOnOff(device.deviceNetworkId, 0, 0) } //settings from cloud def childSettings(zone_num, Map results){ log.debug "Spruce Zone ${zone_num} settings ${results}" sendEvent(name: "zone number", value: zone_num, isStateChange: true, displayed: false) if (results.soil_type != null) sendEvent(name: "soil", value: results.soil_type, isStateChange: true, displayed: false) else sendEvent(name: "soil", value: "not set", isStateChange: true, displayed: false) if (results.nozzle_type != null) sendEvent(name: "nozzle", value: results.nozzle_type, isStateChange: true, displayed: false) else sendEvent(name: "nozzle", value: "not set", isStateChange: true, displayed: false) if (results.landscape_type != null) sendEvent(name: "landscape", value: results.landscape_type, isStateChange: true, displayed: false) else sendEvent(name: "landscape", value: "not set", isStateChange: true, displayed: false) } //set minutes def setLevel(percent) { log.debug "setLevel: ${percent}" sendEvent(name: "level", value: percent, displayed: false) }