Anyone using the Battery Monitoring app from the applications list successfully?

I have finally got the battery monitor working and set up a tts if low battery list is > than 0
Might any one be able to help with the next step of staying the device name in the Low Battery column in the tts announcement?
Current Tts below
luup.call_action(“urn:micasaverde-com:serviceId:Sonos1”, “Say”,
{Text=“Check battery Levels”, Language=“en”, Volume=75},
601)

You can use expression variables in Reactor to split the list of devices and pull the name. Use another expression to create the message string, and use that variable as the Text parameter for TTS.

Your > 0 test is a bit shaky: the variable value is a list of device numbers, so if it contains, for example “109,431” it will not parse to a valid number and the test will fail. I’m not sure what the value is when there are no low battery devices to report, but if it’s blank, just test that it’s not an empty string.

I’m traveling for the rest of the week, so maybe others can take a stab at the variables/expressions. Hint: there’s a split() function that will take a list string and make an array out of it (breaks on comma by default).

I am not sure on how to proceed with the split(“”) operator then covert the string into names for input into tts output. As you can see below empty list returns 0 and populated list returns sting values.

Putting those strings through split() will return an array (Lua table). The simple “0” string will be converted to an array containing the “0” string as its first and only element. The second example (your screenshot) will be converted to an array of 17 elements (if I’ve counted correctly).

The device name be retrieved using the getattribute() function, which retrieves the value of any of the Luup device attributes (of which name is one): getattribute( devnum, "name" )

I’m not sure what your goal is from there. If you want the device names for all of the array elements, it’s a simple matter to use iterate() and getattribute() together to create an array of names:

battlist = split( getstate( 891, "urn:upnp-org:serviceId:BatteryMonitor1", "LowDeviceList" ) )
battnames = iterate( battlist, getattribute( _, "name" ) )

The iterate() function goes over all the elements of an array (first argument) and evaluates an expression (second argument) against each element. So in this example, iterate() runs getattribute() 17 times, once for each array element. The result value of iterate() is a new array containing the values that result from each run of the expression. More on iterate() can be found in the LuaXP built-in functions docs.

Finally, you can use the join() function to turn the array of names into a string: join( battnames, ", " )

My goal is as follows:
Check if lowdevicelist is populated then grab all deviceid, conver to names the pass into tts to send to Sonos app for audible please check battery for device 1,2,3

Add: ttstext = "Please check batteries for " + join( battnames, ", " )

You can send that string to your TTS. Also, note that there is a space after the comma in the join() call’s second (string) argument. Not sure that’s needed, but it may help the TTS read the list properly.

Thanks Rigpapa,
I now have the desired array output (ttstext), I notice that this is held in reactor variables but I am not sure of the appropriate way to call this into the tts command
luup.call_action(“urn:micasaverde-com:serviceId:Sonos1”, “Say”,
{Text=“Check battery Levels”, Language=“en”, Volume=75},
601)

Don’t use a Run Lua action, use a device action on the Sonos and select the “Say” action, then provide the parameters as needed. For the Text parameter, choose ttstext from the menu (click twice in the empty Text entry field), or enter {ttstext} into the field directly.

I see, much more user friendly, very cool… I now have a reactor setup with the following expressions and conditions

battlist

battlist = split( getstate( 891, “urn:upnp-org:serviceId:BatteryMonitor1”, “MidDeviceList” ) )

[“685”,“538”,“192”]

battnames

iterate( battlist, getattribute( _, “name” ) )

[“Swipe1”,“Front Porch Wallmote”,“BMW Garage”]

ttstext

"Please check batteries for " + join( battnames, ", " )

“Please check batteries for Swipe1, Front Porch Wallmote, BMW Garage”

and the following actions

This might be nit picking but any way to add an “and” just before the last read tts device
but would polish off this scenario nicely
e.g Please check battery for Swipe1, Front Porch Wallmote and BMW Garage (number of devices in this list may change or may also be only 1 device not requiring an “and”)

I have observed that when there is a null value returned (e.g when no devices are listed in LowDeviceList the reactor places the error exclamation mark on the reactor but in this case it is expected
image

Does Battery monitor still work? I can’t seem to get it to update even though I run a scene every 4 hours. Please help!!