Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions smartapps/smartapp.pushsafer/README.md
Original file line number Diff line number Diff line change
@@ -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
222 changes: 222 additions & 0 deletions smartapps/smartapp.pushsafer/pushsafer.smartapp.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
/**
* Pushsafer
*
* 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:
*
* 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
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
}
}

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"
}

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",
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]"
}
}

}