One reason why I have not moved my Domoticz tot the latest version is that I would need to move to Zigbee2MQTT Auto Discovery.
The main issue I have with that switch, is that Z2M AD does not create selector switches, but new devices per state of the input device.
In my examplte below I use a Trust ZYCT-202. To Z2M AD it has 6 buttons x 5 functions = 30 devices ...
This would significantly clog up my already busy device list in Domoticz.
The example below is only for button 5 of my ZYCT-202 remote, but you can easily configure it for all buttons by changing the wildcard on the "on =" section and configure names you like (i.e. "Btn 1", "Btn 2", etc.)
My solution:
1. Make sure all the device states have been detected by the Z2M AD
2. Add the script below into the "Events" in Domoticz
3. Configure hidden devices for all the states ("$" starting on the name)
4. Make sure they alle have a name with the syntax {devicename}_{state}. I used "_" as the separator, but you can use others if you want
5. Make sure you have a dummy selector switch with the same name as the hidden devices, but without the "$"
6. Make sure the selector switch state names match the hidden device state names
7. Configure the device name in "on =" portion in the script below
In my case I have devices from different hardware in my system which I include in the device name.
"(ZB)" is for the Zigbee2MQTT and "(ZBAD)" is for Zigbee to MQTT Auto Discovery.
These are the devices I created:
This is the configuration of the selector switch. Make sure the level names match the names of the hidden devices.
This is the script I use:
Code: Select all
-- ########################################################
-- # #
-- # Version 0.1 of Zigbee Auto Discovery Translator #
-- # John Huppertz 17-11-2024 #
-- # #
-- # Find a way to translate separate devices into #
-- # selector switches as used by zigbee2mqtt plugin #
-- # with minimal device configuration effort #
-- # #
-- # 17-11-2024 - Start #
-- # - Using wildcard "*" to trigger group of #
-- # devices #
-- # - Using the device name syntax {name}_function #
-- # the result van be split into parts where _ is #
-- # the separator #
-- # #
-- ########################################################
return {
on = {
devices = {
'$Trust Btn5_*'
},
},
logging = {
level = domoticz.LOG_INFO,
marker = "ZBAD_Translate"
},
execute = function(dz, device )
devName = device.name
devState = device.state
dz.log("Start triggered by " .. devName, dz.LOG_INFO)
dz.log("State presented = " .. devState, dz.LOG_INFO)
-- split the devicename into fields based on seprator character "_"
local splittedResult = dz.utils.stringSplit(devName,'_')
-- Read the device name and remove the "$" form the device name
devNameSplit = splittedResult[1]:gsub("[$),]","")
-- Read the state from the devicename
devStateSplit = splittedResult[2]
dz.log("Device Name = " .. devNameSplit, dz.LOG_INFO)
dz.log("Device State = " .. devStateSplit, dz.LOG_INFO)
-- Make sure you create a dummydevice that has the correct name and that states match (case sensitive)
dz.devices(devNameSplit .. " (ZBAD)").switchSelector(devStateSplit)
end
}
You can reconfigure the device wild card in the "on =" section to suite your needs. You could use a wild card that matches all devices detected by Z2M AD.
I hope this helps other who are dealing with the same challenge
Cheers,
John