Duplicate events

I'm writing an app to control linked switches with a master switch.
What I have encountered is when a switch is toggled manually i get a single event, e.g:

dev:2682019-10-08 11:04:48.813 pm infoHallway Light (Virtual) was turned off
dev:2682019-10-08 11:04:41.730 pm infoHallway Light (Virtual) was turned on

However when the same switch is toggled using a command it fires 2 events, e.g:

dev:2682019-10-08 11:06:03.993 pm infoHallway Light (Virtual) was turned off
dev:2682019-10-08 11:06:03.986 pm infoHallway Light (Virtual) was turned off
dev:2682019-10-08 11:06:02.769 pm infoHallway Light (Virtual) was turned on
dev:2682019-10-08 11:06:02.724 pm infoHallway Light (Virtual) was turned on

This creates additional problem of handling the duplicate events, which will result in adding workarounds and complicate the code unnecessary.

Ideally there should be no duplicate event or there should be a way to differentiate the 2 events. I am using Nue Zigbee Switch driver and I suspect the driver is firing the event from inside the on and off commands and also from the parse method.

So my thoughts on possible solution:

  1. I guess simplest is to update the driver not to fire a second event if state has not changed (e.g. if on() command was called it would fire the event, changing state to on, then in parse() it would check the state and not fire the on event since already on)
  2. Alternatively could extend the event model to be able to pass additional data to indicate what triggered the event, e.g. src = "command" or src = "device").

Is there anything else I could use instead?

Tagging @mike.maxwell.

it isn't, we don't write drivers this way, however this is a complex driver in that it supports 1 to n endpoints dynamically on install.
If there is only one endpoint, then there shouldn't be any child devices.
If there are multiple endpoints, then each endpoint will get it's own child device, and the parent on off commands should turn on and off each each of the children together.

So I need to know which switch model you have in order to look into this more.
As an aside, we have a built in app mirror, that provides one master to many slave command replication, just wanted to be sure you were aware of that app...

I have the 3 gang version, with 3 child devices. And i'm subscribing to a single child device (not the parent)

I wasn't aware of it. Will check it out.

I've enabled debug logging on the parent device, and here's what it logs:

Turning on:

dev:2682019-10-09 06:47:14.530 pm infoHallway Light (Virtual) was turned on
dev:2682019-10-09 06:47:14.523 pm infoHallway Light (Virtual) was turned on
dev:2632019-10-09 06:47:14.490 pm debugdescMap:[raw:catchall: 0104 0006 01 01 0040 00 55CA 00 00 0000 0B 01 0100, profileId:0104, clusterId:0006, clusterInt:6, sourceEndpoint:01, destinationEndpoint:01, options:0040, messageType:00, dni:55CA, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:0B, direction:01, data:[01, 00]]
dev:2632019-10-09 06:47:14.474 pm debugdescMap:[raw:55CA0100060800001001, dni:55CA, endpoint:01, cluster:0006, size:08, attrId:0000, encoding:10, command:0A, value:01, clusterInt:6, attrInt:0]

Turning off:

dev:2682019-10-09 06:48:54.035 pm infoHallway Light (Virtual) was turned off
dev:2632019-10-09 06:48:53.940 pm debugdescMap:[raw:catchall: 0104 0006 01 01 0040 00 55CA 00 00 0000 0B 01 0000, profileId:0104, clusterId:0006, clusterInt:6, sourceEndpoint:01, destinationEndpoint:01, options:0040, messageType:00, dni:55CA, isClusterSpecific:false, isManufacturerSpecific:false, manufacturerId:0000, command:0B, direction:01, data:[00, 00]]
dev:2682019-10-09 06:48:53.922 pm infoHallway Light (Virtual) was turned off
dev:2632019-10-09 06:48:53.874 pm debugdescMap:[raw:55CA0100060800001000, dni:55CA, endpoint:01, cluster:0006, size:08, attrId:0000, encoding:10, command:0A, value:00, clusterInt:6, attrInt:0]

I've tested it and it works. However i wanted to go a bit further:

  1. Turning master switch off will turn off linked switches.
  2. Turning master switch on will restore previously on switches.
  3. When any of the linked switches are on, the master switch will remain on.
  4. When all linked switches are off the master switch will be off.

So i still want to build my own app for functionality and to learn how to build apps.

debug logs are perfect, thanks, I see why the driver is producing the events, just don't know why my sample didn't do this while testing, anyway should be simple to sort out...

Can you post a screen shot of the data section of the parent driver details?, wondering if this is due in part to a different model...

Here is the data:

endpointId: 01
application: 42
model: TS0003
isMultiEP: true
manufacturer: _TYZB01_nft8zgds

Here's the data for this switch from the system event logs:

{
"01":{"endpointId":"01","profileId":"0104","inClusters":"0000,0003,0004,0005,0006","outClusters":"0019","manufacturer":"_TYZB01_nft8zgds","model":"TS0003"},
"02":{"endpointId":"02","profileId":"0104","inClusters":"0000,0003,0004,0005,0006","outClusters":"0019","manufacturer":null,"model":null},
"03":{"endpointId":"03","profileId":"0104","inClusters":"0000,0003,0004,0005,0006","outClusters":"0019","manufacturer":null,"model":null}
}

yeah, totally different switch, I can work with it though.
this driver was written specifically for the "3A Smart Home DE" devices...

Great, thanks for your help, Mike