This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

API with Mitsubishi MELCloud for heatingpumps
#1
Hi,

Is there anybody that has done an integration with Mitsubishi`s cloud portal MELCloud through api?

I found this french guy that has reversed engineered this and created a python script to communicate with it.
http://mgeek.fr/blog/un-peu-de-reverse-e...r-melcloud

From web searches I have found plugins created for Home Assistant and Domoticz based on this. 

It would be awsome to have my heating pump also visualized on the HomeLynk.

kind regards
thomas
Reply
#2
Can you send cloud login/password via PM so I can provide a working example?
Reply
#3
PM sent :-)
Reply
#4
Here's a working example, it will log all devices from your account.
Code:
email = 'test@test.com'
password = '123456'

https = require('ssl.https')
json = require('json')
ltn12 = require('ltn12')

function encodepost(t)
  local res = {}
  local esc = require('socket.url').escape

  for k, v in pairs(t) do
    res[ #res + 1 ] = esc(k) .. '=' .. esc(v)
  end

  return table.concat(res, '&')
end

function login(email, password)
  local url = 'https://app.melcloud.com/Mitsubishi.Wifi.Client/Login/ClientLogin'
  local data = encodepost({
    AppVersion = '1.9.3.0',
    Language = '7',
    CaptchaChallenge = '',
    CaptchaResponse = '',
    Persist = 'true',
    Email = email,
    Password = password,
  })

  local res, code = https.request(url, data)

  if res then
    resp = json.pdecode(res)

    if type(resp) ~= 'table' then
      return nil, 'failed to decode reply data'
    elseif resp.ErrorId ~= json.null then
      return nil, 'cloud login failed'
    else
      return resp.LoginData.ContextKey
    end
  else
    return nil, 'login request failed'
  end
end

function getdevices(key)
  local url = 'https://app.melcloud.com/Mitsubishi.Wifi.Client/User/ListDevices'
  local tbl = {}

  local res, code = https.request({
    url = url,
    headers = {
      ['X-MitsContextKey'] = key
    },
    sink = ltn12.sink.table(tbl),
  })

  if res then
    local data = table.concat(tbl)
    return json.pdecode(data)
  else
    return nil, 'get devices request failed'
  end
end

key, err = login(email, password)
if key then
  items, err = getdevices(key)

  if items then
    for _, item in ipairs(items) do
      local devs = item.Structure.Devices
      for _, dev in ipairs(devs) do
        log(dev)
      end
    end
  else
    log(err)
  end
else
  log(err)
end
Reply
#5
Nice! Thank you very much :-)
Reply
#6
(12.08.2019, 11:54)thomasoppida Wrote: Nice! Thank you very much :-)
Hello,

this topic is a bit older but I hope it can be active again and maybe someone can help ...

I am using ioBroker and Melcloud. There is an adapter for homebridge which I am using actually. But I think that it could be done with objects and status. I am serching for a solution to make states which can be read from a json like I do it already for my homepilot or the controme heating system. But I have no idea because I am new to this ...

Maybe here is someone knowing the iobroker and knows maybe how to handle the script in this topic correctly. Or maybe it is not possible ...

I think the probelm is to get the JSON - For controme I have this javascript - but I also have already the json api available, which I do not have for melcloud -Example für the kitchen and the sensors:

Code:
const request = require('request');
const link_kueche = 'http://192.168.1.12/get/json/v1/1/temps/1/';

// Datenpunkte erzeugen
//Küche
createState('Controme.kueche.frt_temp', 0, {type: "number", unit: '°C'});
createState('Controme.kueche.rl_temp', 0, {type: "number", unit: '°C'});
createState('Controme.kueche.frt_akt', 0, {type: "string", unit: ''});
createState('Controme.kueche.rl_akt', 0, {type: "string", unit: ''});
createState('Controme.kueche.solltemperatur', 0, {type: "number", unit: '°C'});

function controme_kueche() {
    request(link_kueche, function(error,response, body) {
        if(error) log('Fehler request: ' + error, 'error');
       
        else if(body.indexOf('html') == -1) {
            log(body);
            var sensoren = JSON.parse(body)[0].sensoren;
            var solltemp = JSON.parse(body)[0];
            
            var rl_temp = sensoren[0].wert;
            setState('Controme.kueche.rl_temp', Math.round(10*rl_temp)/10, true);
            var frt_temp = sensoren[1].wert.Temperatur;
            setState('Controme.kueche.frt_temp', Math.round(10*frt_temp)/10, true);
            var rl_akt = sensoren[0].letzte_uebertragung;
            setState('Controme.kueche.rl_akt', rl_akt, true);
            var frt_akt = sensoren[1].letzte_uebertragung;
            setState('Controme.kueche.frt_akt', frt_akt, true);
            var soll = solltemp.solltemperatur;
            setState('Controme.kueche.solltemperatur', Math.round(10*soll)/10, true);
                 }   
    });
}

function alledaten() {
    controme_kueche();
    controme_schlafzimmer();
    controme_wohnzimmer();
    controme_abstellkammer();
    controme_badezimmer();
    controme_flur();
    controme_arbeitszimmer();
    controme_esszimmer();
    controme_hkv();
    controme_vsensor1();
}
schedule('*/1 * * * *', alledaten); // alle 15 Minuten

So the question is - is someone using iobroker and melcloud and has done something like that or has anybody any idea how to do it ? I would like to learn out of this but I have no idea and I am a bloody newbe.

Any ideas ... Thanks so far ...

Best regards,
Marc
Reply
#7
Start by checking HTTP communication. This script will send a GET request and log the result (change IP as needed):
Code:
url = 'http://192.168.1.12/get/json/v1/1/temps/1/'

http = require('socket.http')
require('json')
http.TIMEOUT = 5

data, err = http.request(url)
log(data, err)
Reply
#8
Hey, thanks for your reply ... :-)

It seems I can not use it in iobroker as a Javascript. I get errors on the log:

javascript.0 2020-02-05 18:36:42.446 error (13885) at Script.runInContext (vm.js:133:20)
javascript.0 2020-02-05 18:36:42.445 error (13885) at script.js.Mitsubishi.Skript_1:5:14
javascript.0 2020-02-05 18:36:42.445 error (13885) TypeError: Cannot set property 'TIMEOUT' of undefined
javascript.0 2020-02-05 18:36:42.445 error (13885) ^
javascript.0 2020-02-05 18:36:42.445 error (13885) http.TIMEOUT = 5
javascript.0 2020-02-05 18:36:42.444 error (13885) script.js.Mitsubishi.Skript_1: script.js.Mitsubishi.Skript_1:5
javascript.0 2020-02-05 18:36:42.443 error (13885) at Script.runInContext (vm.js:133:20)
javascript.0 2020-02-05 18:36:42.442 error (13885) at script.js.Mitsubishi.Skript_1:4:1
javascript.0 2020-02-05 18:36:42.442 error (13885) script.js.Mitsubishi.Skript_1: Error: Cannot find module '/opt/iobroker/node_modules/iobroker.javascript/lib/../../json'
javascript.0 2020-02-05 18:36:42.439 error (13885) at Script.runInContext (vm.js:133:20)
javascript.0 2020-02-05 18:36:42.439 error (13885) at script.js.Mitsubishi.Skript_1:3:8
javascript.0 2020-02-05 18:36:42.439 error (13885) script.js.Mitsubishi.Skript_1: Error: Cannot find module '/opt/iobroker/node_modules/iobroker.javascript/lib/../../socket.http'

Maybe I need to run the script elswhere but not in iobroker ? If yes, how and where ...

For URL I need to use the melcloud, I guess. But before I need to logon there ... see the script in topic #4 - I tried this also in iobroker but has errors in log also ... seems not to be JAVA.

If possible I should login with Java, then find possible devices and the create the datapoints ...


Best regards,
Marc
Reply
#9
My example is in Lua for LM Smile
Reply


Forum Jump: