Page 1 of 1
Connected/disconnected to one of a list of bluetooth devices
Posted: 20 Oct 2019 21:44
by rubaboo
The problem: I drive more than one car, and I'd like to set
when I connect to any of the cars, and
when I disconnect from any of the cars. So, I'm thinking I would trigger Bluetooth Device Connected (or Disconnected, accordingly) and then check if the device name is one of the names in a global list. But I don't see any function that would tell me if a string is in a list. Do I need to loop over the list to find out?
The alternative is to maintain two multiple trigger conditions, one for Connected and another for Disconnected, but I thought sharing a list between the two would be neater.
Re: Connected/disconnected to one of a list of bluetooth devices
Posted: 20 Oct 2019 23:26
by rubaboo
Looked into it some more. Now I'm thinking it should be a trigger Bluetooth Device Connected (any), followed by a condition Bluetooth Device Connected, where I save connected_device_names to another variable, and then a script to find if connected device list and car device list intersect. What is the scope of connected_device_names variable, is it available in subsequent actions or only within the Bluetooth Device Connected condition? And how do I script finding if the intersection of two lists is empty or not?
Re: Connected/disconnected to one of a list of bluetooth devices
Posted: 21 Oct 2019 05:51
by rubaboo
I solved it. Here is the flow and the script. The "False" branch is mainly for clarity. The flow will work correctly if both "True" and "False" are pointing to the same script, the one on the left (full source listed under the pic).
- Screenshot_20191020-224732.jpg (131.54 KiB) Viewed 7989 times
Code: Select all
if (isList(connected_devices_names))
{
for (c in global_list_cars)
{
inCar=containsElement(connected_devices_names, c);
if (inCar)
{
break;
}
}
if (global_state_inCar!=inCar)
{
global_state_inCar=inCar;
}
}
else
{
global_state_inCar=false;
log("NOT A LIST: connected_devices_names");
}