Labs: SmartThings Health and Battery Reports

Thanks for this.
So I’m not the best at this so a little help would be great.
I’ve managed to get the token from Smartthings and the http example to check the health of my devices.

Now what do i have to do in order to get a notification sent to my phone if any device goes offline? I use push bullet and can successfully get notifications so I have that part set up but I don’t know how to create a rule to make this work.
Can anyone help?
Thanks.

The HTTP Action help article has some good insights:

:page_facing_up: HTTP Rule Action - SharpTools Knowledge Base

As noted in the original post, the textSummary property is the easiest one to use as it has a human readable list of device names that you can use directly in notification.

So a basic example might look something like the following:

Per the written instructions above, here’s how we access that textSummary variable:

I would note that this is a simple example that always sends the notification every day at the specified time regardless of if there are devices offline or not. I would start with that just to make sure you’ve got the basics down.

Once you’ve got that, you could add some logic if you’d like. For example, some people will add an IF Condition and will only send the notification if there’s content in the textSummary (eg. if there are offline devices). Other people like to use more advanced features like filtering on the list of offline devices to exclude certain device names or other things which requires expressions as demonstrated further up in the thread.

2 Likes

Thank you so much mate I got this working. :slight_smile:
I just have one last query and I see there’s another post about it but I’m unsure on where to add any of this into the rule. So I have around 4 devices that I’d like to filter out and not notify me when offline. Do I add this onto the same rule, and how would I go about doing this? Like I said, I’ve seen the other post about this but really unsure on exactly where to add this.

Edit : is there a way to have this trigger every hour or so rather than daily, or would I have to create more duplicate rules and simply change the times on them?

Thank you.

You would use a Set Variable action and choose Expression for the source. Then use the snippet mentioned in the thread further above to filter things… then use the value from the variable you set in your notification.

You can add multiple Timer triggers to a single rule. We don’t currently support ‘Every XX hours’ type of triggers. Some community members have come up with creative approaches to accomplish that, but it’s not something we officially support or recommend.

Thank you.
So I have to take this out now? Does that go somewhere else now?

I also don’t see expression variable. Sorry.

Check the screenshot from my post. What it’s doing is using the Set Variable action where you will set a variable based on the result of an expression.

This comes after the HTTP Action in your rule flow since the expression needs the value from the HTTP action… and it comes before your notification (or IF Condition) since the notification or condition needs the result of the Set Variable action.

So you select Set Variable as the action, select the variable you want to store the result in (or create a Text variable first and then select it), then tap the Expressions tab as shown in my screenshot in the source, then fill in the expression based on my example snippet further up in the thread.

Keep in mind that using expressions is a bit of an advanced feature, so you can’t always just copy-paste… in this case, you would need to change the values in the exclusions section of my sample expression from above.

You would use the variable that you used as the target in the Set Variable action since that has the filtered list of device names.

Sorry mate I’m really stuck. Far too advanced for me.
I’ve no idea what I’m doing here unfortunately:(

Here’s my attempt at it and I know it’s clearly wrong but hopefully you can tell me where I’m going wrong.
‘Big Mo’ is an openclose sensor that id like to exclude. I have 3 more devices Id like to exclude but trying with one for now. It says invalid variable.

Thanks.

I managed to suss it out. I don’t know how but I did.

Thank you for the help mate :ok_hand:

1 Like

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: