Battery capability?

In the capability taxonomy there is a “battery” capability listed which includes the “battery” attribute but there isn’t any guidance on how this should be set?

Does it need to be numeric to represent percentage values or can it be set to string values like “OK” and “Low”?

How can I set it in such a way to make sure the rest of ST will react to it appropriately?

What would you be setting for the battery cap?

This is to allow smartthings to alert you of low battery from device types. I’m interested to know what other uses there could be. Not knocking it, truly interested what your idea is.

The Vista alarm panel will tell you when it’s backup battery is low, plus the battery powered sensors will report when the battery is low. I don’t get numeric values, but just low battery warnings. I figured this could be used by the ST low battery warning app if I knew how to set the data.

While you’re digging around the battery object, do you think it is possible to list all the battery levels of all the devices? This has always been one of my pet peeves:

@beckwith, I’m not sure if your question was aimed at me. In my case, the ADT sensors don’t report their level, All they report is OK or LOW but I’d like to report at least that much.

I would think about adding a custom “attribute” to your device type instead of using battery. I think this will work better for you in the long run. If you need and idea of how to add attributes take a look at the netatmo weather station device. Tons of attributes in the device type and you can subscribe to attributes and as you would a capability. Hope this helps :slight_smile:

I’ve already had to add some custom attributes so that’s not a problem, but it seems like it would be better to be a well-behaved ST citizen in order to participate in other smartapps. It’s just not clear wha the specs for that attribute are.

Got ya. The values are just 0-100%. I can look at a few of my device types later as well but I think it’s just a value that’s passed and nothing special. (I honestly forget exactly right now)

take a look at the smart multisensor stock code. That should give you some clues.

I’ll report back with my findings as well later today.

Thanks, Tim, much appreciated!

My original thoughts were correct. It quite literally is a 0-100 level. See this snippet of code for some more details. Basically creates an event with device, name, value. Hope this helps.

private getBatteryResult(part, description) {
	def batteryDivisor = description.split(",").find {it.split(":")[0].trim() == "batteryDivisor"} ? description.split(",").find {it.split(":")[0].trim() == "batteryDivisor"}.split(":")[1].trim() : null
	def name = "battery"
	def value = zigbee.parseSmartThingsBatteryValue(part, batteryDivisor)
	def unit = "%"
	def linkText = getLinkText(device)
	def descriptionText = "$linkText Battery was ${value}${unit}"
	def isStateChange = isStateChange(device, name, value)

	[
		name: name,
		value: value,
		unit: unit,
		linkText: linkText,
		descriptionText: descriptionText,
		handlerName: name,
		isStateChange: isStateChange,
		displayed: false
	]
}

Thanks! Based on that I should probably keep my low battery warnings in a custom attribute since they aren’t numeric.

I agree.

Interested to see what your working on with your alarm panel. :smile:

I’ve created custom device types for the contact, motion and smoke detectors used on the system that was in the house we bought a bit over a year ago. I also created a custom switch to control the chime and another for the arming and disarming. Also, a custom contact sensor to indicate if the alarm panel is on ac or battery power which should be a good proxy for a power failure. My last device type is one to track whether the alarm is sounding or not and to allow it to be triggered from the phone.

It’s all tied together with a smartapp that routes events appropriately. It communicates with a small mac app that talks tot he panel with an ad2usb.

Once I finish the last device type it should be completely functional except for the low battery warnings. I’ll need to think about that some more. And I may put some UI in the smartapp to bring the various components together in one view.

I started coding last Friday I think so I’m pretty happy for a week’s worth of work! Our daughter’s dog, though, he’s not so happy. He doesn’t like the alarm at all. :smile:

1 Like

I think keeping with the ST battery management is a good idea. From my logs, it appears that ST will alert you when a battery hits 13%, and again when it hits 3%. So your LOW would likely be equivalent to 13%, if you wanted to go that route…

I would prefer to have it integrate with ST’s battery management though I’m not keen on using a number that’s subject to change as they refine their system. I can probably handle the notifications in my top level routing app and get the same effect.

Maybe ST can modify their battery checking code to look for OK and LOW in addition to numeric values. That would be ideal!