commit 03a1306cd2b2b272a9b7597e97a3b0959f33e23f Author: pstuart Date: Fri Apr 22 20:50:38 2016 -0500 initial commit from LCF 4/22/16 show diff --git a/devicetypes/pstuart/generic-video-camera.src/generic-video-camera.groovy b/devicetypes/pstuart/generic-video-camera.src/generic-video-camera.groovy new file mode 100644 index 0000000..7f30fc3 --- /dev/null +++ b/devicetypes/pstuart/generic-video-camera.src/generic-video-camera.groovy @@ -0,0 +1,123 @@ +/** + * Generic Video Camera + * + * Copyright 2016 Patrick Stuart + * + * 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. + * + */ +metadata { + definition (name: "Generic Video Camera", namespace: "pstuart", author: "Patrick Stuart") { + capability "Configuration" + capability "Video Camera" + capability "Video Capture" + capability "Refresh" + capability "Switch" + + // custom commands + command "start" + } + + simulator { + // TODO: define status and reply messages here + } + + tiles(scale: 2) { + multiAttributeTile(name: "videoPlayer", type: "videoPlayer", width: 6, height: 4) { + tileAttribute("device.switch", key: "CAMERA_STATUS") { + attributeState("on", label: "Active", icon: "st.camera.dlink-indoor", action: "switch.off", backgroundColor: "#79b821", defaultState: true) + attributeState("off", label: "Inactive", icon: "st.camera.dlink-indoor", action: "switch.on", backgroundColor: "#ffffff") + attributeState("restarting", label: "Connecting", icon: "st.camera.dlink-indoor", backgroundColor: "#53a7c0") + attributeState("unavailable", label: "Unavailable", icon: "st.camera.dlink-indoor", action: "refresh.refresh", backgroundColor: "#F22000") + } + + tileAttribute("device.errorMessage", key: "CAMERA_ERROR_MESSAGE") { + attributeState("errorMessage", label: "", value: "", defaultState: true) + } + + tileAttribute("device.camera", key: "PRIMARY_CONTROL") { + attributeState("on", label: "Active", icon: "st.camera.dlink-indoor", backgroundColor: "#79b821", defaultState: true) + attributeState("off", label: "Inactive", icon: "st.camera.dlink-indoor", backgroundColor: "#ffffff") + attributeState("restarting", label: "Connecting", icon: "st.camera.dlink-indoor", backgroundColor: "#53a7c0") + attributeState("unavailable", label: "Unavailable", icon: "st.camera.dlink-indoor", backgroundColor: "#F22000") + } + + tileAttribute("device.startLive", key: "START_LIVE") { + attributeState("live", action: "start", defaultState: true) + } + + tileAttribute("device.stream", key: "STREAM_URL") { + attributeState("activeURL", defaultState: true) + } + /* + tileAttribute("device.profile", key: "STREAM_QUALITY") { + attributeState("1", label: "720p", action: "setProfileHD", defaultState: true) + attributeState("2", label: "h360p", action: "setProfileSDH", defaultState: true) + attributeState("3", label: "l360p", action: "setProfileSDL", defaultState: true) + } */ + } + + + main("videoPlayer") + details(["videoPlayer"]) + } +} + +mappings { + path("/getInHomeURL") { + action: + [GET: "getInHomeURL"] + } +} + + +def installed() { + configure() +} + +def updated() { + configure() +} +// parse events into attributes +def parse(String description) { + log.debug "Parsing '${description}'" + +} + +// handle commands +def configure() { + log.debug "Executing 'configure'" + sendEvent(name:"switch", value: "on") +} + +def start() { + log.trace "start()" + def dataLiveVideo = [ + OutHomeURL : parent.state.CameraStreamPath, + InHomeURL : parent.state.CameraStreamPath, + ThumbnailURL: "http://cdn.device-icons.smartthings.com/camera/dlink-indoor@2x.png", + cookie : [key: "key", value: "value"] + ] + + def event = [ + name : "stream", + value : groovy.json.JsonOutput.toJson(dataLiveVideo).toString(), + data : groovy.json.JsonOutput.toJson(dataLiveVideo), + descriptionText: "Starting the livestream", + eventType : "VIDEO", + displayed : false, + isStateChange : true + ] + sendEvent(event) +} + +def getInHomeURL() { + [InHomeURL: parent.state.CameraStreamPath] +} \ No newline at end of file diff --git a/smartapps/pstuart/generic-video-camera-connect.src/generic-video-camera-child.groovy b/smartapps/pstuart/generic-video-camera-connect.src/generic-video-camera-child.groovy new file mode 100644 index 0000000..465eddc --- /dev/null +++ b/smartapps/pstuart/generic-video-camera-connect.src/generic-video-camera-child.groovy @@ -0,0 +1,82 @@ +/** +* Generic Video Camera Child +* +* Copyright 2016 Patrick Stuart +* +* 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. +* +*/ +definition( + name: "Generic Video Camera Child", + namespace: "pstuart", + author: "Patrick Stuart", + description: "Child Video Camera SmartApp", + category: "Safety & Security", + iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", + iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png", + iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png") + + +preferences { + page(name: "mainPage", title: "Install Video Camera", install: true, uninstall:true) { + section("Camera Name") { + label(name: "label", title: "Name This Camera", required: true, multiple: false, submitOnChange: true) + } + section("Add a Camera") { + input("CameraStreamPathList","enum", title: "Camera Stream Path", description: "Please enter your camera's streaming path", required:false, submitOnChange: true, + options: [ + ["rtsp://admin:winter12@192.168.101.185/Streaming/Channels/1":"Hikvision"], //hikvision + ["http://192.168.101.248:80/mjpeg.cgi?user=admin&password=winter12&channel=1.mjpeg":"Dlink"], //dlink 932l + ["http://pstuart:winter12@192.168.101.251/nphMotionJpeg?Resolution=640x480&Quality=Standard":"Panasonic"] //panasonic bl-140c + ], displayDuringSetup: true) + + + input("CameraStreamPathCustom","string", title: "Camera Stream Path", description: "Please enter your camera's streaming path", defaultValue: settings?.CameraStreamPathList, required:false, displayDuringSetup: true) + + } + } + +} + +def installed() { + log.debug "Installed" + + initialize() +} + +def updated() { + log.debug "Updated" + + unsubscribe() + initialize() +} + +def initialize() { + log.debug "CameraStreamPathList is $CameraStreamPathList" + log.debug "CameraStreamPathCustom is $CameraStreamPathCustom" + if(CameraStreamPathList) { state.CameraStreamPath = CameraStreamPathList } + if(CameraStreamPathCustom) { state.CameraStreamPath = CameraStreamPathCustom } + try { + def DNI = (Math.abs(new Random().nextInt()) % 99999 + 1).toString() + def cameras = getChildDevices() + if (cameras) { + removeChildDevices(getChildDevices()) + } + def childDevice = addChildDevice("pstuart", "Generic Video Camera", DNI, null, [name: app.label, label: app.label, completedSetup: true]) + } catch (e) { + log.error "Error creating device: ${e}" + } +} + +private removeChildDevices(delete) { + delete.each { + deleteChildDevice(it.deviceNetworkId) + } +} \ No newline at end of file diff --git a/smartapps/pstuart/generic-video-camera-connect.src/generic-video-camera-connect.groovy b/smartapps/pstuart/generic-video-camera-connect.src/generic-video-camera-connect.groovy new file mode 100644 index 0000000..4f8fc19 --- /dev/null +++ b/smartapps/pstuart/generic-video-camera-connect.src/generic-video-camera-connect.groovy @@ -0,0 +1,57 @@ +/** +* Generic Video Camera Connect +* +* Copyright 2016 Patrick Stuart +* +* 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. +* +*/ +definition( + name: "Generic Video Camera Connect", + namespace: "pstuart", + author: "Patrick Stuart", + description: "This smartapp installs the Generic Video Camera Connect App so you can add multiple child video cameras", + category: "Safety & Security", + iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", + iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png", + iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png", + singleInstance: true) + + +preferences { + page(name: "mainPage", title: "Existing Camera", install: true, uninstall: true) { + if(state?.installed) { + section("Add a New Camera") { + app "Generic Video Camera Child", "pstuart", "Generic Video Camera Child", title: "New Camera", page: "mainPage", multiple: true, install: true + } + } else { + section("Initial Install") { + paragraph "This smartapp installs the Generic Video Camera Connect App so you can add multiple child video cameras. Click install / done then go to smartapps in the flyout menu and add new cameras or edit existing cameras." + } + } + } +} + +def installed() { + log.debug "Installed with settings: ${settings}" + + initialize() +} + +def updated() { + log.debug "Updated with settings: ${settings}" + + unsubscribe() + initialize() +} + +def initialize() { + state.installed = true +}