Create a simple? Button

I’m still trying to get my head wrapped around the way Hubitat works. For some reason it just isn’t clicking for me.

Anyway, how would I create a simple on/off button that sends a UDP command? Would I need a driver, an app, or both?

For example, if I wanted to send the equivalent of:

udp://192.168.0.9:8899/0x460055

With a button press I see the following:

// Send UDP Message
new HubAction("My UDP Message", Protocol.LAN, [type: HubAction.Type.LAN_TYPE_UDPCLIENT])

How would I setup the button to add the action?

I hope that makes sense. Right now there is a fundamental gap in my understanding. :wink:

How you implement this would be up to you. You can create a driver that sends the hubaction based on one of it capabilities. For example, it your driver has the switch capability, you can have it send on "On".

You can also write an app that subscribes to a device and have the app send the hubAction based on...well..whatever you code to send on.

The driver approach would allow you to include the virtual device in any automation based on its capabilities.

The app approach might give you more flexibility...it all depends on what and how you intend to use the update command.

Thanks, but I do get that part.

I’m stuck on where to begin. I see the developer documentation but it just lists all the commands. So far I haven’t seen any practical samples and literally would like to setup an app that only has an on button and an off button to get a feel for the system.

I copied a random driver into the custom section and started poking around. I tried to insert a HubAction but it failed. From the logs I found that this is a command for the apps (or so it seems).

It is a simple beginning but it isn’t clear how to proceed. Is there any example code anywhere? I can take other code and start hacking around but the little edit window drives me nuts.

Eventually I’ll sit down and pull apart somebody’s code but it would be helpful if there were a simple sample showing basic syntax and what is minimally required.

A basic driver that uses hubaction is @ogiewon's Http switch. It's not a udp hubaction but can give you an idea

I also use hubaction with my WOL app

There are quite a few ways to do this and I'm far from an expert but hopefully these 2 simple examples are enough to get you started.

Perfect, that’s what I was looking for. There’s enough there to jump start the process and not too much to confuse the issue. Unfortunately the second example is returning a 404 but the first is enough to get me going.

There is one piece that I don’t understand,

def headers = [:]

What does the [:] reference do?

Thanks for your patience and examples. :blush:

So, is the language Python? And the line in question creating an empty slice (array)?

I’ve not worked with Python so I see I have a few bits to pick up.

Oops, I see the .groovy in the paths of the examples so I guess this is Groovy. Still new to me. :wink:

Yes this is groovy. I'm not a programmer but I have learned groovy over the years making appd and drivers for Smarthings and now Hubitat. [:] references a map. Google "groovy map" and I think you will get what you need.

The second link doesn't work because of a new hiccup with Discourse not formatting url's correctly (@bobbyD any update on this).

See the url below.

Hubitat/apps/Boot Me Up Scottie/Boot Me Up Child.groovy at master · stephack/Hubitat · GitHub

Thanks again. This is just what I was looking for.