How can I understand when device is selected in app using device selector?


I use Device selector in my project. How can I understand when device is selected in app?
I want to realize that algorithm: when I choose device in device selector, it automatically switches relays.

Do you mean being able to tell in code on your device which device is selected in the device selector?


Yes, that is what I mean.
Thanks for your reply

Well the idea is that you have one device, with its own Auth code, set-up in the app for each physical device that you have.
Let’s say that you have 4 NodeMCUs, each controlling a relay. We’ll call them Relay 1, 2, 3 & 4, but you’d probably give them sensible names.

We’ll also assume that you have a switch widget on virtual pin V1 in your device selector.

If you select Relay 1 in Device selector then turning the the switch widget on will send the change to device 1, causing the BLYNK_WRITE(V1) function to trigger on just that device.
If Relay 4 was selected instead then the V1 button press would be sent to device 4 instead, causing BLYNK_WRITE(V1) to trigger on that device.

As a result, you don’t need to know which device has been selected, as the App/Server handle the process of directing the commands to the correct device.