OK, but that is not relavent. As you have created the Dashboard Template yourself, it is up to you to include code in the template such that, when the switch is activated, it sends back a suitable message indicating the ID if the switch activated.
There are plenty of examples around of how to send a msg back to Node-RED. The only thing you are really missing is making sure that the msg that is sent back contains an identifier that you can link to the appropriate sonoff.
device variable that you receive from the loop.
The function does a msg.send back to Node-RED containing a suitable
msg.topic related to the ID you've passed in, the payload need only be "toggle" or something else.
Once back in Node-RED, you connect the output from your template node to something that passes the msg onward to MQTT, processing the topic if it doesn't exactly match your SONOFF device topic.