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.
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...
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.
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.