sydspost / Domoticz-WiZ-connected-plugin

Domoticz WiZ connected plugin
MIT License
5 stars 6 forks source link

Plugin crashes when device is unreacheable #10

Open junnuvi opened 2 years ago

junnuvi commented 2 years ago

I have couple wiz devices which are connected to wall switch. When ever I shutdown lights from switch and try to control that device it will cause Domoticz-Wiz plugin and other plugins too to crash..

2021-11-08 19:15:14.046 Activating Scene/Group Device: AK Plafondi (On)
2021-11-08 19:15:14.048 Wiz: Pushing 'onCommandCallback' on to queue
2021-11-08 19:15:17.308 Error: UPS Kellari hardware (11) thread seems to have ended unexpectedly
2021-11-08 19:15:17.309 Error: Mikrotik Router hardware (12) thread seems to have ended unexpectedly
2021-11-08 19:15:17.309 Error: Wiz hardware (17) thread seems to have ended unexpectedly 

Only restarting domoticz will fix the issue.

My plugin is slightly modified because I have RGBW wiz devices but I don't believe modifications will cause this issue.

Renevandenbroek commented 2 years ago

Hello junnuvi. What modification did you make to the Plugin to make it work for color lamps?

junnuvi commented 2 years ago

Try this. http://ihan.tutkalla.com/wiz_plugin_rgb.py Also you need manually modify domoticz device type to rgbww lamp. Type=241, Switchtype=7,Subtype=7

Renevandenbroek commented 2 years ago

Thanks junnuvi but.... where and how do I manually modify domoticz devicde type. I replaced plugin.py by your wiz_plugin_rgb.py and renamed it to plugin.py. In the fyle I change Subtype=8 tp Subtype=7 But that was obviously not the solution. ( I feel a bit stupid:)

junnuvi commented 2 years ago

You need to modify device type in sqlite database.

Renevandenbroek commented 2 years ago

Thank you junuvi, that did the job.

sydspost commented 2 years ago

Rene,

My plan is to adjust the plugin so it will detect if it's a warm white of a color bulb, and give it according to its detection the right subtype. Also depending on if it's a warme white or color bulb the correct message to Domoticz to update the device status. But i have no color bulbs at my home, so maybe you can give me the output of the following command:

echo '{"method":"getPilot"}' | nc -u -w 1 38899 (please replace with an ip-address from one of your color bulbs)

You get an answer like: {"method":"getPilot","env":"pro","result":{"mac":"a8bb5042a55c","rssi":-49,"state":false,"sceneId":11,"temp":2700,"dimming":40}}

If you post your output here, maybe i can improve the functionality of the plugin.

Thanks in advance,

Syds

Renevandenbroek commented 2 years ago

Hello Syds, This is the response

{"method":"getPilot","env":"pro","result":{"mac":"6c2990905a81","rssi":-59,"state":true,"sceneId":11,"temp":3000,"dimming":20}}

Succes René

junnuvi commented 2 years ago

Sydspost,

Back to original topic. Are you able to replicate my problem? This is pretty annoying that plugin crashes every time when bulb is unreachable. I'm totally rookie with python so I was not able to fix it by myself. For now I disabled plugin to prevent domoticz to crash.

For future, it would be nice to have possibility to add devices manually and disable auto discovery. It does not work on all networks for example in situations when there is no automatic dns update feature in router.

Renevandenbroek commented 2 years ago

I see once in a while the following error. Domoticz does not crash and the problem disappears automatically.

2021-12-01 03:04:24.345 Error: WiZ connected hardware (11) thread seems to have ended unexpectedly

junnuvi commented 2 years ago

In my case it will not crash immediately after bulb is disconnected (powered off from manual switch):

After Wiz connected plugin crashes other plugin threats will crash as well.. And some time after that whole Domoticz process will die.

sydspost commented 2 years ago

Junnuvi, can you uncomment lines 123 until 125 in the plugin:

    # if not dev.available():
    #     Domoticz.Error('Command for DeviceID='+Devices[Unit].DeviceID+' but device is offline.')
    #     return

and check if this solves your problem ?

junnuvi commented 2 years ago

Problem was too long default timeout.

Fixed like this:

            sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
            sock.settimeout(5)
            try:
                sock.sendto(mJSON, (host, port))  
                received = sock.recv(1024).decode('utf-8')
            except:
                Domoticz.Error('Command for DeviceID='+Devices[Unit].DeviceID+' but device is offline.')
                return
            finally:
                sock.close()

Btw, I found another fork of you plugin which has in my opinion better autodiscovery https://github.com/faust93/Domoticz-WiZ-connected-plugin

Thanks for all your work with plugin.