gysmo38 / domoticz-python-melcloud

A plugin in python for Domoticz
13 stars 15 forks source link

error code 500 #27

Open Patricen1 opened 2 years ago

Patricen1 commented 2 years ago

Hello,

Since a couple of days, there is an issue when controlling air conditioner. Status is correctly uploaded to Domoticz, but when trying to control air conditioner from Domoticz, the following message appears in the log and there is no effect on the aircon system : "MELCloud receive unknonw message with error code 500".

Has anybody got a clue regarding this issue? Thanks

Xavier74 commented 2 years ago

same problem here.. :(

mitkodotcom commented 2 years ago

It looks like MELcloud does not accept urlencoded forms. I have created a quick-and-dirty (very dirty) fix by replacing the urlencoded form with a json one. I don't have a time for patch or pull request now, so you have to edit plugin.py manually

I also don't have time to check the whole code now so I don't want to patch the original melcloud_send_data function as it is used elsewhere. So copy the function melcloud_send_data as melcloud_send_data_json and change the content-type from application/x-www-form-urlencoded; to application/json;

def melcloud_send_data_json(self, url, values, state):
        self.melcloud_state = state
        if self.melcloud_key is not None:
            headers = {'Content-Type': 'application/json;',
                       'Host': self.melcloud_baseurl,
                       'User-Agent': 'Domoticz/1.0',
                       'X-MitsContextKey': self.melcloud_key}
            if state == "SET":
                self.melcloud_conn.Send({'Verb': 'POST', 'URL': url, 'Headers': headers, 'Data': values})
            else:
                self.melcloud_conn.Send({'Verb': 'GET', 'URL': url, 'Headers': headers, 'Data': values})
        else:
            headers = {'Content-Type': 'application/x-www-form-urlencoded;',
                       'Host': self.melcloud_baseurl,
                       'User-Agent': 'Domoticz/1.0'}
            self.melcloud_conn.Send({'Verb': 'POST', 'URL': url, 'Headers': headers, 'Data': values})
        return True

Then change melcloud_set as follows (you may keep the old code as melcloud_set_urlencoded just in case):

    def melcloud_set(self, unit, flag):
        post_fields = "'Power':{0},'DeviceID':{1},'OperationMode':{2},'SetTemperature':{3},'SetFanSpeed':{4},'VaneHorizontal':{5},'VaneVertical':{6},'EffectiveFlags':{7},'HasPendingCommand':true"
        post_fields = post_fields.format(str(unit['power']).lower(), unit['id'], unit['op_mode'], unit['set_temp'], unit['set_fan'], unit['vaneH'], unit['vaneV'], flag)
        Domoticz.Debug("SET COMMAND SEND {0}".format(post_fields))
        self.melcloud_send_data_json(self.melcloud_urls["set_unit"], "{"+post_fields+"}", "SET")

EDIT: it seems MELcloud is validating the json syntax so I had to make some changes (lowcase for power, single quotes)

Patricen1 commented 2 years ago

Hello,

I have tried but it does unfortunately not operate properly (maybe due to a bad paste from my side), see log below.

By the way, it looks like there is some knowledgeable people there, would it be possible improving the plugin using a setpoint type device for temp setpoint instead of a multi level switch?

Patrice

_2022-02-01 16:02:27.805 Status: MELCloud: Initialized version 0.7.8, author 'gysmo' 2022-02-01 16:02:27.435 Error: (FindModule) Domoticz/DomoticzEx modules not found in interpreter. 2022-02-01 16:02:28.018 Error: MELCloud: 'onConnect' failed 'AttributeError':''BasePlugin' object has no attribute 'melcloud_send_data''. 2022-02-01 16:02:28.018 Error: MELCloud: Exception traceback: 2022-02-01 16:02:28.018 Error: MELCloud: ----> Line 538 in '/home/pi/domoticz/plugins/domoticz-python-melcloud/plugin.py', function onConnect 2022-02-01 16:02:28.018 Error: MELCloud: ----> Line 149 in '/home/pi/domoticz/plugins/domoticz-python-melcloud/plugin.py', function onConnect 2022-02-01 16:02:28.018 Error: MELCloud: ----> Line 437 in '/home/pi/domoticz/plugins/domoticz-python-melcloud/plugin.py', function melcloudlogin 2022-02-01 16:02:34.155 Status: User: Xxx (IP: xxx.xxx.xxx.xxx) initiated a switch command (621/MELCloud - Couloir - Mode/Set Level) 2022-02-01 16:02:34.198 Error: MELCloud: 'onCommand' failed 'TypeError':''bool' object does not support item assignment'. 2022-02-01 16:02:34.198 Error: MELCloud: Exception traceback: 2022-02-01 16:02:34.198 Error: MELCloud: ----> Line 550 in '/home/pi/domoticz/plugins/domoticz-python-melcloud/plugin.py', function onCommand 2022-02-01 16:02:34.198 Error: MELCloud: ----> Line 299 in '/home/pi/domoticz/plugins/domoticz-python-melcloud/plugin.py', function onCommand

mitkodotcom commented 2 years ago

Did you left the original melcloud_send_data function intact? You are supposed to copy it and then change the name and content type, leaving the original function as it is, because it is used elsewhere (during login process, for example).

You can probably make a script to synchronize the selector values with a setpoint.

Patricen1 commented 2 years ago

It looks like I did not catch something. Could you please share your plugin.py file? Thanks!

mitkodotcom commented 2 years ago

Here it is

plugin.zip

stefstef2000 commented 2 years ago

Here it is

plugin.zip

Thanks !

Xavier74 commented 2 years ago

When using the latest plugin version, I get others errors, like described in #24 and #22 I'm using latest stable domoticz version, v2021.1 build 14119). Using plugin version 0.7.6 the problem is not present, the device I have is found but I continue getting the 500 error. Using latest 0.7.7 with your proposed change on plugin.py or uploaded one, problem goes away but no device found in the building and error mentionned appires. If anyone can explain it...

mitkodotcom commented 2 years ago

It's hard to say. Unfortunately the debug setting does not work so you have to uncomment Domoticz.Debugging(62) or Domoticz.Debugging(-1) in my file and restart.

Try not to use areas, only floors. Do not use any non-ascii characters in names.

Xavier74 commented 2 years ago
  Many thanks, updating to floor instead of area and applying the new plugin.py worked :)
herbod-nl commented 2 years ago

Thanks for this fix. It made me able to controle the airco's with Domoticz again. I do get the errors below. Any idea how to solve these?

2022-02-05 21:00:58.239 Error: Airco: (Airco) 'onMessage' failed 'UnboundLocalError':'local variable 'setPicID' referenced before assignment'. 2022-02-05 21:00:58.239 Error: Airco: (Airco) ----> Line 570 in '/home/pi/domoticz/plugins/Melcloud/plugin.py', function onMessage 2022-02-05 21:00:58.239 Error: Airco: (Airco) ----> Line 255 in '/home/pi/domoticz/plugins/Melcloud/plugin.py', function onMessage 2022-02-05 21:00:58.239 Error: Airco: (Airco) ----> Line 520 in '/home/pi/domoticz/plugins/Melcloud/plugin.py', function domoticz_sync_switchs

Paul-AUB commented 2 years ago

The given file works for me (only tested on a standard use case start/stop) ! Thx a lot :)

Note the given file also includes the changes relative to https://github.com/gysmo38/domoticz-python-melcloud/pull/25, and I'm waiting to see if it crashed after some time or not (ongoing test, I'll let you know).

nonolk commented 2 years ago

As I was facing the same issue as several, I dig a bit in the plugin, and rewrote a bit the login function, to use json instead url-encoded logic. I also adapted the device discovery process to be able to discover my devices.

Here is the modified file: plugin.py.zip

Patricen1 commented 2 years ago

As I was facing the same issue as several, I dig a bit in the plugin, and rewrote a bit the login function, to use json instead url-encoded logic. I also adapted the device discovery process to be able to discover my devices.

Here is the modified file: plugin.py.zip

I'll try this! There are some things that looks strange to me regarding Melcloud.

Thanks!

LOYK31 commented 2 years ago

Hello,

Thanks to @mitkodotcom for the quick fix, it worked well for me. I was previously on version 0.7.6

Hope the plugin will be updated properly :)

manolo75 commented 2 years ago

Hi,

I am facing the same issue :

2022-08-18 23:31:25.180 MelCloud clim: Set to Vent the unit Haut 2022-08-18 23:31:25.322 MelCloud clim: MELCloud receive unknonw message with error code 500 2022-08-18 23:31:25.373 MelCloud clim: MELCloud receive unknonw message with error code 500 2022-08-18 23:31:27.755 Status: User: Admin (IP: 192.168.1.4) initiated a switch command (1835/MelCloud clim - Haut - Mode/Set Level) 2022-08-18 23:31:27.787 MelCloud clim: onCommand called for Unit 8: Parameter 'Off', Level: 0 2022-08-18 23:31:27.787 MelCloud clim: Switch Off the unit Hautwith ID offset 7 2022-08-18 23:31:27.929 MelCloud clim: MELCloud receive unknonw message with error code 500

I tried several plugin.py, but still the same :(

zajc3w commented 2 years ago

Thanks for this fix. It made me able to controle the airco's with Domoticz again. I do get the errors below. Any idea how to solve these?

2022-02-05 21:00:58.239 Error: Airco: (Airco) 'onMessage' failed 'UnboundLocalError':'local variable 'setPicID' referenced before assignment'. 2022-02-05 21:00:58.239 Error: Airco: (Airco) ----> Line 570 in '/home/pi/domoticz/plugins/Melcloud/plugin.py', function onMessage 2022-02-05 21:00:58.239 Error: Airco: (Airco) ----> Line 255 in '/home/pi/domoticz/plugins/Melcloud/plugin.py', function onMessage 2022-02-05 21:00:58.239 Error: Airco: (Airco) ----> Line 520 in '/home/pi/domoticz/plugins/Melcloud/plugin.py', function domoticz_sync_switchs

did you fix it? mine starting doing the same thing after 2 days of running...

Jcasval commented 1 year ago

Gracias Patricen1, gracias a tu archivo todo funciona a la perfección.

dalonsic commented 1 year ago

Hello,

Today, I tried to solve a hearbeat problem with a rewrite of the heartbeat management. I implemented a parameter to choose the interval. I also implemented multilingual support with the MELCloud app.

Thanks for correcting error code 500 ;)

Have fun ;)

EDIT : after few fixes... v0.8.2 based on Nonolk version : plugin.py.0.8.2.zip

EDIT : and v0.8.3 based on Mitkodotcom version : plugin.py.0.8.3.zip

Dalonsic.

manjh commented 1 day ago

I'm afraid none of the solutions work for me. When I try the latest plugin.py in the post above, it gives me a lot of syntax errors: 2024-11-05 17:22:24.074 Error: Airco: ValueError: invalid literal for int() with base 10: '' 2024-11-05 17:22:26.170 R-Pi sensors: Temp (Internal Temperature) 2024-11-05 17:22:26.178 R-Pi sensors: General/Percentage (CPU_Usage) 2024-11-05 17:22:34.090 Error: Airco: Call to function 'onHeartbeat' failed, exception details: 2024-11-05 17:22:34.092 Error: Airco: Traceback (most recent call last): 2024-11-05 17:22:34.092 Error: Airco: File "/home/pi/domoticz/plugins/domoticz-python-melcloud/plugin.py", line 656, in onHeartbeat 2024-11-05 17:22:34.092 Error: Airco: _plugin.onHeartbeat() 2024-11-05 17:22:34.092 Error: Airco: File "/home/pi/domoticz/plugins/domoticz-python-melcloud/plugin.py", line 440, in onHeartbeat 2024-11-05 17:22:34.092 Error: Airco: self.runCounter = int(Parameters['Mode2'])

Any chance of a proper cleanup on the plugin?