Smanar / Domoticz-deCONZ

deCONZ plugin for Domoticz (Zigbee application)
GNU General Public License v3.0
36 stars 27 forks source link

Support xiaomi Opple switches #46

Closed eserero closed 4 years ago

eserero commented 4 years ago

Hello - recent version of deconz (V2_05_73) introduce support in opple smart switches that have 3 variants (6 buttons, 4 buttons, 2 buttons). https://github.com/dresden-elektronik/deconz-rest-plugin/issues/2061

The support is not perfect, and they are working to improve, but single press is functional as well as long press on some of the buttons. I meddle a bit with the python code and added support for the 6 button switch (what I have) for whats there. dont know much about how to go about it in Git, so I just pasted the files with my changes. I marked sections I changed with "#eyal start" and "#eyal end". these are really great switches and cheap, so I hope it help someone and that you can included it in the official release.

fonctions.txt plugin.txt

Smanar commented 4 years ago

Ha nice thx ^^. I can make the modification myself, but better if you do it, like that changes will be assigned to you.

If you wana do that :

Go on beta branch (not the master), and try to edit a file, it will make a fork on your github.

Or you can make a fork direclty, but remember to use the beta branch.

eserero commented 4 years ago

Got it - just did - see if this make sense to you?

Smanar commented 4 years ago

Yep, perfect ^^, Thx a lot, I have comment the PR, I have see it before your post here.

Just a think, there is so much button, idk how look the device in domoticz, but it will be not a good idea to use the combobox, instead of the button display ?

eserero commented 4 years ago

Thanks Smanar - agree with all your suggestions, also I just saw that I didn't remove my name, just put it there so I will remember what code sections I touched, so feel free to remove. the reason for so many buttons is that for each button you can possibly have single press, double press and long press. as you can see from the code many events are not yet working, but i'm monitoring the changes in deconz rest plugin, and when it is supported I will add the rest of the events.

Smanar commented 4 years ago

Why remove your name ? IDK on your machine, but on mine, it's look like that b1

but if you wana use combo (Just need to change SelectorStyle in code) b2

IDK for you, but I think the combo will be more usefull ? Harder to use but better for GUI ?

eserero commented 4 years ago

Combo is better. on my machine I'm using machinon theme, so there is a scroller. in any case, this is a switch - whole purpose is to press physical buttons, so I never use the domoticz widget directly

Smanar commented 4 years ago

Right, anyway you can't clic on button on domoticz, else you will have an error "this device don't support action".

I make change to use it as combo.

Smanar commented 4 years ago

@eserero Hello, the Version 76 of deconz is just out, with better version for opple. If you can check/modify the plugin code with last deconz code ?

eserero commented 4 years ago

Ha Ha - you are fast :-). actually I have 5 switches waiting for this for a while. I will definitely do this - hopefully tomorrow.

Smanar commented 4 years ago

Lol, yeap, so long time I m waiting for this version, so many bugs corrected.

eserero commented 4 years ago

hi @Smanar, I updated the file I have, and it is working now, but I saw that you did some changes in the beta branch related to the opple switch which changed the conversion function to a table. I am still using the conversion function and have the updated code. would you like to merge it yourself? note that the only thing that doesnt work is release after hold events, but I already implemented this so when this will start working in deconz then domoticz will work as well.

in plugin.py

kwarg['Options'] = {"LevelActions": "|||||||||||||||||||||||||||||", "LevelNames": "Off|B1|B2|B3|B4|B5|B6|B1L|B2L|B3L|B4L|B5L|B6L|B1RL|B2RL|B3RL|B4RL|B5RL|B6RL|B1D|B2D|B3D|B4D|B5D|B6D|B1T|B2T|B3T|B4T|B5T|B6T", "LevelOffHidden": "true", "SelectorStyle": "0"}

in fonction.py

eyal start

0 - Off

single press

10 - B1 - 1002

20 - B2 - 2002

30 - B3 - 3002

40 - B4 - 4002

50 - B5 - 5002

60 - B6 - 6002

long press

70 - B1L - 1001

80 - B2L - 2001

90 - B3L - 3001

100 - B4L - 4001

110 - B5L - 5001

120 - B6L - 6001

release afer long press (not working for some reason)

130 - B1RL - 1003

140 - B2RL - 2003

150 - B3RL - 3003

160 - B4RL - 4003

170 - B5RL - 5003

180 - B6RL - 6003

double press

190 - B1D - 1004

200 - B2D - 2004

210 - B3D - 3004

220 - B4D - 4004

230 - B5D - 5004

240 - B6D - 6004

tripple press

250 - B1T - 1005

260 - B2T - 2005

270 - B3T - 3005

280 - B4T - 4005

290 - B5T - 5005

300 - B6T - 6005

if val == '1002' or val == 1002: kwarg['nValue'] = 10 elif val == '2002' or val == 2002: kwarg['nValue'] = 20 elif val == '3002' or val == 3002: kwarg['nValue'] = 30 elif val == '4002' or val == 4002: kwarg['nValue'] = 40 elif val == '5002' or val == 5002: kwarg['nValue'] = 50 elif val == '6002' or val == 6002: kwarg['nValue'] = 60 elif val == '1001' or val == 1001: kwarg['nValue'] = 70 elif val == '2001' or val == 2001: kwarg['nValue'] = 80 elif val == '3001' or val == 3001: kwarg['nValue'] = 90 elif val == '4001' or val == 4001: kwarg['nValue'] = 100 elif val == '5001' or val == 5001: kwarg['nValue'] = 110 elif val == '6001' or val == 6001: kwarg['nValue'] = 120 elif val == '1003' or val == 1003: kwarg['nValue'] = 130 elif val == '2003' or val == 2003: kwarg['nValue'] = 140 elif val == '3003' or val == 3003: kwarg['nValue'] = 150 elif val == '4003' or val == 4003: kwarg['nValue'] = 160 elif val == '5003' or val == 5003: kwarg['nValue'] = 170 elif val == '6003' or val == 6003: kwarg['nValue'] = 180 elif val == '1004' or val == 1004: kwarg['nValue'] = 190 elif val == '2004' or val == 2004: kwarg['nValue'] = 200 elif val == '3004' or val == 3004: kwarg['nValue'] = 210 elif val == '4004' or val == 4004: kwarg['nValue'] = 220 elif val == '5004' or val == 5004: kwarg['nValue'] = 230 elif val == '6004' or val == 6004: kwarg['nValue'] = 240 elif val == '1005' or val == 1005: kwarg['nValue'] = 250 elif val == '2005' or val == 2005: kwarg['nValue'] = 260 elif val == '3005' or val == 3005: kwarg['nValue'] = 270 elif val == '4005' or val == 4005: kwarg['nValue'] = 280 elif val == '5005' or val == 5005: kwarg['nValue'] = 290 elif val == '6005' or val == 6005: kwarg['nValue'] = 300 else: kwarg['nValue'] = 0

Smanar commented 4 years ago

Ok so I have updated the code with your values, if you can make a try before I validate the code pls ?

For information I will use the same table for all opple switch (2 to 6 button).

eserero commented 4 years ago

Sure - I'll try it this evening and update.

eserero commented 4 years ago

just replaced the file and the switches are still working fine (tested all the buttons). didnt test creation of a new switch, but you didnt change that. I"ll probably do this in a couple of days.

Smanar commented 4 years ago

No for the creation I have used your widget, I have just changed the condition to create this sensor using only the end of name instead of the full name, to make it compatible for all opple sensor (the end of the name is always the same).

So I think it's good, thx ^^

Smanar commented 4 years ago

Hello, you haven't error like this one in log on your side ?

Error: (ConBee) Can't Update Unit >19 (sensors)