The energy monitoring device I use just released there first api.
Seeing the data I get from a http-get request, it looks like a driver for this device should not be that hard to create. That sayed, I'm not a coding star, so will need som help, pointing me in the right direction.
When I make a http-get request to the device itself ( http://{IP address}/api/v1/data ) I'm getting a nice result set:
Please feel free to take a look at my custom driver for the IoTaWatt power monitoring device. It should help get you started with a possible design to achieve your goals. Good luck with your project!
It was still pretty easy to read (especially with Google translate :)).
There's really only one API call supported, unless you want the raw data from the meter.
I took a stab at supporting it as a PowerMeter in Hubitat. Your version of the meter seems to update its power reading every 1 second, but I made the default refresh rate 10 seconds. The API document says not to poll any faster than twice per second.
Do you need access to any of the other readings, like cumulative power or instantaneous power for any of the individual phases? Those could be added using custom attributes, and they would be a good way for you to experiment with driver development if you are interested.
Looking good Tomw.
looking at your code in detail, and trying to grasp what you are doing with each line of code.
If I understand correctly, with the line sendEvent(name: "power", value: res?.active_power_w?.toInteger()) you define the "active_power_w" result as an integer?
The toInteger() is, at least to me, conceptually similar to a reinterpet_cast in C languages. sendEvent is a Hubitat platform function call that sets the current value of an attribute and also logs an event with the system.
For example, you may want to use SignalStrength for the Wi-Fi signal, though for the record the value reported as 100 seems suspect and in different units than either rssi or lqi, which are the attributes supported by SignalStrength.
If you want to support an attribute that is not part of a built in capability class, be sure to declare that attribute in the driver definition section like I did with commStatus. Then you can use sendEvent like you did with total_power_import_t1_kwh
I haven't used the units functionality with events personally, but maybe you can get it to do what you are looking for. Please share results here if you figure it out.
If I use the default sendevent, I do not have the chance to define the unit type: sendEvent(name: "total_power_import_t1_kwh", value: res?.total_power_import_t1_kwh.toInteger())
If I use a defined unit in the sendevent, it wil not return the units: sendEvent([name: "total_power_import_t1_kwh", value: res?.total_power_import_t1_kwh.toInteger(), unit: "kWh"])
Need to look at more existing code to get an idee how to define custom displayable units.
This is a good option is you only want to display the value with units. Make the whole attribute a string. It isn't a good option if you need to make numerical comparisons with the measurement, for example in Rule Machine automatons.