Updating attributes via http

I'm new to Hubitat and was looking for some best-practice advice on integrating a custom sensor device I've been working on.

As you can see, it's POE powered/connected ESP32 based board with a bunch of sensors attached (PIR, temperature, humidity, illuminance). Plan is to ceiling mount a collection of them around the place.

To get data out, the plan is to issue HTTP requests directly to the Hubitat hub to update temperature, etc attributes and trigger the motion command. I'm stuck on the best way to achieve this: I've tinkered with creating a custom device via the Drivers Code tab:

metadata {
definition (name: "Custom POE Motion Sensor", namespace: "me", author: "me") {
capability "Sensor"
capability "MotionSensor"
capability "IlluminanceMeasurement"
capability "TemperatureMeasurement"
capability "RelativeHumidityMeasurement"
}
}

def installed() {
}

The problem is I don't know how to update the attributes via the Maker API (or any other way) via HTTP calls.

Would love any suggestions on best approach here.

Welcome to Hubitat!

You might find my HubDuino project interesting. It handles all of the heavy lifting to establish local, two-way communications for devices exactly like yours!

2 Likes

+1000 for ogiewon's Hubduino. It's to goto for most of us using esp-Anything. You won't be disappointed.

3 Likes

Oh wow this looks like just the ticket. Thanks so much for your work.

1 Like

I did a little research regarding your Wesp32 board... Since I assume you’re planning on using the POE port for both power and LAN connectivity, I wanted to point out that HubDuino currently does not support LAN connectivity on an ESP32. It currently only supports WiFi connectivity on an ESP32.

It would most likely be possible to add support for the Wesp32’s POE port to HubDuino if that it desirable. If this is something you think you could handle on your own, I can provide you with some assistance and guidance. Usually I can add support for new boards relatively quickly, when I have a sample available for testing. However, the Wesp32 looks to be a niche product. Let me know how you’d like proceed.

1 Like

Ah bugger. Logically thinking, I believe I need to answer the question of "Can I (trivially) update attribute values on the Hubitat via HTTP?" before I can determine whether it's worth sinking the effort into full-blown Wesp32 Hubduino support.

You would have to define through the driver what to do with the information that is passed up to Hubitat. For example, if you call up to the device with the command "active" from the motion sensor capability, your driver would have to define how to handle that command. And that would be sending the hub event of active for the motion attribute. But even if you are only going to use the maker API, you would need to write a custom driver for the device that would define each of the commands you plan to send to hubitat with any data. That is a lot if you're not familiar with coding in Groovy.

If you go the hubduino route, the drivers are all done for you. The only thing you would have to work on is the Arduino coding.

Adding support in HubDuino should be fairly simple and straightforward. It only requires the addition of two files that abstract the actual network communications. If you look in my ST_Anything GitHub repository, you'll find an Arduino\Libraries folder. Within that folder, you will see a groups of folders names "SmartThings..." Each of these implements a specific network communications method. I would recommend you start with the SmartThingsEthernetW5100.h and .cpp as a starting point.

Hope this helps, if you decide to pursue the HubDuino option. I can take a stab at this once I have some free time, but you would have to perform all of the testing. In order for you to gain some familiarity with HubDuino, I would recommend you try using a standard NodeMCU ESP8266 or NodeMCU ESP32 board which are already supported in HubDuino. This would allow you to know what to expect during the testing.

yes, I do have the same question those days. I have a JSON file on my web server, and I would like to use this to update attribute values (custom driver) on the HE Hub, so the change will be showing on the dashboard ... Ideally, if maker API could support LOCAL HTTP POST then will be much more simple. Just a thought...

Why not simply use an HTTP Get call from Hubitat to pull the Json file from your Webserver?

When event triggered, my web server will get info through a HTTP Post. Then I would like to update the attributes real time. I don't like using pull to query as I don't know when things happened.

You can do this through the Maker API to your custom driver. Just send the command and the parameter. What kind of data are we talking about here?

That's the only way that I think could use Maker API now. When event triggered, I will run a URL using Maker API send the command (e.g. PullData), then my custom driver could update the attributes. The only concern is how I can pass the data from Python to Groovy, a JSON file saved on the disk?

I am talking about location data such as Latitude, Longitude, Geofence, place, and etc.

You can pass information to Hubitat via the maker API. It is NOT just commands. For example, you can pass dimmer levels. That is done passing passing the second value. See the example link in the Maker API documentation.

http://[IP]/apps/api/[APP_ID]/devices/[Device ID]/[Command]/[Secondary value]?access_token=[TOKEN]

You would pass the data you want to send in the secondary value section of the URL. So, in the case of Lat and Long (although i have no idea why you'd want to send that, you could do one call to send the Lat and one call to send the long. Or, your driver could parse them out when sent together. For example, you could separate the Lat from the Long by a carrot (^).

Thank you for the idea. Using Maker API [commnd]/[secondary value] could pass the data/attributes to HE Hub.

Download the Hubitat app