Learning how to write variable code


#1

I have no coding background so need some help or resources for understanding how to write this please.

I want to create a variable deviceList and another deviceName (to use shorter names when sending notifications) and save active devices to another list activeDevice but call the shorter names (deviceName) vs device name (deviceList)
Example
device deviceList AAA, BBB, CCC
device deviceName A,B,C
string activeDevices (no value set)

I can not figure out how to write this.
I tried
IF trigger happens
for each $device in {deviceList}
set variable {activeDevices} = {activeDevices},{deviceName} + $devices

But that didn’t work. I found a lot of examples but no actual explanations of how to write this. Any suggestions or links to learn from (for someone with minimal coding knowledge) is much appreciated!


#2

There is a easy way to do this that is built into a condition/trigger. Example piston below when any of the switches turn on, the on switches get saved into the activeSwitch variable.

The coding is done when adding your condition/trigger to the piston. The option to save to variable is hidden by default, click image to open those options.


#3

Please correct me if I’m wrong, but if I save matching variables to a list, that list still uses the full device name vs a shortened name correct? My goal is to call the shortened names for the push/sms/tts message.
i.e. front door open/close sensor shortened to front door


#4

Apologizes for missing that point in your post. You can actually use indexOf to match the active device to a device name. You’ll need a string variable with your preferred switch names in a list that correlates with the device list.

Updated the above piston for reference. The presence tile piston is also a good example of an alternative method using $currentEventDevice rather than saving the active device to a variable. https://wiki.webcore.co/Samples#Presence_Tiles