Mitsubishi MELCLOUD integration with Home Assistant

Hi, happy to help.

So that’s the way I make my call to the API and how I extract the compressor frequency in my configuration.yaml :

 - platform: command_line 
    command: 'curl -v -H "X-MitsContextKey: xxxxxyourkeyherexxxx" "https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=xxxxxxx&buildingID=xxxxxx"| jq ".[].Structure.Devices[].Device"'    
    name: Ecodan

    json_attributes:
      - FlowTemperature
      - FlowTemperatureZone1
      - FlowTemperatureZone2
      - HeatPumpFrequency
      - OutdoorTemperature
      - ReturnTemperature
      - ReturnTemperatureZone1
      - ReturnTemperatureZone2
      - TargetHCTemperatureZone1
      - TargetHCTemperatureZone2
    value_template: '{{ value_json.FlowTemperature }}'
    scan_interval: 30
    command_timeout: 10

  - platform: template
    sensors:
      ecodan_cprfrequency:
        entity_id: sensor.ecodan
        friendly_name_template: Ecodan_CprFrequency 
        unit_of_measurement: 'Hz'
        value_template: "{{ state_attr('sensor.ecodan', 'HeatPumpFrequency') }}"

Then this is the automation I use (in automations.yaml)

- id: '1601905305249'
  alias: New Automation
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.ecodan_cprfrequency
    to: '0'
  condition: []
  action:
  - entity_id: counter.cprstopcount
    service: counter.increment
  - delay: 00:20:00
  - entity_id: counter.cprstopcount
    service: counter.reset
  mode: restart

- id: '1601928986834'
  alias: change setting when counter is bigger than 0
  description: ''
  trigger:
  - platform: numeric_state
    entity_id: counter.cprstopcount
    above: '1'
  condition: []
  action:
  - service: climate.set_temperature
    data:
      temperature: '15'
    entity_id: climate.mitsubishi_zone_1
  - service: climate.set_temperature
    data:
      temperature: '15'
    entity_id: climate.mitsubishi_zone_2
  - delay: 00:59:00
  - service: climate.set_temperature
    data:
      temperature: '22'
    entity_id: climate.mitsubishi_zone_1
  - service: climate.set_temperature
    data:
      temperature: '22'
    entity_id: climate.mitsubishi_zone_2
  mode: single

I just changed from melcloud interface to modbus interface (found a 2nd hand Procon A1M) but not sure I can do much more than what can be done via the API and melcloud… I had higher expectations.

Regards
Guido

Thanks @guidods! Works like a charm!

No afraid not. Have you?

I now use the flow temp 1 and returntemp1 values, they give me an accurate result

Hi all, FYI: Melcloud now - finally - works with Google Assistant/ Google Home! :grinning:

Thank you for this integration, it works flawlessly for me!

Does anyone know how I could get energy consumption without the accumulation. It seems to update twice per hour, so that would mean kWh/30mins. Can I do it by creating a template sensor?

Same here, any updates regarding this or how to fix it?

Hey!
Here is my contribution to missing/showing 25 degrees all the time at Flow Temperature (reading default zone, hitting wrong/static value).

Also added Daily Heating Energy Consumed (Heating and Hot Water, plus combined together - bare in mind that this value is from yesterday (-1 day)).

  - platform: rest
    name: Zubadan_Rest
    json_attributes_path: '$.[0].Structure.Floors[0].Devices[0].Device'
    json_attributes:
      - FlowTemperature
      - ReturnTemperature
      - DailyHeatingEnergyConsumed
      - DailyHeatingEnergyProduced
      - DailyHotWaterEnergyConsumed
      - DailyHotWaterEnergyProduced
      - OperationMode
      - CurrentEnergyConsumed
      - CurrentEnergyProduced
    resource: https://app.melcloud.com/Mitsubishi.Wifi.Client/user/ListDevices?id=[INSERT]&buildingID=[INSERT]
    headers:
      X-MitsContextKey: '[INSERT]'
    value_template: 'OK'
    scan_interval: 300
    
  - platform: template
    sensors:
      zubadan_rest_flowtemperature:
        value_template: '{{ state_attr("sensor.zubadan_rest", "FlowTemperature") }}'
        unit_of_measurement: '°C'
        unique_id: 'zubadan_rest_flowtemperature'
      zubadan_rest_flowreturntemperature:
        value_template: '{{ state_attr("sensor.zubadan_rest", "ReturnTemperature") }}'
        unit_of_measurement: '°C'
        unique_id: 'zubadan_rest_flowreturntemperature'
      zubadan_rest_dailyheatingenergyconsumed:
        value_template: '{{ state_attr("sensor.zubadan_rest", "DailyHeatingEnergyConsumed") }}'
        unit_of_measurement: 'kWh'
        unique_id: 'zubadan_rest_dailyheatingenergyconsumed'
      zubadan_rest_dailyhotwaterenergyconsumed:
        value_template: '{{ state_attr("sensor.zubadan_rest", "DailyHotWaterEnergyConsumed") }}'
        unit_of_measurement: 'kWh'
        unique_id: 'zubadan_rest_dailyhotwaterenergyconsumed'
        
  - platform: template
    sensors:
      zubadan_rest_dailyenergyconsumedtotal:
        value_template: '{{ states("sensor.zubadan_rest_dailyheatingenergyconsumed") | float + states("sensor.zubadan_rest_dailyhotwaterenergyconsumed") | float }}'
        unit_of_measurement: 'kWh'
        unique_id: 'zubadan_rest_dailyenergyconsumedtotal'

Replace [INSERT] with own values, also sensor names if necessary.

Let me know if it works for you, it’s my first attempt writing this kind of code - or, if you’d do anything differently, feedback welcome.

@matindex
I would like to try this. Where do I find the information needed to replace the [INSERT] values?

BuildingID and ListDevices?id: are these the values (“select system”) you select if you want to make a report in the MELcloud app?
X-MitsContextKey I can’t find anywhere?

edit: found it logging in MELcloud in the browser and using the developer tools > Network > XHR > Headers :slight_smile:

I get:
Screenshot 2021-04-18 at 09.53.43

As it turns out I managed to turn off all noticiations on this platform and thought this topic had died.

@Stieviewievie This definitely looks like a bug. I don’t remember too well whether I got many 2 zone setups in the testing pool. Have you managed to find a workaround for the issue? I think I need to take a look at this anyways.

@guidods Your compressor frequency command_line scan frequency exceeds the frequency of changes in the data. The ListDevices endpoint is particularly slow. Could you please edit those samples to reduce home-assistant related load on MELCloud.

On a tanglential theme: Have you found other interesting sensors or readings besides the HeatPumpFrequency?

@matindex What device is this and could you elaborate on the FlowTemperature issue? I clearly remember seeing similar issue on home-assistant GitHub, but I didn’t quite get enough info out of it before it was closed and apparently deleted.

@ vilppuvuorinen
re. second zone not displaying issue
I also see this issue, and I have the following error in the HA log on startup that I think explains it is lack of unique UIDs for the entities. Let me know if I can help debug it further.

2021-05-25 22:57:46 ERROR (MainThread) [homeassistant.components.sensor] Platform melcloud does not generate unique IDs. ID 2011064417-aa:bb:cc:dd:ee:ff-room_temperature already exists - ignoring sensor.ecodan_loft_fancoil_room_temperature
2021-05-25 22:57:46 ERROR (MainThread) [homeassistant.components.sensor] Platform melcloud does not generate unique IDs. ID 2011064417-aa:bb:cc:dd:ee:ff-flow_temperature already exists - ignoring sensor.ecodan_loft_fancoil_flow_temperature
2021-05-25 22:57:46 ERROR (MainThread) [homeassistant.components.sensor] Platform melcloud does not generate unique IDs. ID 2011064417-aa:bb:cc:dd:ee:ff-return_temperature already exists - ignoring sensor.ecodan_loft_fancoil_flow_return_temperature

(ecodan_loft_fancoil_* is actually my zone 1 that is working; zone 2 is ecodan_ground_floor_ufh but the room and flow temps for that aren’t registering)

Setting operation mode
While I’m here: I see the heatpump integration correctly reports if the system is set to heat or cool mode, however there’s no way to modify the mode via this integration. Is this a known issue?

Part of the cause is that the integration only lists a single entry (the correct mode) in the hvac_modes attribute, but I presume this is by design as changing mode isn’t supported? To change mode, it looks like it would also need to know the correct setting for the zone OperationMode e.g. Room, Flow or Curve control, and Flow temps where appropriate, and getting these wrong could be costly mistake? (e.g. damaged floor finishes in the case of underfloor heating)

I’ll take a look ot those UID conflicts. It sounds like it should be a simple thing to spot.

The current version of the integration in home-assistant does not support OperationMode settings correctly. It just assumes that the setup is running in the external thermostat mode. I had started to work on new features that would add at least the Flow mode into the mix, but I ran out of people willing to help with testing as I don’t have access to an ATW device.

There’s a fork of the integration as a custom component available here: GitHub - vilppuvuorinen/hass-melcloud. It works in parallel with the existing melcloud integration. The issue here is that it is awfully outdated and I don’t know if it will even run anymore with latest versions of home-assistant. I’m tyring to update it this week.

It would be great if you could give it a go so that I would dare to PR the features to upstream home-assistant. I can ping you here when I get the updates in.

2 Likes

Thanks for the quick reply!
I’d be happy to try the experimental version - let me know when you think it’s worth giving it a whirl on ~latest HA and I’ll see.

(FWIW I use ‘curve’ rather than flow temp for heating mode, but cooling only supports flow. Curve feels safer to me as the settings for it a set in the controller setup menu and there’s no way to mess with them over the WiFI interface. That said, the heat and cool flow temps are supplied in every response, so as long as you bundle the same values back into the request there shouldn’t be so much risk of messing them up.)
I have HAR captures of changing modes, I can look to santize and share if needed.

The custom component is now up to date. I’m not feeling super confident about the changes because I had to do some funky cp -rf and git cherry-pick magic to get things sorted. It did seem to work OK with the my ATA device.

I have a fix for the unique ID problem and I should have a PR open any day now. I just can’t run the tests locally for some reason right now and it has stopped me right in my tracks :face_with_head_bandage:

[Sorry for long time to reply - it seems I also do not get forum notifications]

@vilppuvuorinen I just tried installing the Experimental fork from github HEAD, but afraid it looks like the old warning about duplicate IDs is still there, and now there’s a new error too

* Platform melcloudexp does not generate unique IDs. ID 2011064417-......-room_temperature already exists - ignoring sensor.ecodan_loft_fancoil_room_temperature

Logger: homeassistant.components.climate
Source: custom_components/melcloudexp/climate.py:81
Integration: Climate ([documentation](https://www.home-assistant.io/integrations/climate), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+climate%22))
First occurred: 6:24:46 PM (1 occurrences)
Last logged: 6:24:46 PM

Error while setting up melcloudexp platform for climate

Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 250, in _async_setup_platform await asyncio.shield(task) 
File "/config/custom_components/melcloudexp/climate.py", line 75, in async_setup_entry + [ 
File "/config/custom_components/melcloudexp/climate.py", line 81, in <listcomp> 
   if atw.ZONE_OPERATION_MODE_HEAT_FLOW in zone.operation_modes AttributeError: module 'pymelcloud.atw_device' has no attribute 'ZONE_OPERATION_MODE_HEAT_FLOW' 

Let me know if I can provide further info to debug further

I’m able to fix the duplicate ID error, and make both zones appear as sensors, by adding _name_slug to the unique_id property like so:

class MelDeviceSensor(SensorEntity):

    @property
    def unique_id(self):
        """Return a unique ID."""
        return f"{self._api.device.serial}-{self._api.device.mac}-{self._name_slug}-{self._measurement}"

The duplicate IDs are most likely fixed by now in the upstream versions too. I recently got the PR merged. I’ll try to update the experimental fork as soon as I can find the time.

Hi,
I’m trying to figure out how to control my EW-50E device from my own scripts but I’m unable to find documentation how the XML API is supposed to work. You posted an example XML request here which works perfectly fine. Do you happen to have XML API documentation?

Hello, I bought recently Mitsubishi air conditioner mkv35fe with mel cloud wifi interface. Integration works but very very slow. Each command that I give I must wait 1minute or so, to climate react to it.
Also with theirs application for iOS MELCloud. Very very slow responsiveness. Any hints on that?

That’s just how the service is built. The whole thing seems to be pretty simple HTTP service and lowering the poll interval must reduce their operational expenses to a tolerable level. They are getting just a one time payment on unit sales and the units quite a long time.