Energy items in the Device Details pane

Posted on
Sat Aug 31, 2019 9:23 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Energy items in the Device Details pane

I have been working on a plugin for some devices that can provide energy data (watts, amps, volts...) and show some of that in the Device Details pane. I looked through the online documentation and couldn't find anything, other than the mention of the Device Base Class Properties which mentions energyCurLevel, energyAccumTotal, energyAccumBaseTime & energyAccumTimeDelta and a short discussion of indigo.device.resetEnergyAccumTotal(). Then, in the Plugin SDK Energy Meter Devices.xml I found this cryptic entry,,,
Code: Select all
<!-- This hidden field forces property SupportsEnergyMeter to True
         which enables the energy meter states and UI.
         -->
         <Field type="checkbox" id="SupportsEnergyMeter" defaultValue="true" hidden="true" />

         <Field type="checkbox" id="SupportsEnergyMeterCurPower" defaultValue="true">
            <Label>Supports power load:</Label>
            <Description>Show current power load (Watts) in UI</Description>
         </Field>
However, nowhere did I find any information on how to actually update the 4 energy properties that can be displayed in the Device Details. Finally, after looking through a couple of other plugins, I figured out there are four magic states created, one for each energy property, and when these states are updated they actually update the 4 properties.

So, here is my question. Is this actually documented somewhere and I just missed it? Or, does it need to be added to the documentation?

Posted on
Sat Aug 31, 2019 9:40 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Energy items in the Device Details pane

It is documented in the Energy Meter plugin. That plugin is the best starting place for how to implement a device that supports energy/power states. For example the states are explained in the Devices.xml:

Code: Select all
         <!--
         Because the device above sets the SupportsEnergyMeter property
         to true, the device will automatically inherit the states:

            accumEnergyTotal (kWh)
            curEnergyLevel (W)      - only exists SupportsEnergyMeterCurPower is True
         ...

The plugin.py file then also shows those states being updated, as well as handling the device action callbacks related to energy/power status request and resetting (zeroing out accumEnergyTotal).

Ideally we would, of course, have it documented on the Web site as well, but for now the example plugin SDK is the way to go.

Image

Posted on
Sat Aug 31, 2019 9:47 am
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Energy items in the Device Details pane

matt (support) wrote:
It is documented in the Energy Meter plugin....

Thanks Matt. Given everything else you two are working on this is not a big deal. The only thing I would suggest is a comment, maybe in the energy example plugin.py like:
Code: Select all
# states are automatically created for each the 4  energy properties. The property is updated by updating the state.
Last edited by berkinet on Sat Aug 31, 2019 9:52 am, edited 1 time in total.

Posted on
Sat Aug 31, 2019 9:51 am
matt (support) offline
Site Admin
User avatar
Posts: 21417
Joined: Jan 27, 2003
Location: Texas

Re: Energy items in the Device Details pane

Agreed – I've now added some more comments to the plugin.py file.

Image

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests

cron