Driver and app code examples


#22

Thanks for the pointers. Getting closer. Just need to read more and peck away... Groovy is just different enough from other languages I use that I need to simply spend some time with the syntax.


#23

@gavincampbell Finished my vent/temp balancing app, seems to be working well.

I appreciate your help. It is amazing what just a few pointers in the right direction can do in terms of moving things forward.

I still have a number of things to look into/read up on to make writing the next app a little more efficient, but full steam ahead. For instance I figured out the absolute value function, but didn't see a MIN or MAX function so just did it in conditional code. There may be a few other math functions that would speed up coding versus doing it the long way.

Thanks again!


#24

I remember seeing that in one of my drivers... this should help.

def onTime = Math.max(Math.min(onTime, 720), 8)

I've learned a lot by pulling apart other apps/drivers. I've also rewritten some of them as I found certain drivers were just done really bad and weren't working properly and some apps I wanted to add more features too. Most of my stuff is all custom written now and I know it inside out. I keep the features basic and add as I need.

The next thing you will probably want to look at is subscribing to device events. This is the fun stuff. Having methods launch when your contact is opened or a switch is turned on. Then you can get really creative.


#25

Just curious -

Anyone have a preferred groovy editor? I've just been using Notepad++ with a groovy language plugin. It works, but was curious what others use.


#26

emacs :smile: ... my text editor for everything, even docs LOL.


#27

I'd recommend IntelliJ from Jetbrains - the community edition is free and supports Groovy


#28

I just do it right in the web interface. Works well for me and is easy to quickly save and test code.

Its missing a few small features (I think there is no search and replace) but if I have to I just cut and paste to notepad and do the replace and paste it back.


#29

Example code can be useful when someone else has already done what I’m trying to do, but it can’t substitute for full documentation when I need to do something new.

Specifically, I’m trying to adapt a Cooper Aspire Scene Controller driver so that instead of associating with scene-capable devices, it sends button events to the hub. So far I’ve managed to get it to log button events (in the form of BasicSet and SceneActivationSet commands,) but I have no idea how to tell it to send these events to the hub.

For either of these types of commands the driver executes the following statements:

cmds << response(zwave.indicatorV1.indicatorGet())
sendHubCommand(cmds)

The ‘indicatorGet’ method is called in many places throughout the driver, but it isn’t defined there so I have no idea what it does. The ‘response’ method isn’t used anywhere else or defined anywhere; I put in some log.debug statements and found that this apparently returns the number 8702 regardless of which indicators are lit on the switches. The ‘sendHubCommand’ also isn’t defined anywhere, but I assume that’s something built into Hubitat — it’s mentioned in a community post from last October, but it isn’t documented.

I have a Simple Lighting rule that’s supposed to trigger when the first button on this scene controller is pressed. It isn’t doing anything, even though I can see the event being generated in the driver. So I’m pretty certain it’s a matter of sending the right command to the hub, but I have no idea where to start.

This is just a specific example. My point is to illustrate how the lack of adequate documentation hinders development, and that just relying on public driver code as examples is insufficient.


#30

Most, if not all of these can be found in the SmartThings developer docs API Documentation — SmartThings Classic Developer Documentation

The ZWave stuff requires you to log in with a Samsung or Smartthings account


#31

Is there any hope of getting generated docs for Hubitat instead of looking at the ST docs and hoping they are right? Since this is all groovy having auto-generated groovydoc for each release would be WONDERFUL. I don't even need comments, just knowing all the method signatures would be huge.


#32

Have you looked at the developer documentation at the following? It's not 100% complete, but compared to a year ago, Hubitat has come a very long way, IMHO.

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

Also, the Hubitat team welcomes help from the community to improve and complete the documentation.


#33

Sure, there is some stuff there but the vast majority of the API has no docs.

For example the Hub Update 2.0.3 release notes say that HubMultiAction has been added. Searching the wiki for that class gets me to Driver Object but it just mentions HubMultiAction as a return type with no information on how to use it.

Even HubAction isn't really documented. I have to go look at the ST docs to get an idea of how to use the API: HubAction — SmartThings Classic Developer Documentation


#34

I understand. Did you come from SmartThings originally? Or another platform? Or is Hubitat your first home automation hub?

For many of us that are SmartThings refugees, we sometimes take for granted our previous experience on that platform with the very similar API. I still pop back over to ST to check their documentation from time to time.

I can say that if you have a specific issue, which the community cannot help with, the Hubitat staff is usually very quick to lend their expertise to help developers sort things out. Just tag @mike.maxwell (drivers), @bravenel (apps), @patrick (dashboard), @bobbyD (support), or @chuck.schwer (platform). They are a great team to work with! :sunglasses:

Welcome to Hubitat!


#35

Coming from ST and more so coming from ~20 years of open source software development. I just feel bad poking on here constantly when I run into things that I feel like I could sort out if I could dig into the API docs.

Currently I'm trying to figure out why my ported ST driver threw an error. I posted a dedicated thread about it: Modify sendHubCommand from ST?