Labs: SmartThings Health and Battery Reports

I’m playing with the Battery check lab. Am I able to filter items out in the textSummary context or only the items context?

If I need to use the item context, can I then format it to read more like the textSummary format with only the device name and battery %?

Yes, in the example above, the last line is doing two things:

  1. The map() is mapping the detailed item to only display the item.name
  2. It’s joining all of the filtered items (which have been remapped) into a string with a comma and a space between them

So you could modify the map() part to combine whatever parts of the item together as you see fit.

Here’s the same thing but with those last two steps split out and the map() step concatenates a string together as you alluded to:

items = $context.response.data.items
exclusions = ["Motion Elliot"]
filteredItems = filter(items, not(contains(exclusions, item.name)))
formattedItems = map(filteredItems, concat(item.name, " (", toFixed(isEmpty(item.batteryLevel) ? 0 : item.batteryLevel), "%)"))
join(formattedItems, ", ")

I added some fallback checks to the example as I had some battery levels that were reporting as ‘null’ which was throwing things off.

I finally had time to come back and play with this. Thank you for the help Josh.
I do have another question.

I am using this expression

items = $context.response.data.items
exclusions = ["SmartTag Keys","Hub 2 Master","Hub 2 Living Room"]
filteredItems = filter(items, not(contains(exclusions, item.name)))
formattedItems = map(filteredItems, concat(item.name, "-", toFixed(isEmpty(item.batteryLevel) ? 0 : item.batteryLevel), "%"))
join(formattedItems, "\r\n")

I would like to filter the device list further by the value returned. For example, is battery level between 30-60. Is there a way to set the threshold using isBetween, can I use exclusion based on battery level returned, or do I need to use the filter function?
I’ve tried several variations and keep getting an expression error.

I would supply the upper threshold as part of the URL, then you could filter the list multiple times as needed.

Something like the following:

items = $context.response.data.items
exclusions = ["SmartTag Keys","Hub 2 Master","Hub 2 Living Room"]
filteredItems = filter(items, item.batteryLevel > 30)
filteredItems = filter(filteredItems, not(contains(exclusions, item.name)))
formattedItems = map(filteredItems, concat(item.name, "-", toFixed(isEmpty(item.batteryLevel) ? 0 : item.batteryLevel), "%"))
join(formattedItems, "\r\n")

Note that on the first pass filter, we’re just filtering on the batteryLevel and assigning that to filteredItems, so in the second pass filter we need to further filter the filteredItems based on the named exclusions (rather than the original items).

Using what the expression you suggested results in an expression error.
I had to reverse the filteredItems lines.

items = $context.response.data.items
exclusions = ["SmartTag Keys","Hub 2 Master","Hub 2 Living Room"]
filteredItems = filter(items, not(contains(exclusions, item.name)))
filteredItems = filter(filteredItems, item.batteryLevel > 55)
formattedItems = map(filteredItems, concat(item.name, "-", toFixed(isEmpty(item.batteryLevel) ? 0 : item.batteryLevel), "%"))
join(formattedItems, "\r\n")

Nice! Thanks for the update.

The order shouldn’t matter unless the items being excluded by name are missing their battery value altogether. In that case, the system would have tried to run the filter expression and failed if the batteryLevel on any of the items you wanted to exclude by name were missing their battery level. Swapping the order to filter out those items without a reported battery level would fix the issue as you noted. :slight_smile:

1 Like

Hi mate. My pushover notifications have started to just say this now. I haven’t changed anything within this rule. Is this a bug or something?

Here is my set up

Thanks

We pushed an update intended to better align the Set Variable command with the value type that is stored with the action.

One thing we’ve noticed is that if the variable was originally created as a different type (eg. true/false), and a Set Variable action was created at that time, then the variable was later deleted and recreated, if the Set Variable action wasn’t modified it might still have the original target type of true/false rather than text.

That did it mate, thank you once again.

any way to add another endpoint for status == open.

this would help the scenario posted here

which is essentially check all my contact sensors and let me know what is open

Hi @matt_schuett welcome to the community and thanks for posting. These labs endpoints are specifically designed for the health status and battery features and don’t offer the ability to specify arbitrary capabilities + attributes + values to check for.

If you’re interested in that particular feature, I would recommend casting a vote on it. Community feedback is a key part of how we prioritize what to work on and the number of votes a feature request has on it is one of the factors we consider. :slight_smile:

Sorry to bump this but sometimes my pushover is giving me this error when it checks if something is offline or not. Other times it will work.

Bump. :slight_smile:

Hoping someone has a fix for this?

It looks like the SmartThings server is returning errors at an elevated rate compared to before. Copying in a reply from another discussion:

Unfortunately, if SmartThings is having some sort of issue with their API servers that introduced this intermittent type of issue, it’s even more likely to occur with this Labs healthcheck endpoint as it’s aggregating multiple API calls to SmartThings.

It makes an initial request to SmartThings get the list of devices, then individual requests for each device to get their health status before returning that as a single response.

So if any of those requests experience this issue, then the whole response fails.

I was hopeful that it would get resolved on the SmartThings side of things, but if it continues, I’m open to trying some sort of retry/backoff. With this type of aggregated sub-query approach, it can get a bit tricky to decide what to backoff and when. This gets particularly complicated since requests are made in parallel for efficiency. :slight_smile:

Hi Josh,
I’m jumping on to this thread because it started by assuming everyone knows how to get the SmartThings token required and then how to use it. Once I see a simple example rule on how to use the labs health check routine I feel confident to be able to modify its use to requirements. It’s just basic building blocks I’m struggling with.
Forgive me if this appears elsewhere but have tried searching other threads and articles but I’m still stumped getting started.
Thanks in advance,
Bob

This works for my SmartThings devices. Is there a way to do the same for Hubitat devices?

Just trying to make this work but your link to get the Personal Access Token tells me that these only last for 24 hours. Is there some alternative way to use to use the health check tool now?

It looks like you might have found it based on your follow-up post, but the original post links directly to the page for creating a Personal Access Token.

Per the following SmartThings community thread, it looks like SmartThings shortened these from being long-lived tokens to just 24 hour temporary use tokens. :confused:

Anyone with an existing Personal Access Token (PAT) seems to be grandfathered in and those keep their original long life, but the newer tokens are the short 24 hours.

Unfortunately, I don’t have an immediate solution in mind so I’m open to feedback from the community. It looks like the recommended approach is not to use an OAuth integration which is what we use for the SharpTools platform level integration… but this Healthcheck tool was explicitly intended as a “Labs” type of feature - something we could quickly get out to help the community without it needing all the rigor related to a tight production-level integration with our main platform. In other words, more of a community-supported type of initiative than an official release.

It seems like a big effort for each individual to have to create their own OAuth integration, so I’ll need to think about what we do here. I don’t really want to make this an official integration, but putting together a management interface for separately authenticating ‘labs’ experience would require quite a bit of effort. :thinking:

Check the last section of the original post.

Thanks Josh. I guess that will have to go on the back burner for now then.