/** * Copyright 2022 dsegall * * 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. * */ @SuppressWarnings('unused') public static String version() {return "1.2.0"} metadata { definition(name: "Replica Arlo Camera", namespace: "replica", author: "dsegall", importUrl:"https://raw.githubusercontent.com/dds82/replica/main/replica-arlo-camera.groovy") { capability "Actuator" capability "Battery" capability "Configuration" capability "MotionSensor" capability "SoundSensor" capability "Switch" capability "Refresh" attribute "healthStatus", "enum", ["offline", "online"] } preferences { } } def installed() { initialize() } def updated() { initialize() } def initialize() { updateDataValue("triggers", groovy.json.JsonOutput.toJson(getReplicaTriggers())) updateDataValue("commands", groovy.json.JsonOutput.toJson(getReplicaCommands())) } def configure() { log.info "${device.displayName} configured default rules" initialize() updateDataValue("rules", getReplicaRules()) sendCommand("configure") } // Methods documented here will show up in the Replica Command Configuration. These should be mostly setter in nature. Map getReplicaCommands() { return ([ "setSwitchValue":[[name:"switch*",type:"ENUM"]], "setSwitchOff":[], "setSwitchOn":[], "setMotionValue":[[name:"motion*",type:"ENUM"]], "setMotionActive":[], "setMotionInactive":[], "setSoundValue":[[name:"sound*",type:"ENUM"]], "setSoundDetected":[], "setSoundNotDetected":[], "setBatteryValue":[[name:"battery*",type:"NUMBER"]], "setHealthStatusValue":[[name:"healthStatus*",type:"ENUM"]] ]) } def setSwitchValue(value) { String descriptionText = "${device.displayName} was turned $value" sendEvent(name: "switch", value: value, descriptionText: descriptionText) log.info descriptionText } def setSwitchOff() { setSwitchValue("off") } def setSwitchOn() { setSwitchValue("on") } def off() { sendCommand("off") } def on() { sendCommand("on") } def setBatteryValue(value) { String descriptionText = "${device.displayName} battery level is $value %" sendEvent(name: "battery", value: value, unit: "%", descriptionText: descriptionText) log.info descriptionText } def setMotionValue(value) { String descriptionText = "${device.displayName} motion is $value" sendEvent(name: "motion", value: value, descriptionText: descriptionText) log.info descriptionText } def setMotionActive() { setMotionValue("active") } def setMotionInactive() { setMotionValue("inactive") } def setSoundValue(value) { String descriptionText = "${device.displayName} sound is $value" sendEvent(name: "sound", value: value, descriptionText: descriptionText) log.info descriptionText } def setSoundDetected() { setSoundValue("detected") } def setSoundNotDetected() { setSoundValue("not detected") } def setHealthStatusValue(value) { sendEvent(name: "healthStatus", value: value, descriptionText: "${device.displayName} healthStatus set to $value") } // Methods documented here will show up in the Replica Trigger Configuration. These should be all of the native capability commands Map getReplicaTriggers() { return ([ "refresh":[] ]) } private def sendCommand(String name, def value=null, String unit=null, data=[:]) { parent?.deviceTriggerHandler(device, [name:name, value:value, unit:unit, data:data, now:now]) } void refresh() { sendCommand("refresh") } String getReplicaRules() { return """{"version":1,"components":[ {"trigger":{"type":"attribute","properties":{"value":{"title":"ActivityState","type":"string"}},"additionalProperties":false,"required":["value"],"capability":"motionSensor","attribute":"motion","label":"attribute: motion.*"},"command":{"name":"setMotionValue","label":"command: setMotionValue(motion*)","type":"command","parameters":[{"name":"motion*","type":"ENUM"}]},"type":"smartTrigger"}, {"trigger":{"name":"off","label":"command: off()","type":"command"},"command":{"name":"off","type":"command","capability":"switch","label":"command: off()"},"type":"hubitatTrigger"}, {"trigger":{"name":"on","label":"command: on()","type":"command"},"command":{"name":"on","type":"command","capability":"switch","label":"command: on()"},"type":"hubitatTrigger"}, {"trigger":{"type":"attribute","properties":{"value":{"title":"ActivityState","type":"string"}},"additionalProperties":false,"required":["value"],"capability":"soundSensor","attribute":"sound","label":"attribute: sound.*"},"command":{"name":"setSoundValue","label":"command: setSoundValue(sound*)","type":"command","parameters":[{"name":"sound*","type":"ENUM"}]},"type":"smartTrigger"}, {"trigger":{"title":"IntegerPercent","type":"attribute","properties":{"value":{"type":"integer","minimum":0,"maximum":100},"unit":{"type":"string","enum":["%"],"default":"%"}},"additionalProperties":false,"required":["value"],"capability":"battery","attribute":"battery","label":"attribute: battery.*"},"command":{"name":"setBatteryValue","label":"command: setBatteryValue(battery*)","type":"command","parameters":[{"name":"battery*","type":"NUMBER"}]},"type":"smartTrigger","mute":true}, {"trigger":{"type":"attribute","properties":{"value":{"title":"SwitchState","type":"string"}},"additionalProperties":false,"required":["value"],"capability":"switch","attribute":"switch","label":"attribute: switch.*"},"command":{"name":"setSwitchValue","label":"command: setSwitchValue(switch*)","type":"command","parameters":[{"name":"switch*","type":"ENUM"}]},"type":"smartTrigger"}, {"trigger":{"type":"attribute","properties":{"value":{"title":"HealthState","type":"string"}},"additionalProperties":false,"required":["value"],"capability":"healthCheck","attribute":"healthStatus","label":"attribute: healthStatus.*"},"command":{"name":"setHealthStatusValue","label":"command: setHealthStatusValue(healthStatus*)","type":"command","parameters":[{"name":"healthStatus*","type":"ENUM"}]},"type":"smartTrigger","mute":true} ]}""" }