Using a variable to define a variable / routine


#1

Hi folks.

A bit of a strange question but I wonder if Webcore allows defining a variable with a variable? Probably best if I explain what I want to achieve to make it simpler:

I have a number of AirBNB properties which themselves have a number of rooms in them.

Each of my properties is defined by a 3 character code, ie RB3
In each of my properties each room is defined by a 3 character code, ie RB3BR1 defines a bedroom in RB3
In each room each device is defined by defice ie: RB3BR1Lock, RB3BR1Heat RB2BR1Light and so on.

For each room I have a variable defined ie @RB3BR1Status which will be able to hold a number of values, ie. PreCheckIN, CheckedIN, CheckedOUT, Dirty, Clean, Maintenance and I set the variable accordingly. Most often the piston is executed by looking for a Routine, ie RB3BR1Unlock

I have a piston called RB3BR1RoomManagement which executes and changes parameters for RB3BR1Lock, RB3BR1Heat. As I have multiple rooms in my piston I define a variables called Lock, Heat and so on so that when I repeat this piston across multiple rooms I can simply define the Door Locks and Heaters in these once and it applies all through the piston.

What I want to do now however is to be able to build my variable RB3BR1Status from variables in the piston but of course this will be using Set Variable but the result of another variable to choose the one that I want to set.


#2

What do you want to do with the Status variable once it is set?

I have a piston that builds a message everyday based on the status of selected items like battery level, lights left on, temperature, weather forecast. I got the idea from:

This uses a series of if statements to determine what to report but I get the impression that you just want to combine all your current variables into one status string variable. If so, I would do it using an expression:

“RB3BR1 Status:
" RB3BR1Lock”,
“RB3BR1Heat”,
"RB2BR1Light

and so on (note: line breaks with quotes will result in a line break in a push/sms message)

or if you only want to see a variable under certain conditions, for example, only if locked, otherwise no entry
if(RB3BR1Lock==“Locked”,“Locked”,"")