[Release] HubDuino v1.1.9 - Hubitat to Arduino / ESP8266 / ESP32 / ThingShield Integration (ST_Anything)

That is a great question. The reason I have included various third-party libraries is two-fold:

  1. Make sure I have a copy of the code in the event the developer were to remove it from GitHub
  2. The versions included have been tested and are known to work with the HubDuino libraries.

Thanks!

In relation to the Contact Sensor device handler im trying to find a way to change the displayed state from "Open" or "Closed" to something else like "Alarm" and "Normal". Im not sure where to begin editing the driver to modify this?

In general, HubDuino implements Hubitat’s standard device capabilities. Obviously, you’re welcome to change things as you see fit for your needs.

If you’re using the released version of HubDuino and ST_Anything, the you should be able to copy and modify the Child Contact Sensor custom driver. After creating a new version, you could change the child device’s driver type to your new one.

The section of code you’d modify the following section.

def parse(String description) {
    if (logEnable) log.debug "parse(${description}) called"
	def parts = description.split(" ")
    def name  = parts.length>0?parts[0].trim():null
    def value = parts.length>1?parts[1].trim():null
    if (name && value) {
        // Update device
        sendEvent(name: name, value: value)
    }
    else {
    	log.error "Missing either name or value.  Cannot parse!"
    }
}

You could add a custom attribute to your version of driver, and then add your custom sendEvent() using your custom text.

Thanks very much for the quick reply, im very new at coding, I've been able to create a custom attribute by dumb luck mostly. what line would i need to add to the existing code. Or is there a reference document that i can research to work through this. Best i can come up with would be this:

def value = if open=Alarm, if closed=Normal?

I found some code for a konnected contact sensor that does this but it seems its getting some info from its parent app:

metadata {
capability "Water Sensor"
capability "Sensor"
}
preferences {
input name: "normalState", type: "enum", title: "Normal State",
options: ["Normally Closed", "Normally Open"],
defaultValue: "Normally Open",
description: "Most leak sensors indicate water when the circuit is closed (NO). Select Normally Closed (NC) to reverse this logic."
}
}

def isClosed() {
normalState == "Normally Closed" ? "dry" : "wet"
}

def isOpen() {
normalState == "Normally Closed" ? "wet" : "dry"
}

//Update state sent from parent app
def setStatus(state) {
def stateValue = state == "1" ? isOpen() : isClosed()
sendEvent(name: "water", value: stateValue)
log.info "$device.label is $stateValue"
}

What is the name of your custom attribute? Did you declare the custom attribute within the driver? What data type did you choose for it?

The change would be something like the following, assuming your custom attribute name is "AlarmStatus"

def parse(String description) {
    if (logEnable) log.debug "parse(${description}) called"
	def parts = description.split(" ")
    def name  = parts.length>0?parts[0].trim():null
    def value = parts.length>1?parts[1].trim():null
    if (name && value) {
        // Update device
        sendEvent(name: name, value: value)

       //Start of new Code for custom attribute
        if (value == "open") {
            sendEvent(name: "AlarmStatus", value: "Alarm")
        }
        else {
            sendEvent(name: "AlarmStatus", value: "Normal")
        }
       //end of new code

    }
    else {
    	log.error "Missing either name or value.  Cannot parse!"
    }
}

Was throwing an error because the IF command was uppercase but now i got it working. Thank you very much for this and the entire HubDuino platform its very useful.

I'm using a Mega with 12 sensors and 4 switches going in to enable and monitor my in floor radiant heating system and mechanical equipment, so for the contact sensors i didn't want to figure out which state is which since some of the device contacts are normally open and some are normally closed. This will also work nicely with displaying any custom state like Wet/Dry, ect

If anyone wants this for the future full code is below:

/**

  • Child Contact Sensor
  • Copyright 2017 Daniel Ogorchock
  • 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.
  • Change History:
  • Date Who What

  • 2017-04-10 Dan Ogorchock Original Creation
  • 2017-08-23 Allan (vseven) Added a generateEvent routine that gets info from the parent device. This routine runs each time the value is updated which can lead to other modifications of the device.
  • 2018-06-02 Dan Ogorchock Revised/Simplified for Hubitat Composite Driver Model
  • 2018-09-22 Dan Ogorchock Added preference for debug logging
  • 2019-07-01 Dan Ogorchock Added importUrl
  • 2020-01-25 Dan Ogorchock Remove custom lastUpdated attribute & general code cleanup

*/
metadata {
definition (name: "Child Contact Sensor", namespace: "ogiewon", author: "Dan Ogorchock", importUrl:

	capability "Contact Sensor"
	capability "Sensor"
    
    attribute "AlarmStatus", "String"
}

preferences {
    input name: "logEnable", type: "bool", title: "Enable debug logging", defaultValue: true
}

}

def logsOff(){
log.warn "debug logging disabled..."
device.updateSetting("logEnable",[value:"false",type:"bool"])
}

def parse(String description) {
if (logEnable) log.debug "parse(${description}) called"
def parts = description.split(" ")
def name = parts.length>0?parts[0].trim():null
def value = parts.length>1?parts[1].trim():null
if (name && value) {
// Update device
sendEvent(name: name, value: value)

   //Start of new Code for custom attribute
    if (value == "open") {
        sendEvent(name: "AlarmStatus", value: "Alarm")
    }
    else {
        sendEvent(name: "AlarmStatus", value: "Normal")
    }
   //end of new code

}
else {
	log.error "Missing either name or value.  Cannot parse!"
}

}

def installed() {
updated()
}

def updated() {
if (logEnable) runIn(1800,logsOff)
}