Noob - help with a minor DH modification - want to "set a variable" that can be used by webcore


(Kebel87) #1

Hi all,

I want to do a very minor and easy modification to a device handler but after many tries and errors, I resorted to ask for help.

I my own words, what I want to do is to define a variable that will be exploitable within other smartapps, such as WebCoRE.

The value I’m looking for seems to be already existing in the code. I’ve spotted the sendevent that logs it to graph.

sendEvent (name: "status", value: "${state}")

In the event log, I see the following :

Source Name Value
Device status ready

What modification should I do to the following code in order to be able to use the value “ready” (or whatever other value it sometime contains) into other smartapps.

Thanks a lot for your help.

/**
 *  DSC Away Panel
 *
 *  Author: Jordan <jordan@xeron.cc
 *  Original Code By: Rob Fisher <robfish@att.net>, Carlos Santiago <carloss66@gmail.com>, JTT <aesystems@gmail.com>
 *  Date: 2016-02-03
 */
 // for the UI

metadata {
    // Automatically generated. Make future change here.
    definition (name: "DSC Away Panel", author: "Jordan <jordan@xeron.cc>", namespace: 'dsc') {
        capability "Switch"
        capability "Refresh"
                
        command "away"
        command "autobypass"
        command "bypassoff"
        command "disarm"
        command "instant"
        command "night"
        command "nokey"
        command "partition"
        command "key"
        command "keyfire"
        command "keyaux"
        command "keypanic"
        command "reset"
        command "stay"
        command "togglechime"
    }

    // simulator metadata
    simulator {
    }

    // UI tile definitions
    tiles(scale: 2) {
      multiAttributeTile(name:"status", type: "generic", width: 6, height: 4){
        tileAttribute ("device.status", key: "PRIMARY_CONTROL") {
          attributeState "alarm", label:'Alarm', action: 'disarm', icon:"st.security.alarm.alarm", backgroundColor:"#ff0000"
          attributeState "away", label:'Armed Away', action: 'disarm', icon:"st.security.alarm.on", backgroundColor:"#800000"
          attributeState "disarm", label:'Disarmed', icon:"st.security.alarm.off", backgroundColor:"#79b821"
          attributeState "duress", label:'Duress', action: 'disarm', icon:"st.security.alarm.alarm", backgroundColor:"#ff0000"
          attributeState "entrydelay", label:'Entry Delay', action: 'disarm', icon:"st.security.alarm.on", backgroundColor:"#ff9900"
          attributeState "exitdelay", label:'Exit Delay', action: 'disarm', icon:"st.security.alarm.on", backgroundColor:"#ff9900"
          attributeState "notready", label:'Not Ready', icon:"st.security.alarm.off", backgroundColor:"#ffcc00"
          attributeState "ready", label:'Ready', action: 'away', icon:"st.security.alarm.off", backgroundColor:"#79b821"
          attributeState "forceready", label:'Ready - F', action: 'away', icon:"st.security.alarm.off", backgroundColor:"#79b821"
          attributeState "stay", label:'Armed Stay', action: 'disarm', icon:"st.security.alarm.on", backgroundColor:"#008CC1"
          attributeState "instantaway", label:'Armed Instant Away', action: 'disarm', icon:"st.security.alarm.on", backgroundColor:"#800000"
          attributeState "instantstay", label:'Armed Instant Stay', action: 'disarm', icon:"st.security.alarm.on", backgroundColor:"#008CC1"
        }
        tileAttribute ("device.trouble", key: "SECONDARY_CONTROL") {
          attributeState "detected", label: 'Trouble', icon: "st.security.alarm.alarm"
          attributeState "clear", label: 'No Trouble', icon: "st.security.alarm.clear"
        }
      }
      standardTile("disarm", "capability.momentary", width: 2, height: 2, title: "Disarm", decoration:"flat"){
        state "disarm", label: 'Disarm', action: "disarm", icon: "st.presence.house.unlocked", backgroundColor: "#79b821"
      }
      standardTile("away", "capability.momentary", width: 2, height: 2, title: "Away", decoration:"flat"){
        state "away", label: 'Away', action: "away", icon: "st.presence.car.car", backgroundColor: "#800000"
      }
      standardTile("stay", "capability.momentary", width: 2, height: 2, title: "Stay", decoration:"flat"){
        state "stay", label: 'Stay', action: "stay", icon: "st.presence.house.secured", backgroundColor: "#008CC1"
      }
      standardTile("refresh", "device.refresh", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
        state "default", action:"refresh.refresh", icon:"st.secondary.refresh"
      }
      standardTile("chime", "device.chime", width: 2, height: 2, title: "Chime", decoration:"flat"){
        state "togglechime", label: 'Toggling Chime', action: "togglechime", icon: "st.alarm.beep.beep"
        state "chime", label: 'Chime', action: "togglechime", icon: "st.custom.sonos.unmuted"
        state "nochime", label: 'No Chime', action: "togglechime", icon: "st.custom.sonos.muted"
      }
      standardTile("autobypass", "capability.momentary", width: 2, height: 2, title: "Auto-Bypass", decoration:"flat"){
        state "autobypass", label: 'Auto-Bypass', action: "autobypass", icon: "st.locks.lock.unlocked"
      }
      standardTile("bypassoff", "capability.momentary", width: 2, height: 2, title: "Bypass Off", decoration:"flat"){
        state "bypassoff", label: 'Bypass Off', action: "bypassoff", icon: "st.locks.lock.locked"
      }
      standardTile("instant", "capability.momentary", width: 2, height: 2, title: "Instant", decoration:"flat"){
        state "instant", label: 'Instant', action: "instant", icon: "st.Health & Wellness.health7", backgroundColor: "#00FF00"
      }
      standardTile("night", "capability.momentary", width: 2, height: 2, title: "Night", decoration:"flat"){
        state "night", label: 'Night', action: "night", icon: "st.Bedroom.bedroom2", backgroundColor: "#AA00FF"
      }
      standardTile("reset", "capability.momentary", width: 2, height: 2, title: "Sensor Reset", decoration:"flat"){
        state "reset", label: 'Sensor Reset', action: "reset", icon: "st.alarm.smoke.smoke"
      }
      valueTile("ledready", "device.ledready", width: 2, height: 1){
        state "ledready", label:'Ready: ${currentValue}'
      }
      valueTile("ledarmed", "device.ledarmed", width: 2, height: 1){
        state "ledarmed", label:'Armed: ${currentValue}'
      }
      valueTile("ledmemory", "device.ledmemory", width: 2, height: 1){
        state "ledmemory", label:'Memory: ${currentValue}'
      }
      valueTile("ledbypass", "device.ledbypass", width: 2, height: 1){
        state "ledbypass", label:'Bypass: ${currentValue}'
      }
      valueTile("ledtrouble", "device.ledtrouble", width: 2, height: 1){
        state "ledtrouble", label:'Trouble: ${currentValue}'
      }
      valueTile("ledprogram", "device.ledprogram", width: 2, height: 1){
        state "ledprogram", label:'Program: ${currentValue}'
      }
      valueTile("ledfire", "device.ledfire", width: 2, height: 1){
        state "ledfire", label:'Fire: ${currentValue}'
      }
      valueTile("ledbacklight", "device.ledbacklight", width: 2, height: 1){
        state "ledbacklight", label:'Backlight: ${currentValue}'
      }
      standardTile("key", "device.key", width: 2, height: 2, title: "Key", decoration:"flat"){
        state "nokey", label: 'Alarm Keys Off', action: "key", icon: "st.illuminance.illuminance.dark", defaultState: true
        state "key", label: 'Alarm Keys On', action: "nokey", icon: "st.illuminance.illuminance.light"
      }
      standardTile("keyfire", "device.keyfire", width: 2, height: 2, title: "Fire Key", decoration:"flat"){
        state "restore", label: 'Fire Key', action: "keyfire", icon: "st.Home.home29", backgroundColor: "#FF2400"
        state "alarm", label: 'Fire Key Alarm', action: "keyfire", icon: "st.Home.home29", backgroundColor: "#FF2400"
      }
      standardTile("keyaux", "device.keyaux", width: 2, height: 2, title: "Aux Key", decoration:"flat"){
        state "restore", label: 'Aux Key', action: "keyaux", icon: "st.Transportation.transportation7", backgroundColor: "#DD0000"
        state "alarm", label: 'Aux Key Alarm', action: "keyaux", icon: "st.Transportation.transportation7", backgroundColor: "#DD0000"
      }
      standardTile("keypanic", "device.keypanic", width: 2, height: 2, title: "Panic Key", decoration:"flat"){
        state "restore", label: 'Panic Key', action: "keypanic", icon: "st.Transportation.transportation9", backgroundColor: "#000fd5"
        state "alarm", label: 'Panic Key Alarm', action: "keypanic", icon: "st.Transportation.transportation9", backgroundColor: "#000fd5"
      }

      main "status"
      details(["status", "away", "stay", "disarm", "instant", "night", "refresh", "chime", "autobypass", "bypassoff", "reset", "ledready", "ledarmed", "ledmemory", "ledbypass", "key", "ledtrouble", "ledprogram", "ledfire", "ledbacklight", "keyfire", "keyaux", "keypanic"])
    }
}

def partition(String state, String partition, Map parameters) {
  // state will be a valid state for the panel (ready, notready, armed, etc)
  // partition will be a partition number, for most users this will always be 1

  log.debug "Partition: ${state} for partition: ${partition}"

  def onList = ['alarm','away','entrydelay','exitdelay','instantaway']

  def chimeList = ['chime','nochime']

  def troubleMap = [
    'trouble':"detected",
    'restore':"clear",
  ]

  if (onList.contains(state)) {
    sendEvent (name: "switch", value: "on")
  } else if (!(chimeList.contains(state) || troubleMap[state] || state.startsWith('led') || state.startsWith('key'))) {
    sendEvent (name: "switch", value: "off")
  }

  if (troubleMap[state]) {
    def troubleState = troubleMap."${state}"
    // Send trouble event
    sendEvent (name: "trouble", value: "${troubleState}")
  } else if (chimeList.contains(state)) {
    // Send chime event
    sendEvent (name: "chime", value: "${state}")
  } else if (state.startsWith('led')) {
    def flash = (state.startsWith('ledflash')) ? 'flash ' : ''
    for (p in parameters) {
      sendEvent (name: "led${p.key}", value: "${flash}${p.value}")
    }
  } else if (state.startsWith('key')) {
    def name = state.minus('alarm').minus('restore')
    def value = state.replaceAll(/.*(alarm|restore)/, '$1')
    sendEvent (name: "${name}", value: "${value}")
  } else {
    // Send final event
    sendEvent (name: "status", value: "${state}")
  }
}


def away() {
  parent.sendUrl("arm?part=${device.deviceNetworkId[-1]}")
}

def autobypass() {
  parent.autoBypass()
}

def bypassoff() {
  parent.sendUrl("bypass?zone=0")
}

def disarm() {
  parent.sendUrl("disarm?part=${device.deviceNetworkId[-1]}")
}

def instant() {
  parent.sendUrl("toggleinstant?part=${device.deviceNetworkId[-1]}")
}

def night() {
  parent.sendUrl("togglenight?part=${device.deviceNetworkId[-1]}")
}

def nokey() {
  sendEvent (name: "key", value: "nokey")
}

def on() {
  away()
}

def off() {
  disarm()
}

def key() {
  sendEvent (name: "key", value: "key")
}

def keyfire() {
  if ("${device.currentValue("key")}" == 'key') {
    parent.sendUrl('panic?type=1')
  }
}

def keyaux() {
  if ("${device.currentValue("key")}" == 'key') {
    parent.sendUrl('panic?type=2')
  }
}

def keypanic() {
  if ("${device.currentValue("key")}" == 'key') {
    parent.sendUrl('panic?type=3')
  }
}

def refresh() {
  parent.sendUrl('refresh')
}

def reset() {
  parent.sendUrl("reset?part=${device.deviceNetworkId[-1]}")
}

def stay() {
  parent.sendUrl("stayarm?part=${device.deviceNetworkId[-1]}")
}

def togglechime() {
  parent.sendUrl("togglechime?part=${device.deviceNetworkId[-1]}")
}

[DEPRECATED Thread: visit community.webcore.co for assistance] webCoRE - Piston Design Help (ask your fellow members for assistance)
( I hate Mondays) #2

You need to publish it the same way you did with the commands. Add this before or after the command … list:

attribute status

(Kebel87) #3

@ady624

I get the following error when I press save

  × groovy.lang.MissingMethodException: No signature of method: script15012061422481586401836.attribute() is applicable for argument types: (java.lang.String) values: [status]
Possible solutions: attribute(java.util.Map), attribute(java.lang.String, java.lang.String), attribute(java.lang.String, java.lang.String, java.util.List), tileAttribute(java.lang.String), attributeState(java.lang.String) @ line 16

Line 16 is where I added attribute “status” as you suggested.

I’m not the one who coded the handler so I am very much a noob… thanks for your help, you’re really doing wonders.


( I hate Mondays) #4

Oh I forgot, second parameter is the data type, sorry - is this an enum (known list of distinct values) or a string (unknow number of values?)

attribute “status”, “string”

Should work


(Kebel87) #5

I modified accordingly and I could save.

However, for an unknown reason, it still doesn’t show up in webCoRE after save and publish as me.

Should there be a " def status = (don’t know what to write here) " somewhere down the file or the fact that The value of status get reported to events means the “variable” is already defined?

Thanks for the 1000th time!


( I hate Mondays) #6

Go to webCoRE’s ST app and go to Settings > Available devices and contacts > Available devices, then just tap Done > Done > Done, then refresh the UI - that forces webCoRE to reread all available atributes. It should show after that.


(Kebel87) #7

Wow, it works!!! Thank you so much! I learn a bit more everyday since I jumped into core/webcore.

Btw, on a different matter, I might have found a very minor “bug” within webcore ST app. I can’t open the “available contacts” page (it spins than nothing happens) since I have inadvertently created a duplicate contact that I can’t delete because of bug on graph side.

I opened a ticket with ST to get the contact ID deleted manually (the interface generate an error when trying to delete it, access denied).

In case it might help, here’s the weird contact entry that I believe is causing a problem to the webcore ST app. I’m pretty it’s a very isolated problem so I get you probably won’t investigate.

Thanks again for everything!