Posts: 41
Threads: 9
Joined: Apr 2018
Reputation:
0
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
Posts: 8509
Threads: 47
Joined: Jun 2015
Reputation:
486
Can you send cloud login/password via PM so I can provide a working example?
Posts: 41
Threads: 9
Joined: Apr 2018
Reputation:
0
Posts: 8509
Threads: 47
Joined: Jun 2015
Reputation:
486
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
Posts: 41
Threads: 9
Joined: Apr 2018
Reputation:
0
Nice! Thank you very much :-)
Posts: 2
Threads: 0
Joined: Feb 2020
Reputation:
0
(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
Posts: 8509
Threads: 47
Joined: Jun 2015
Reputation:
486
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)
Posts: 2
Threads: 0
Joined: Feb 2020
Reputation:
0
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
Posts: 8509
Threads: 47
Joined: Jun 2015
Reputation:
486
My example is in Lua for LM
Posts: 2
Threads: 0
Joined: Jul 2020
Reputation:
0
Hi there
Has anyone experience controlling (starting and stopping) a MELCloud-Device (AC)?
I successfully get the context key to authenticate myself and am able to get a list with devices, also with the Device-IDs, but I fail to start or stop a device.
Also, because my customer has multiple devices the returned json-string for all device-data is too long to display and decode for LogicMachine. Is there a way to split the returned json-string?
I found this thread to start and stop the device via powershell and adapted it to LUA:
Control-MELCloudDevice/Start-MELCloudDevice.psm1 at master · freddiecode/Control-MELCloudDevice · GitHub
Control-MELCloudDevice/Stop-MELCloudDevice.psm1 at master · freddiecode/Control-MELCloudDevice · GitHub
According to the MELCloud website and app, I'm successfully able to start and stop the device. Because when I send the commands, it shows the appropriate state immediately. So the command is sent successfully to the cloud. Unfortunately the device itself doesn't change the state. Also on the MELCloud website and app, the state changes a few seconds after to the original state (probably because MELCloud syncs the state with the device and refreshes it on the MELCloud). So the command isn't sent successfully from MELCloud to the device.
Also I'd like to get the current state of the device. But as the returned json-string from the devices is too long, i can't decode it.
Thank you in advance!
Posts: 8509
Threads: 47
Joined: Jun 2015
Reputation:
486
You can put JSON string into storage and then use Storage viewer app.
Posts: 2
Threads: 0
Joined: Jul 2020
Reputation:
0
(09.01.2026, 09:21)admin Wrote: You can put JSON string into storage and then use Storage viewer app.
Great, I'll try this. Thanks!
Do you also have an approach for the starting/stopping-issue?
I think this may be a security/trust-issue and that something in my command may be missing (in the header or in the body part. For example a correct time-stamp in the body part, as shown in the PowerShell-Example), in order to establish a "trusted" connection and successfully send the command to the device, and not only to the MELCloud.
Posts: 8509
Threads: 47
Joined: Jun 2015
Reputation:
486
Log and see what your Lua codes sends compared to the original PowerShell script. If PowerShell scripts works fine then adjust your Lua code to match the sent headers and body data.
|