From 6bd99de9002341b0ece5ccca8365239aed9326b8 Mon Sep 17 00:00:00 2001 From: Kevin Siml Date: Tue, 14 Feb 2017 22:14:23 +0100 Subject: [PATCH 1/3] Create pushsafer.smartapp.groovy --- .../pushsafer.smartapp.groovy | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 smartapps/smartapp.pushsafer/pushsafer.smartapp.groovy diff --git a/smartapps/smartapp.pushsafer/pushsafer.smartapp.groovy b/smartapps/smartapp.pushsafer/pushsafer.smartapp.groovy new file mode 100644 index 00000000000..445ad8c218d --- /dev/null +++ b/smartapps/smartapp.pushsafer/pushsafer.smartapp.groovy @@ -0,0 +1,180 @@ +/** + * Pushsafer + * + * Copyright 2017 Kevin Siml / Pushsafer.com + * + * 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: "Pushsafer", + namespace: "smartapp.pushsafer", + author: "Kevin Siml", + description: "Send a Pushsafer.com notification when a device event occurs.", + category: "Safety & Security", + iconUrl: "https://www.pushsafer.com/icon60.png", + iconX2Url: "https://www.pushsafer.com/icon120.png", + iconX3Url: "https://www.pushsafer.com/icon180.png") + + +preferences +{ + section("Devices...") { + input "switches", "capability.switch", title: "Which Switches?", multiple: true, required: false + input "motionSensors", "capability.motionSensor", title: "Which Motion Sensors?", multiple: true, required: false + input "contactSensors", "capability.contactSensor", title: "Which Contact Sensors?", multiple: true, required: false + input "presenceSensors", "capability.presenceSensor", title: "Which Presence Sensors?", multiple: true, required: false + input "accelerationSensors", "capability.accelerationSensor", title: "Which Acceleration Sensors?", multiple: true, required: false + input "locks", "capability.lock", title: "Which Locks?", multiple: true, required: false + } + section("Application...") { + input "push", "enum", title: "SmartThings App Notification?", required: true, multiple: false, + metadata :[ + values: [ 'No', 'Yes' ] + ] + } + section("Pushsafer...") { + input "privatekey", "text", title: "Private or Alias Key", required: true + input "Pushtitle", "text", title: "Title", required: false + input "Pushdevice", "text", title: "Device or Device Group ID (blank for all)", required: false + input "PushURL", "text", title: "URL or URL scheme", required: false + input "PushURLtitle", "text", title: "Title of URL", required: false + input "PushTime2Live", "text", title: "Time 2 Live", required: false + input "Pushicon", "text", title: "Icon", required: false + input "Pushsound", "text", title: "Sound", required: false + input "Pushvibration", "text", title: "Vibration", required: false + } +} + +def installed() +{ + log.debug "'Pushsafer' installed with settings: ${settings}" + initialize() +} + +def updated() +{ + log.debug "'Pushsafer' updated with settings: ${settings}" + unsubscribe() + initialize() +} + +def initialize() +{ + /** + * You can customize each of these to only receive one type of notification + * by subscribing only to the individual event for each type. Additional + * logic would be required in the Preferences section and the device handler. + */ + + if (switches) { + // switch.on or switch.off + subscribe(switches, "switch", handler) + } + if (motionSensors) { + // motion.active or motion.inactive + subscribe(motionSensors, "motion", handler) + } + if (contactSensors) { + // contact.open or contact.closed + subscribe(contactSensors, "contact", handler) + } + if (presenceSensors) { + // presence.present or 'presence.not present' (Why the space? It is dumb.) + subscribe(presenceSensors, "presence", handler) + } + if (accelerationSensors) { + // acceleration.active or acceleration.inactive + subscribe(accelerationSensors, "acceleration", handler) + } + if (locks) { + // lock.locked or lock.unlocked + subscribe(locks, "lock", handler) + } +} + +def handler(evt) { + log.debug "$evt.displayName is $evt.value" + + if (push == "Yes") + { + sendPush("${evt.displayName} is ${evt.value} [Sent from 'Pushsafer']"); + } + + // Define the initial postBody keys and values for all messages + def postBody = [ + k: "$privatekey", + m: "${evt.displayName} is ${evt.value}" + ] + + // We only have to define the device if we are sending to a single device + if (Pushdevice) + { + postBody['d'] = "$Pushdevice" + } + + if (Pushicon) + { + postBody['i'] = "$Pushicon" + } + + if (Pushsound) + { + postBody['s'] = "$Pushsound" + } + + if (Pushvibration) + { + postBody['v'] = "$Pushvibration" + } + + if (PushURL) + { + postBody['u'] = "$PushURL" + } + + if (PushURLtitle) + { + postBody['ut'] = "$PushURLtitle" + } + + if (Pushtitle) + { + postBody['t'] = "$Pushtitle" + } + + if (PushTime2Live) + { + postBody['l'] = "$PushTime2Live" + } + + // Prepare the package to be sent + def params = [ + uri: "https://www.pushsafer.com/api", + body: postBody + ] + + log.debug postBody + log.debug "Sending Pushsafer: Private/Alias key '${privatekey}'" + + httpPost(params){ + response -> + if(response.status != 200) + { + sendPush("ERROR: 'Pushsafer' received HTTP error ${response.status}. Check your key!") + log.error "Received HTTP error ${response.status}. Check your key!" + } + else + { + log.debug "HTTP response received [$response.status]" + } + } + +} From 775d58fe40188d8d3ac228deb0119bcb8ec6636e Mon Sep 17 00:00:00 2001 From: Kevin Siml Date: Tue, 14 Feb 2017 22:15:28 +0100 Subject: [PATCH 2/3] Create README.md --- smartapps/smartapp.pushsafer/README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 smartapps/smartapp.pushsafer/README.md diff --git a/smartapps/smartapp.pushsafer/README.md b/smartapps/smartapp.pushsafer/README.md new file mode 100644 index 00000000000..b6c602f8d7c --- /dev/null +++ b/smartapps/smartapp.pushsafer/README.md @@ -0,0 +1,25 @@ +# smartapp.pushsafer +![Pushsafer](https://www.pushsafer.com/de/assets/logos/logo.png) + +# Pushsafer notifications for SmartThings + +Send a Pushsafer notification when a device event occurs. + +## Installation + +1. Browse to My SmartApps (https://graph.api.smartthings.com/ide/apps) +1. Create a [New SmartApp] with the following details + * Author: http://github.com/smartthings-users/smartapp.pushsafer + * Name: Pushsafer + * Description: Send a Pushsafer notification when a device event occurs. + * Icon: https://www.pushsafer.com/icon.png + +1. Copy and paste the code into the IDE. +1. Press [Save] +1. Navigate to [Publish] -> For Me + +## Setup + +1. Open your https://www.pushsafer.com Account +2. Copy your Private or Alias Key to your SmartApp preferences +3. Follow the [API description](https://www.pushsafer.com/en/pushapi) and enter params if necessary From e0d30e0b95929836bc6b860f2908fc4a66d91503 Mon Sep 17 00:00:00 2001 From: Kevin Siml Date: Wed, 15 Mar 2023 10:12:22 +0100 Subject: [PATCH 3/3] Update pushsafer.smartapp.groovy --- .../pushsafer.smartapp.groovy | 62 ++++++++++++++++--- 1 file changed, 52 insertions(+), 10 deletions(-) diff --git a/smartapps/smartapp.pushsafer/pushsafer.smartapp.groovy b/smartapps/smartapp.pushsafer/pushsafer.smartapp.groovy index 445ad8c218d..b43189f5cd1 100644 --- a/smartapps/smartapp.pushsafer/pushsafer.smartapp.groovy +++ b/smartapps/smartapp.pushsafer/pushsafer.smartapp.groovy @@ -1,7 +1,7 @@ /** * Pushsafer * - * Copyright 2017 Kevin Siml / Pushsafer.com + * Copyright 2023 Kevin Siml / Pushsafer.com * * 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: @@ -50,6 +50,13 @@ preferences input "Pushicon", "text", title: "Icon", required: false input "Pushsound", "text", title: "Sound", required: false input "Pushvibration", "text", title: "Vibration", required: false + input "PushPriority", "text", title: "Priority", required: false + input "PushRetry", "text", title: "Retry", required: false + input "PushExpire", "text", title: "Expire", required: false + input "PushConfirm", "text", title: "Confirm", required: false + input "PushAnswer", "text", title: "Answer", required: false + input "PushAnswerOptions", "text", title: "Answer Options", required: false + input "PushAnswerForce", "text", title: "Force Answer", required: false } } @@ -119,17 +126,17 @@ def handler(evt) { { postBody['d'] = "$Pushdevice" } - + if (Pushicon) { postBody['i'] = "$Pushicon" } - + if (Pushsound) { postBody['s'] = "$Pushsound" } - + if (Pushvibration) { postBody['v'] = "$Pushvibration" @@ -139,22 +146,57 @@ def handler(evt) { { postBody['u'] = "$PushURL" } - + if (PushURLtitle) { postBody['ut'] = "$PushURLtitle" } - + if (Pushtitle) { postBody['t'] = "$Pushtitle" } - + if (PushTime2Live) { postBody['l'] = "$PushTime2Live" - } - + } + + if (PushPriority) + { + postBody['pr'] = "$PushPriority" + } + + if (PushRetry) + { + postBody['re'] = "$PushRetry" + } + + if (PushExpire) + { + postBody['ex'] = "$PushExpire" + } + + if (PushConfirm) + { + postBody['cr'] = "$PushConfirm" + } + + if (PushAnswer) + { + postBody['a'] = "$PushAnswer" + } + + if (PushAnswerOptions) + { + postBody['ao'] = "$PushAnswerOptions" + } + + if (PushAnswerForce) + { + postBody['af'] = "$PushAnswerForce" + } + // Prepare the package to be sent def params = [ uri: "https://www.pushsafer.com/api", @@ -163,7 +205,7 @@ def handler(evt) { log.debug postBody log.debug "Sending Pushsafer: Private/Alias key '${privatekey}'" - + httpPost(params){ response -> if(response.status != 200)