parabellum a écrit:@Dominic :
dans eedomus, les parametres doivent etre les suivants:
VAR1: tutut@totto.com:motdepass.....ça c'est bon, j'imagine
VAR2: nomdelaclim.....et pas le nom de ta maison, donc=> Chambre
VAR3: vide ou off...mais pas la valeur par défaut: plugin.parameter.session
en espérant que ça suffise.
pour les ID, ce n'est pas la peine, le script se charge de les recupérer d'apres le nom de ta clim et ton login/psw
sdk_connect($username, $password);
$json = httpQuery("https://app.melcloud.com/Mitsubishi.Wifi.Client/User/ListDevices", "GET", "", "", sdk_getHeader(), false);
$result = sdk_json_decode($json);
$devices = $result[0]['Structure']['Devices'];
merguez07 a écrit:
As tu un lien vers leur API ?
sdk_connect($username, $password);
$json = httpQuery("https://app.melcloud.com/Mitsubishi.Wifi.Client/User/ListDevices", "GET", "", "", sdk_getHeader(), false);
$devices = $result[0]['Structure']['Devices'];
$devices = $result['Structure']['Floors'][0]['Devices'];
<?php
/******modifié par Merguez07
****** le 04 Mai 2020*****/
function sdk_getHeader(){
$contextKey = loadVariable('ContextKey');
return array("X-MitsContextKey: $contextKey", "Content-Type: application/json");
}
/**
* Get Building Id and DeviceId from deviceName
* DeviceNme could be full name or serial number recored in melcloud
*
* */
function sdk_setIds($moduleId, $deviceName, $username, $password){
$json = httpQuery("https://app.melcloud.com/Mitsubishi.Wifi.Client/User/ListDevices?id=227688", "GET", "", "", sdk_getHeader(), false);
$result = sdk_json_decode($json);
if (isset($result['Success'])) {
sdk_connect($username, $password);
$json = httpQuery("https://app.melcloud.com/Mitsubishi.Wifi.Client/User/ListDevices?id=227688", "GET", "", "", sdk_getHeader(), false);
$result = sdk_json_decode($json);
}
$Floors=$result[0]['Structure']['Floors'];
foreach ($Floors as $Floor){
$Tdevices=$Floor['Devices'];
foreach ($Tdevices as $device){
$devices[]=$device;
}
}
foreach ($devices as $device){
if ($device['DeviceName'] == $deviceName || $device['SerialNumber'] == $deviceName){
saveVariable($moduleId.'-buildingId', $device['BuildingID']);
saveVariable($moduleId.'-deviceId', $device['DeviceID']);
}
}
}
/**
* Log and set ContextId
*
* */
function sdk_connect( $username, $password ){
$headers = sdk_getHeader();
$jsonTest = '{Email: "' . $username . '", Password: "' . $password . '", Language: 7, AppVersion: "1.15.3.0", Persist: true}';
$login = httpQuery('https://app.melcloud.com/Mitsubishi.Wifi.Client/Login/ClientLogin', 'POST', $jsonTest, '', $headers, false);
$loginResult= sdk_json_decode($login);
if ($loginResult['ErrorId'] == null) {
$contextKey = $loginResult['LoginData']['ContextKey'];
saveVariable('ContextKey', $contextKey);
} else
echo "Erreur de login " . "<br>";//TODO : handle exceptions*/
}
/**
* Get informations from MelCloud
* rebuild context if needed
* rebuild buildingId and DeviceId if needed
*
* */
function sdk_get($moduleId, $deviceName, $username, $password){
$contextKey = loadVariable('ContextKey');
if ($contextKey == '') sdk_connect($username, $password);
//get building ids
$buildingId = loadVariable($moduleId.'-buildingId');
$deviceId = loadVariable($moduleId.'-deviceId');
if ($buildingId == ''){
sdk_setIds($moduleId, $deviceName, $username, $password);
$buildingId = loadVariable($moduleId.'-buildingId');
$deviceId = loadVariable($moduleId.'-deviceId');
}
$json = httpQuery("https://app.melcloud.com/Mitsubishi.Wifi.Client/Device/Get?id=$deviceId&buildingID=$buildingId", "GET", "", "", sdk_getHeader(), false);
$result = sdk_json_decode($json);
//if (count($device) == 2) {//if no session only 2 datas are raised : { Success: false, ErrorMessage: ""}
if (isset($result['Success']) && $result['Success'] == false) {
sdk_connect($username, $password);
$json = httpQuery("https://app.melcloud.com/Mitsubishi.Wifi.Client/Device/Get?id=$deviceId&buildingID=$buildingId", "GET", "", "", sdk_getHeader(), false);
}
return $json;
}
$deviceName = getArg('deviceName');
$userPass = getArg('userpass');
$tabUserPass = explode(":", $userPass);
$username = $tabUserPass[0];
$password = $tabUserPass[1];
//get parameters
$onoff = getArg('power', false, "");
$fanspeed = getArg('fanspeed', false, "");
$temperature = getArg('temperature', false, "");
$mode = getArg('mode', false, '');
/*
* 1 => Heating
* 8 => Auto
* 7 => Fan
* 2 => Drying
* 3 => Cooling
*/
$moduleId = getArg('eedomus_controller_module_id');
/**
* Session managing
*
* off => nothing recorded
* contextOnly => buildingid and contextid not recorded
* idsOnly => contextKey not recorded
* azzerty => change contextKey to defaut value to test timeouts
*
*/
$resetSession = getArg('session', false, '');
if ($resetSession == "off") {
saveVariable('ContextKey', '');
saveVariable($moduleId.'-buildingId', '');
saveVariable($moduleId.'-deviceId', '');
}else if ($resetSession == "contextOnly") {
saveVariable($moduleId.'-buildingId', '');
saveVariable($moduleId.'-deviceId', '');
} else if ($resetSession == "idsOnly") {
saveVariable('ContextKey', '');
sdk_connect($username, $password);
} else if ($resetSession == "azerty") {
saveVariable('ContextKey', 'azerty');
}
$json = sdk_get($moduleId, $deviceName, $username, $password);
$device = sdk_json_decode($json);
$resultat = "";
if ($onoff != "") {
$aremplacer = array('"Power":false', '"Power":true');
$json = str_replace($aremplacer, '"Power":' . $onoff, $json);
$aremplacer = '"EffectiveFlags":' . $device['EffectiveFlags'];
$json = str_replace($aremplacer, '"EffectiveFlags":1', $json);
$aremplacer = '"HasPendingCommand":false';
$json = str_replace($aremplacer, '"HasPendingCommand":true', $json);
$json = httpQuery('https://app.melcloud.com/Mitsubishi.Wifi.Client/Device/SetAta', 'POST', $json, '', sdk_getHeader(), false);
} else if ($fanspeed != "") {
$aremplacer = '"SetFanSpeed":' . $device['SetFanSpeed'];
$json = str_replace($aremplacer, '"SetFanSpeed":' . $fanspeed, $json);
$aremplacer = '"EffectiveFlags":' . $device['EffectiveFlags'];
$json = str_replace($aremplacer, '"EffectiveFlags":8', $json);
$aremplacer = '"HasPendingCommand":false';
$json = str_replace($aremplacer, '"HasPendingCommand":true', $json);
$json = httpQuery('https://app.melcloud.com/Mitsubishi.Wifi.Client/Device/SetAta', 'POST', $json, '', sdk_getHeader(), false);
} else if ($temperature != "") {
$aremplacer = '"SetTemperature":' . $device['SetTemperature'];
$json = str_replace($aremplacer, '"SetTemperature":' . $temperature, $json);
$aremplacer = '"EffectiveFlags":' . $device['EffectiveFlags'];
$json = str_replace($aremplacer, '"EffectiveFlags":4', $json);
$aremplacer = '"HasPendingCommand":false';
$json = str_replace($aremplacer, '"HasPendingCommand":true', $json);
$json = httpQuery('https://app.melcloud.com/Mitsubishi.Wifi.Client/Device/SetAta', 'POST', $json, '', sdk_getHeader(), false);
} else if ($mode != "") {
$aremplacer = '"OperationMode":' . $device['OperationMode'];
$json = str_replace($aremplacer, '"OperationMode":' . $mode, $json);
$aremplacer = '"EffectiveFlags":' . $device['EffectiveFlags'];
$json = str_replace($aremplacer, '"EffectiveFlags":6', $json);
$aremplacer = '"HasPendingCommand":false';
$json = str_replace($aremplacer, '"HasPendingCommand":true', $json);
$json = httpQuery('https://app.melcloud.com/Mitsubishi.Wifi.Client/Device/SetAta', 'POST', $json, '', sdk_getHeader(), false);
}
echo jsonToXML($json);
merguez07 a écrit:bon je me suis fait une modif qui fonctionne chez moi.
A vous de tester et de me dire (il suffit de remplacer l'ancien script par celui ci dessous)
[/code]
Retour vers Scripts & Périphériques du store
Utilisateurs parcourant ce forum : Aucun utilisateur inscrit et 37 invité(s)