How/where to look up

So I'm totally NOOB right now at making apps, but I'm trying to work from the hubitat public examples given here GitHub - hubitat/HubitatPublic

I'm not sure where to find documentation (or even just a forum post is fine!) of all the possible device types, and methods for those devices. See the error when I figured I would try to set the virtual contact state above.

Any tips appreciated!!!

UPDATE:
Ok, I found this Driver Capability List - Hubitat Documentation
and I see the code example is doing something like this:

if(evt.value == "open") motionDev.active() else motionDev.inactive()

So are "attributes" really just methods? So for setting the virtual contact sensor to open or closed I just say

   myDev.open()

?

Here you go! Devices are defined by their "Capabilities". Capabilities include the Commands and Attributes a device must implement if it chooses to use that capability.

https://docs.hubitat.com/index.php?title=Driver_Capability_List

1 Like

If you explain what you're trying to do, we can assist you with the proper syntax.

Ok, sorry, you were too quick! I was adding update above

Virtual Devices are special, as they need an alternate method of receiving commands versus the typical 'parse()' command.

So, a Virtual Contact Sensor has two additional (somewhat non-standard) commands added to it. These would be typically 'open()' and 'close()' (or maybe 'closed()'). You can see these commands exposed as buttons on the Device Details page for that virtual contact sensor.

But it is a little weird, because a virtual Presence device has "arrived()" and "departed()", whereas the status values for the presence attribute are 'present' and 'not present'

This issue really only impact Virtual 'Sensor' devices. These devices usually have no commands associated with them, as they receive updates via parse() from physical devices. Whereas a virtual 'Switch' just uses its 'on()' and 'off()' commands to update its own status via sendEvent().

Ok, got it working with 'open()' and 'close()'.

Here is the start of my hack at the example. So far it's not working to set the virtual contact sensor to open if I add a few other contact sensors that are open. Something must be wrong with 'areAnyOpen()'

definition(
    name: "Open Door Alerts",
    namespace: "hubitat",
    author: "Justin Eltoft",
    description: "Alert if a set of Doors/Contacts is open for N minutes (with repeat)",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: "")

preferences {
	page(name: "mainPage")
}

def mainPage() {
	dynamicPage(name: "mainPage", title: " ", install: true, uninstall: true) {
		section {
			input "thisName", "text", title: "Name this Door Check", submitOnChange: true
			if(thisName) app.updateLabel("$thisName")
            input "contactSensors", "capability.contactSensor", title: "Select Contact Sensors", submitOnChange: true, required: true, multiple: true
			input "minutesToAlert", "number", title: "Number of Minutes Left Open to Notify:", defaultValue: 15, submitOnChange: true
			if(contactSensors) paragraph "Current state of doors: ${areAnyOpen()}"
		}
        section("Notifications") {
            input "sendPushMessage", "capability.notification", title: "Send a push notification?", multiple: true, required: false
        }

	}
}

def installed() {
	initialize()
}

def updated() {
	unsubscribe()
	initialize()
}

def initialize() {
	def anyOpenDev = getChildDevice("DoorCheck_${app.id}")
	if(!anyOpenDev) anyOpenDev = addChildDevice("hubitat", "Virtual Contact Sensor", "DoorCheck_${app.id}", null, [label: thisName, name: thisName])
    if(areAnyOpen() == true) anyOpenDev.open() else anyOpenDev.closed()
	subscribe(contactSensors, "contact", handler)
}

def areAnyOpen() {
	def anyOpen = false
	contactSensors.each {
        if(it.value == "open") anyOpen = true
	}
	return anyOpen
}

def handler(evt) {
    //if(evt.value == "open") motionDev.active() else motionDev.inactive()
    if(areAnyOpen() == true) log.info "got here"
    //log.info "Contact $evt.device $evt.value"
}

Add some log.debug statements to see what is going on in the Live Logs. That usually helps pinpoint the issue.

Usually, I would use the "evt" data returned in the 'handler' to determine whether or not to update the child. I see what you're doing, though... and it seems like it should still work... :thinking:

Ok, is there one level deeper for the documentation? For example, how would this author know to use this to get at current light level:

luxSensors.each {total += it.currentIlluminance}

Is there source somewhere I can just look at?

Some of this is just how Groovy/Java works. I am definitely not an expert. The SmartThings Classic Documentation is a decent reference guide. Hubitat based much of their design on the ST Groovy model. This makes porting code easier.

1 Like

Here you go! Found it!

https://docs.smartthings.com/en/latest/smartapp-developers-guide/devices.html#getting-device-current-values

1 Like

EXCELLENT! Thank you so much @ogiewon!!! I hope to soon have my first true app, I've forked the hubitat public, so I can push it back once I have it working. I think it will be a good example to show notifications, and some other stuff.

1 Like

Just to be clear, this was all just me learning. I definitely will be using evt in the handler to update something, and to time things etc. :smiley:

1 Like

I don’t believe Hubitat accepts pull requests to their Public repository. You can ask @bravenel and @mike.maxwell for a definitive answer.

You can definitely add your code to the Hubitat Community GitHub repo.

5 Likes

Ok, I started my own little area for my apps for now. I will put them in the community when they're fully functional/baked.

But at least for now I have this door checker working pretty well. It has a stubbed out timer and notification. I need a way to "snooze" or cancel the repeat other than the doors all being closed as well.

Looks like the official notification app recently added this repeating as well, but for whatever reason my version of that official app seems old/stale/broken?

1 Like

Invitation sent...

Screen Shot 2020-05-22 at 4.15.23 PM

1 Like