Webcore stuffing string list example fails

I'm trying to use the sample in this post and it is failing in two ways.

First, the testString doesn't include the name of the devices. It populates as

":Patio,:Garage,:Mmote,:Front,:Porch,:Hall"

rather than:

"Outlet 09E:Patio,Outlet 2EF:Garage,Outlet A80:Mmote,Outlet C20:Front,Outside River Temp 33A:Porch,Outside Street Temp 579:Hall"

Second, after I correct the first issue by hardcoding the device names, the strings variable doesn't get populated correctly. It shows as

{"*ALL":"Outlet 09E:Patio,Outlet 2EF:Garage,Outlet A80:Mmote,Outlet C20:Front,Outside River Temp 33A:Porch,Outside Street Temp 579:Hall"}

rather than:

{"Outlet 09E":"Patio","Outlet 2EF":"Garage","Outlet A80":"Mmote","Outlet C20":"Front","Outside River Temp 33A":"Porch","Outside Street Temp 579":"Hall"}

The piston log shows
6/13/2023, 11:35:17 AM +325ms
+30ms ║null
+35ms ║null
+39ms ║null
+44ms ║null
+49ms ║null
+54ms ║null

Thoughts?

Thanks in advance for the help.

If you think this is a bug or not operating as expected you can post over here:
https://community.hubitat.com/t/webcore-for-hubitat-updates

I'll take a look

@nh.schottfam Any thoughts about this?

webCoRE should handle

Listvariable = parseJson(jsonStringthat is a list)

You should be able to then access Listvariable[0], etc

I don't see that the code does this for a map type, but in general in webcore it has list types for most variables. device is a list.

So if you can accommodate a list, this should work or you can show me your example that gives you trouble.

The example you showed, that code was never accepted into webCoRE proper. I know there were concerns about the syntax reading the thread.

Let me explain what I'm trying to do and get your advice on best options. I have four power monitoring plugs. I periodically move them around my house to take power measurements of different appliances. I'm trying to calculate the cost of running various electrical devices.

I have two pistons that use the device locations. One shows information in tiles. The other logs information to a google sheet. Currently I've duplicated the location information in both pistons but I'd like to find a way to store that in a global variable for easier maintenance. The example I referenced (backup code fwy2d) would allow that.

I do have thoughts on other solutions but they are messier. One choice would be to have four global variables, one for each outlet, with the location and then use the global variable in the assignment in the piston rather than hard coding the location. I don't like that because it means the number of global variables grow by number of devices. I am not keen on that because I would like to be able to move to a new webcore instance without a lot of work and there is no way to export/import global variables (hint, hint).

Another choice is to have a single string holding locations based on the order of devices listed in the switches variable and then use arrayItem to get the location. I don't like this at all because the order of devices can change if I add, rename or remove a device.

Anyway, here are my pistons...


Thank of your advice.

Look at this piston:

Note the use of variables tile, Doors, Door and Doornames.

they show you can use 2 variables to express devices and the names for any number of device/names, you want to use for the devices (assuming you do not want to use the device names themselves).

You could consider 1 piston has the definition, and it writes the definition values to a Global or hub variable that both pistons otherwise use...

I'm sure there are other ways...

Thank you.

Although this approach works, I'm not a fan because renaming a device or deleting a device often causes the labeling to be wrong. And it doesn't generate any errors so it is just silently wrong.

So a couple of things

You can put devices in the global variable

If you just want the device name from the device, you don't need a second variable of names. You only need this if you wish to override the name.

If you are not triggering on the devices, then you can just edit the global and things should work. You can use the device variable as you would any device variable.

If you are triggering, when the device list is changed, the piston using triggers needs to be paused/resumed (it does this when you edit it), so that the subscriptions are updated.

Will the triggers get reset if I reboot Hubitat?

they persist across a reboot, so they are not 'reset'.

What reset's trigger subscriptions is pause/resume (resume is what happens after you edit/save a piston).