Get a paired bluetooth device node red

Hi

I’m trying to see if a specific bluetooth devices is connected to my phone (for example my car) to do an automation on it.

Since I only have one connected device in my house, I tried this out with ‘paired_devices’ so I could get an array of multiple devices, cause I know that in my car there will be more than one (car and watch) connected, but I’m struggeling with the function to see if a specific device is in the array.

So, I get

paired_devices: >-
  [first_paired_device, second_paired_device, third_paired_device, fourth_paired_device,
  fifth_paired_device, sixth_paired_device]

and I want to see if fourth_paired_device is in the array or not. How could I do that?
I know it should be done with a function, but it’s really the code itself that I don’t know.

Hi Christophe,

Do you have any solution to it? :slight_smile:

I can’t remember the exact message structure but this is the kind of what you need.

If (msg.attributes.something.something.paired_devices.includes("some mac address")) {
   return msg;
}

In a function node.

1 Like

No, didn’t have one yet. But I see Hellis81 also replied, so maybe we can use that code