Toshiba home AC control

Hello Everyone,

My first time on this forum.

I have set up a Toshiba AC system with this wifi controlled system you are talking about, in our offices.

However i have trouble connecting the module to our wifi network, as we have a firewall that prevents all “foreign” connections. My IT department is asking me what web port have they got to open to make it work?

I’ve been frantically searching online and haven’t found any hope… until i came across this forum.

Anyone coud help me on that one?

Thanks a lot.

hello and welcome.
the wifi adapter is making an connection to the outside: 51.144.118.31 to port 8883 and uses a tls encrypted amqp protocol.
your app is also connecting to that server, so normally no direct connection is necessary. unless maybe during pairing. if the company wifi is too restrictive i would take a second mobile phone open an wifi hotspot with the same credentials and do the initial pairing there.

good luck.

hello
the code should be used in home assistant or separately?
how does it work?

@h4de5 I have digged a bit into AMQP connection. I’ve managed to capture some decrypted communication in wireshark (with mitmproxy) but it stops working when establishing AMQP communication. It seems like we have multiple levels of encapsulation. Firts TLS connection is established with toshibasmaciothubprod.azure-devices.net, then websocket is created:

Hypertext Transfer Protocol
    GET /$iothub/websocket HTTP/1.1\r\n
    Host: toshibasmaciothubprod.azure-devices.net:443\r\n
    Connection: Upgrade\r\n
    Upgrade: websocket\r\n
    Sec-WebSocket-Version: 13\r\n
    Sec-WebSocket-Key: ######
    Sec-WebSocket-Protocol: AMQPWSB10\r\n
    \r\n
    [Full request URI: https://toshibasmaciothubprod.azure-devices.net:443/$iothub/websocket]
    [HTTP request 1/1]
    [Response in frame: 1822]

Server accepts websocket communication:

Hypertext Transfer Protocol
    HTTP/1.1 101 Switching Protocols\r\n
    Upgrade: websocket\r\n
    Server: Microsoft-HTTPAPI/2.0\r\n
    Sec-WebSocket-Protocol: AMQPWSB10\r\n
    Connection: Upgrade\r\n
    Sec-WebSocket-Accept: ######
    Date: Fri, 20 Aug 2021 12:16:45 GMT\r\n
    \r\n
    [HTTP response 1/1]
    [Time since request: 0.033266349 seconds]
    [Request in frame: 1821]
    [Request URI: https://toshibasmaciothubprod.azure-devices.net:443/$iothub/websocket]

This should create websocket with protocol AMQPWSB10 which is AMQP version 1.0. Unfortunately at this stage my connection is breaking - mitmproxy has some problem handling this further.

As this is MS Azure AMQP API this may help: GitHub - Azure/azure-uamqp-python: AMQP 1.0 client library for Python, but I haven’t tried it yet.

@h4de5 I have mannaged to connect to AMQP and I’m receiving state change notifications for my AC.

I’ve done this with azure-iot-device python package and following code: Toshiba Home AC AMQP connection · GitHub. You have to fill your device id and shared key.

When I change something on my AC it generates output similar to this:

Method handler
smmobile
1
{'sourceId': '######', 'messageId': '######', 'targetId': ['######'], 'cmd': 'CMD_FCU_FROM_AC', 'payload': {'data': '30ffffffffffffffffffffffffffffffffffff'}, 'timeStamp': '21:44:55.5649670'}

Now I need to add encoder/decoder for state of AC and try to control it from python.

Can we use your script to generate device id and shared key or this is something we can only read from android property store?

nice.
unfortunatelly I did not find another way to get those ids.

@Didier3L the script needs to run stand alone at the moment, even it was planed to be integrated into HA. but for the whole “idea” to use the scheduler to send updates to the AC: this did not turn out to be working. so think I’ll retire that again.

but I will definitelly have a look into the AMQP setup asap.

I just tried it too - and I do get updates from the API - can you prepare a script which will send something to the API server?

example data:

turn off:
{‘sourceId’: ‘xxxx’, ‘messageId’: ‘0000000090’, ‘targetId’: [‘yyyyyy’], ‘cmd’: ‘CMD_FCU_TO_AC’, ‘payload’: {‘data’: ‘31ffffffffffffffffffffffffffffffffffff’}, ‘timeStamp’: ‘0061217209’}

turn on and change fanspeed to low:
{‘sourceId’: ‘xxxx’, ‘messageId’: ‘0000000090’, ‘targetId’: [‘yyyyyy’], ‘cmd’: ‘CMD_FCU_TO_AC’, ‘payload’: {‘data’: ‘30ffff20ffffffffffffffffffffffffffffff’}, ‘timeStamp’: ‘0061217209’}

timeStamp: current timestamp converted to hex + two leading zeros

payload:

example fan speed settings (and for a little more see const.py in github code)

quiet = 0x1F,
low = 0x20,
lowPlus = 33,
medium = 34,
mediumPlus = 35,
high = 36

here you can see what those positions actually means - while ff always declare not to change any settings for this function:

# see: SmartAC.Services.MQTTServices.MqttSendCmdJson

_operationStatus = "ff";
_mode = "ff";
_temp = "ff";
_fanSpeed = "ff";
_airSwing = "ff";
_powerSelection = "ff";
_meritFeature = "ff";
_pure = "ff";
_indoorTemp = "ff";
_outdoorTemp = "ff";
_errorCode = "ff";
_timerType = "ff";
_relativeHours = "ff";
_relativeMins = "ff";
_selfCleaning = "ff";
_ledStatus = "ff";
_schedulerStatus = "ff";
_utcHours = "ff";
_utcMins = "ff";

return _operationStatus + _mode + _temp + _fanSpeed + _airSwing + _powerSelection + _meritFeature + _pure + _indoorTemp + _outdoorTemp + _errorCode + _timerType + _relativeHours + _relativeMins + _selfCleaning + _ledStatus + _schedulerStatus + _utcHours + _utcMins;

@h4de5 I have made some progress - I can turn on/off my AC from python. Rest of the commands just needs further parsing and creating some API for them. I have created library here: GitHub - KaSroka/Toshiba-AC-control: Python controller for Toshiba AC please check its README for further info.

What’s missing:

  • Load current state from HTTP API (as discovered by @h4de5) as AMQP only notifies about changes - we need to know initial state after connection. Loading current state on init, also reloading from HTTP periodically as well (just in case).
  • Parse all the fields from fcu reports (currently only some information is parsed)
  • Extract SHARED_ACCESS_KEY, DEVICE_ID and AC_ID from HTTP API (@h4de5 in decompiled SmartAC.Services.ACServices.ACDeviceServices there is a method called GetACDeviceProvisioned which returns RegisterMobileDeviceRespObj that should contain shared access key - can you please check if this works? It requests /api/AC/GetRegisteredACByUniqueId with HTTP GET and ACUniqueId set to device ID) Done, now APP login info is only required.

EDIT: Latest version uses APP login info to fetch all required data, initial AC state and required tokens are fetched using HTTP API and further state updates are handled by AMQP.

Heartbeat notification also provides some nice data.

2 Likes

just want to confirm: its working!

how do we progress from here? do you want to create an home-assistant integration from it? or would you provide your code as pypi package?

It will be nice to get some help. I’ve never created home-assistant integration. Also, library also needs some polishing - it’s missing a lot of error handling and python is not my primary language. Any help is appreciated.

Also I’ve updated the lib - sample has now some GUI in tkinter (I’ve tested in on linux only)

I never created a python package myself, but I think you are on a good track.

I know some basic home-assistant stuff, due to an integration I did for another system. usually we split up the API part (any code that actually communicates with the devices or hubs) and the HA stuff (everything else, that helps home-assistant create and use new entites).
the existing toshiba repository includes most of the boilerplate code for a new integration already. I’ll have a look and add a simple climate entity to it in the next days.

I think the best would be to release this on pypi and create separate repo for HA integration. This way we can separate lib from integration - I think that HA requires this.

exactly.
I updated the toshiba integration. it uses your github repo directly (so for testing we do not need a pypi package - but we should have one later)

if you add it as custom component, it should show up in the integration list:

image

if you enter the correct user + password it should create one climate entity for each device you have connected:

image

currently its possible to turn the device on and off, change modes, target temperature and fan speed.

image

it misses the current temperature as well as settings for the power level.
also there seem to be an issue on my side with the updates back to HA - so any changes made to the device will not show up in HA.

1 Like

It works!

I have created a PR with fix for HA update.

When adding the integration, fields for user name and password doesn’t have any names so user have to guess what to type in.

Also, I wonder if we need Toshiba-AC-control as submodule. It’s already installed by HA from requirements list:

  "requirements": [
    "azure-iot-device",
    "httpx",
    "toshiba_ac @ git+https://github.com/KaSroka/Toshiba-AC-control.git#egg=toshiba_ac"
  ],

I’ve made a simple fix in Toshiba-AC-control with temperature state (None was reported by error), but as Toshiba-AC-control is installed by HA I don’t know how to force its update, any idea?

Today I’m a bit busy but I’ll try to add parsing for other state informations, especially current temperature tomorrow.

1 Like

yes - the submodule can be removed, I just had it for debugging.

usually it should be enough to restart home-assistant to get the newer version.

great - i’ll have a look at it tomorrow as well then.

Cool! Just tested and it worked fine also for me :+1:

Well done, @kamaloo92 and @h4de5

I tried to follow, but I’m a bit lost here. Can somebody tell me what to download and install as custom component?

Thanks!

@yodi thanks!
@haseat you should use this as custom component: GitHub - h4de5/home-assistant-toshiba_ac: Toshiba AC integration into home-assistant.io please remember that this is still a work in progress and may not work/break your HA

Question to Toshiba HVAC owners:
What’s your min and max temperature? Mine goes from 17 to 30 and for others it returns invalid. Is this for all Toshiba HVAC?

1 Like

Thanks a lot! I installed it, and it works fine! And I’m happy to be a beta tester :wink:

In my Toshiba Home AC Control app I can set the temperature from 17 to 30. If I set it to anything lower than 17 in home assistant via your integration, it just jumps back to the last valid value (checked in the Toshiba app). If I set it to anything above 32 in home assistant, it will not change the value in the Toshiba app, it just stays at the last valid value, but in home assistant it will stay to whereever I set it.

If I can anything to help you with testing, please let me know.

Mine are also min/Max 17-30