batteryLevel question

Posted on
Wed Feb 21, 2018 1:05 pm
racarter offline
User avatar
Posts: 468
Joined: Jun 18, 2016
Location: North Yorkshire, UK

batteryLevel question

I have a problem with the device state batteryLevel green bar not showing on some devices.

I have a plugin which creates and updates Indigo devices based on a json response from a server. The json data includes readings from several different types of battery-powered module, and I have one of each of most of them, but three of one type. All battery level bars on the single modules are shown, but the battery level bars only show on the first of the three same-type modules.

I've read here:

[url]wiki.indigodomo.com/doku.php?id=indigo_7_documentation:device_class[/url]

that "Some properties, such as batteryLevel, only exist on the main/root device" and I wonder if that has something to do with it (although I don't see why it should).

The same code processes all modules of one type, and the batteryLevel state shows up if I list the devices and their states using the Utilities plugin. Any thoughts as to why the green bars don't show?

Posted on
Wed Feb 21, 2018 2:29 pm
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: batteryLevel question

Can you post screen captures of the device that is showing the level versus the one that isn't?

Image

Posted on
Wed Feb 21, 2018 2:56 pm
racarter offline
User avatar
Posts: 468
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: batteryLevel question

Hi Matt

Not sure exactly what you're after, but:
Attachments
without.jpg
without.jpg (19.17 KiB) Viewed 1658 times
with.jpg
with.jpg (24.99 KiB) Viewed 1658 times

Posted on
Wed Feb 21, 2018 5:01 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: batteryLevel question

Are you using a device group for the three devices or are you creating three individual instances of the device type?

Screen Shot 2018-02-21 at 4.46.58 PM.png
Screen Shot 2018-02-21 at 4.46.58 PM.png (61.21 KiB) Viewed 1631 times


That guidance is for device groups:
getGroupList() is useful to get the main/root device of a device group. Some properties, such as batteryLevel, only exist on the main/root device. In this example we log the batteryLevel for a module given any devices that belong to its group:

Code: Select all
groupList = indigo.device.getGroupList(devIdOrInstance)
rootDevice = indigo.devices[groupList[0]]
indigo.server.log('battery level is: ' + str(rootDevice.batteryLevel))


Suggests that the battery level will appear in the Indigo UI for the main device (root) of the group and recommends that the battery levels of the child devices be written to the log. You can do that by accessing the elements of groupList[n], where n = the index of the device in the group.
Code: Select all
indigo.devices[groupList[0]]
indigo.devices[groupList[1]]
indigo.devices[groupList[2]]
indigo.devices[groupList[n]]

Matt or Jay would have to say why it's the case that some props only show up for the root device.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Feb 21, 2018 5:36 pm
Colorado4Wheeler offline
User avatar
Posts: 2794
Joined: Jul 20, 2009
Location: Colorado

Re: batteryLevel question

Now Dave that is some spiffy bit of coding right there that I had no idea existed, I had been using logic to get the related devices because they always have the same address! Nice! Also, did you code that device with the submodels? If so I definitely want to learn that trick!

My Modest Contributions to Indigo:

HomeKit Bridge | Device Extensions | Security Manager | LCD Creator | Room-O-Matic | Smart Dimmer | Scene Toggle | Powermiser | Homebridge Buddy

Check Them Out Here

Posted on
Wed Feb 21, 2018 6:44 pm
racarter offline
User avatar
Posts: 468
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: batteryLevel question

Three separate devices Dave, each with their own address.

Posted on
Wed Feb 21, 2018 7:09 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: batteryLevel question

Colorado4Wheeler wrote:
Now Dave that is some spiffy bit of coding right there that I had no idea existed, I had been using logic to get the related devices because they always have the same address! Nice! Also, did you code that device with the submodels? If so I definitely want to learn that trick!

No credit due me, that's for sure. The group device is built off the Indigo SDK and the the code block is from the Wiki. But the cutting and pasting is all me. :D

(The example grouped device above is from my development environment, but the base is SDK.)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Wed Feb 21, 2018 7:15 pm
DaveL17 offline
User avatar
Posts: 6742
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: batteryLevel question

racarter wrote:
Three separate devices Dave, each with their own address.

Can you run the following code against each device and post the log results (careful to not post anything private)?

Code: Select all
dev = indigo.devices[dev_id]
indigo.server.log(str(dev))

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Feb 22, 2018 3:39 am
racarter offline
User avatar
Posts: 468
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: batteryLevel question

DaveL17 wrote:
racarter wrote:
Three separate devices Dave, each with their own address.

Can you run the following code against each device and post the log results (careful to not post anything private)?

Code: Select all
dev = indigo.devices[dev_id]
indigo.server.log(str(dev))


@DaveL17

I've attached the result, showing first the device which shows the battery level, then the device which does not. The problem seems to be that the second and subsequent devices are not showing the SupportsBatteryLevel preference in globalProps, even though the device definition (also attached) is the same for all. As you can see, batteryLevel appears in the list of states for both devices.
Attachments
devs.xml
(2.91 KiB) Downloaded 85 times
log.txt
(2.98 KiB) Downloaded 78 times

Posted on
Thu Feb 22, 2018 7:31 am
matt (support) offline
Site Admin
User avatar
Posts: 21411
Joined: Jan 27, 2003
Location: Texas

Re: batteryLevel question

racarter wrote:
The problem seems to be that the second and subsequent devices are not showing the SupportsBatteryLevel preference in globalProps, even though the device definition (also attached) is the same for all.

I think you are correct. Were the devices that don't show it created before you had SupportsBatteryLevel added to the ConfigUI? That is, does the battery level show up correctly on all newly created devices? You have to add logic on the .py side to manually set that device property if it is added after some devices might have already been defined without it.

Also note you should not be including the batteryLevel state in your devices XML. That state will automatically be added by Indigo when/if SupportsBatteryLevel is True.

Image

Posted on
Thu Feb 22, 2018 7:50 am
racarter offline
User avatar
Posts: 468
Joined: Jun 18, 2016
Location: North Yorkshire, UK

Re: batteryLevel question

Thanks Matt, I'll remove batteryLevel from Devices.xml.

The devices not showing battery level were created AFTER the one which does, not before, and no code had been altered between the additions.

I've included code to add 'SupportsBatteryLevel = True' to the device prefs and they're now all showing the battery bar, but it's still a mystery why those prefs weren't set up correctly on creation.

The devices have dependencies so I'm reluctant to delete and recreate them, but when I have time to spare I might try it to see if the problem is still lurking in the background!

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 3 guests

cron