Foscam Activation Smartapp throwing an error on V2 hub


(Pj Hollenbeck) #1

Hey y’all, I’m running into a snag when trying to re-use an old smartapp from my V1 hub to control when my Foscam clone camera turns on and off based on away/home settings. Basically, I can see the camera fine, and manually enabling it and getting images from it etc. works fine, but when I try to use the attached code to activate it automatically it give me issues. Oddly, from the desktop IDE it installs without issue and seems to work, but if I try to install the smartapp or view it from the phone it gives me the error message “Sorry, but there was an unexpected error” and shows a blank screen with only “Remove” on it, but the Remove option also does nothing. What’s puzzling me is that it worked fine on the V1 but once I migrated I have no success. Thanks!

Here’s the code for the smartapp (I’d fully pulled it from a pre-existing smartapp found on this community, hope that’s ok…):

/**

  • Secure My Foscam
  • Author: brian@bevey.org
  • Date: 9/25/13
  • Simply turns on the alarm for any Foscam custome device. This is intended
  • to be used with the Foscam custom device type with a camera set up for FTP
  • or email uploading based on motion detection.
    */

// Automatically generated. Make future change here.
definition(
name: “Peaches Foscam”,
namespace: " ",
author: “[removed for posting]”,
description: “foscam activator”,
iconUrl: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png”,
iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png”,
iconX3Url: “https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png”)

preferences {
section(“When the house is in this mode…”) {
input “newSTMode”, “mode”, Title: “Mode?”
}

section(“Change to this mode to…”) {
input “newMode”, “enum”, metadata:[values:[“Alarm On”, “Alarm Off”]]
}

section(“Move to this preset…”) {
input “newPreset”, “enum”, metadata:[values:([1, 2, 3])], required: false
}

section(“Change these Foscam modes…”) {
input “foscams”, “capability.imageCapture”, multiple: true
}

}

def installed() {
subscribe(location, changeMode)
subscribe(app, changeMode)
}

def updated() {
unsubscribe()
subscribe(location, changeMode)
subscribe(app, changeMode)
}

def changeMode(evt) {
if(newPreset) {
def preset = new Integer(newPreset)

log.info("Preset: ${preset}")
foscams?.preset(preset)

}

if(newMode == “Alarm On”) {
log.info(“Alarm: on”)
/** def message = "${app.label} activated the IP Camera because everyone left home"
log.info(message)
sendPush(message)*/

foscams?.alarmOn()

}

else {
log.info(“Alarm: off”)
/** def message = "${app.label} disarmed the IP Camera because someone is home"
log.info(message)
sendPush(message)*/

foscams?.alarmOff()

}
}