Skip to content

Instantly share code, notes, and snippets.

@h4de5
Last active October 16, 2023 19:45
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h4de5/7f97db0f4efc265e48904d4a84dab4fb to your computer and use it in GitHub Desktop.
Save h4de5/7f97db0f4efc265e48904d4a84dab4fb to your computer and use it in GitHub Desktop.
Toshiba AC API Client - Get status and settings from Toshiba AC Services (used e.g. in RAS-18PKVSG-E + RAS-18PAVSG-E + WIFI Adapter RB-N103S-G)
#!/usr/local/bin/php73
<?php
$username = "YOUR_USERNAME";
$password = "YOUR_PASSWORD";
/**
* @param string $url
* @param string $post
* @param string $token
* @return []
*/
function query($url, $post = null, $token = null) {
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
if (!empty($post)) {
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
$header = [
'Content-Type: application/json'
];
if (!empty($token)) {
$header[] = 'Authorization: Bearer ' . $token;
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
// echo $result . PHP_EOL;
if (!empty($result)) {
return json_decode($result, true);
} else {
echo "Error in query: " . $url . PHP_EOL;
return false;
}
}
// $base_url = "https://toshibamobileservice.azurewebsites.net";
// new url since 2022-07-14
$base_url = "https://mobileapi.toshibahomeaccontrols.com";
$login_url = "/api/Consumer/Login";
$device_url = "/api/AC/GetRegisteredACByUniqueId";
$mapping_url = "/api/AC/GetConsumerACMapping";
$status_url = "/api/AC/GetCurrentACState";
$settings_url = "/api/AC/GetConsumerProgramSettings";
echo '//////////////////////////////////////////////////////////' . PHP_EOL;
///////////// LOGIN RESULT
//The data you want to send via POST
$fields = [
'Username' => $username,
'Password' => $password
];
// url-ify the data for the POST
$fields_string = json_encode($fields);
$result_object = query($base_url . $login_url, $fields_string);
var_export($result_object) . PHP_EOL;
// Store access token and consumerId for further calls
$access_token = $result_object['ResObj']['access_token'];
$consumerId = $result_object['ResObj']['consumerId'];
echo '//////////////////////////////////////////////////////////' . PHP_EOL;
///////////// MAPPING RESULT
$fields = http_build_query([
'consumerId' => $consumerId
]);
$result_object = query($base_url . $mapping_url . '?' . $fields, null, $access_token);
var_export($result_object) . PHP_EOL;
// store first AC id
$deviceId = $result_object['ResObj'][0]['ACList'][0]['Id'];
echo '//////////////////////////////////////////////////////////' . PHP_EOL;
///////////// DEVICE STATUS RESULT
$fields = http_build_query([
'ACId' => $deviceId
]);
$result_object = query($base_url . $status_url . '?' . $fields, null, $access_token);
var_export($result_object) . PHP_EOL;
echo '//////////////////////////////////////////////////////////' . PHP_EOL;
///////////// DEVICE SETTING RESULT
$fields = http_build_query([
'consumerId' => $consumerId
]);
$result_object = query($base_url . $settings_url . '?' . $fields, null, $access_token);
var_export($result_object) . PHP_EOL;
echo '//////////////////////////////////////////////////////////' . PHP_EOL;
{
"ResObj": {
"access_token": "KxxA",
"token_type": "bearer",
"expires_in": 1xx9,
"consumerId": "5xx3",
"countryId": 15,
"consumerMasterId": "4xxb"
},
"IsSuccess": true,
"Message": "Success",
"StatusCode": "Success"
}
{
"ResObj": [
{
"GroupId": "7xx8",
"GroupName": "All",
"ConsumerId": "5xx3",
"TimeZone": "W. Europe Standard Time",
"ACList": [
{
"Id": "5xx1",
"DeviceUniqueId": "4xx8",
"Name": "Klima",
"ACModelId": "1",
"Description": "AC_4xx8",
"CreatedDate": "xx\/xx\/xxxx 12:02:36 PM",
"ACStateData": "31421a3131640010197ffe0b00001002010000",
"FirmwareUpgradeStatus": "",
"URL": "",
"File": "",
"MeritFeature": "0000",
"AdapterType": null,
"FirmwareVersion": "x.x.x.xxxx",
"FirmwareCode": null,
"ModeValues": [
{
"Mode": "41",
"Temp": "16",
"FanSpeed": "41"
},
{
"Mode": "42",
"Temp": "1a",
"FanSpeed": "31"
},
{
"Mode": "43",
"Temp": "1b",
"FanSpeed": "31"
},
{
"Mode": "44",
"Temp": "16",
"FanSpeed": "41"
},
{
"Mode": "45",
"Temp": "16",
"FanSpeed": "36"
}
],
"Control": null
}
]
}
],
"IsSuccess": true,
"Message": "Success",
"StatusCode": "Success"
}
{
"ResObj": {
"ConsumerId": "5xx3",
"ACGroupProgramSettings": [
{
"ACProgramSettingList": [
{
"ACId": "5xx1",
"ConsumerId": null,
"ACUniqueId": "4xx8",
"ACName": "Klima",
"ACModel": "1",
"Type": null,
"dstStatus": "ON",
"timeZone": "W. Europe Standard Time",
"schedulerStatus": "01",
"ACStateDataForProgram": "31421a3131640010197ffe0b00001002010000",
"MeritFeature": "0000",
"PartitionKey": null,
"programSetting": {
"Sunday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
},
"Monday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
},
"Tuesday": {
"p1": "103030421832ff41",
"p2": "111531ffffffffff",
"p3": "173030421831ff41",
"p4": "190031ffffffffff"
},
"Wednesday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
},
"Thursday": {
"p1": "103030421832ff41",
"p2": "111531ffffffffff",
"p3": "173030421831ff41",
"p4": "190031ffffffffff"
},
"Friday": {
"p1": "103030421832ff41",
"p2": "111531ffffffffff",
"p3": "173030421831ff41",
"p4": "190031ffffffffff"
},
"Saturday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
}
},
"time": null,
"dst": {
"Time": "1635649200",
"Status": "OFF"
}
}
],
"PartitionKey": null,
"GroupId": "7xx8",
"ConsumerId": "5xx3",
"GroupName": "All",
"Type": null,
"programSetting": {
"Sunday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
},
"Monday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
},
"Tuesday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
},
"Wednesday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
},
"Thursday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
},
"Friday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
},
"Saturday": {
"p1": "",
"p2": "",
"p3": "",
"p4": ""
}
},
"time": "",
"dst": {
"Time": "",
"Status": ""
}
}
]
},
"IsSuccess": true,
"Message": "Success",
"StatusCode": "Success"
}
{
"ResObj": {
"Id": "9xx4",
"ACId": "5xx1",
"ACDeviceUniqueId": "4xx8",
"ACStateData": "3xx0",
"OnOff": "31",
"FirmwareVersion": "x.x.x.xxxx",
"FirmwareUpgradeStatus": "",
"URL": "",
"File": "",
"MeritFeature": "0000",
"VersionInfo": "0xxxx0",
"FirmwareCode": null,
"AdapterType": null,
"UpdatedDate": "xx-xx-xxTxx:xx:xx.xxxZ",
"Lat": 0,
"Long": 0,
"Model": "1",
"ModeValues": [
{
"Mode": "41",
"Temp": "16",
"FanSpeed": "41"
},
{
"Mode": "42",
"Temp": "1a",
"FanSpeed": "31"
},
{
"Mode": "43",
"Temp": "1b",
"FanSpeed": "31"
},
{
"Mode": "44",
"Temp": "16",
"FanSpeed": "41"
},
{
"Mode": "45",
"Temp": "16",
"FanSpeed": "36"
}
],
"IsMapped": false,
"FirstConnectionTime": "xx-xx-xxTxx:xx:xx.xxxZ",
"LastConnectionTime": "xx-xx-xxTxx:xx:xx.xxxZ",
"Cdu": null,
"Fcu": null,
"ConsumerMasterId": "4xxb",
"PartitionKey": "4xx8"
},
"IsSuccess": true,
"Message": "Get Current AC State Successful",
"StatusCode": "GetCurrentACStateSuccess"
}
@h4de5
Copy link
Author

h4de5 commented Jul 6, 2021

@QuitayenKA16
Copy link

how did you set up an account to use for username/password?

@h4de5
Copy link
Author

h4de5 commented Sep 14, 2022

there are: toshiba home ac control and toshiba ac control:

https://play.google.com/store/apps/details?id=com.toshibatctc.SmartAC

it does not work for the devices distributed in america (toshiba ac na). for those search for midea

@ifixr
Copy link

ifixr commented Oct 6, 2022

Hi, I wonder if you could port this to homebridge as well? That would be awesome.

@h4de5
Copy link
Author

h4de5 commented Oct 7, 2022

as i do not have any homekit/homebridge devices at home, i do not plan to integrate it.

but there is a python library that can be a good start for other integrators: https://github.com/KaSroka/Toshiba-AC-control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment