Samsung AC

Keep us posted if you succeed. Thanks

Sure, first stop is SSL
the units use SSLv3 cyphers which are right now deprecated in openssl, so if I try to interrogate it using curl I get back

3069289680:error:14082174:SSL routines:SSL3_CHECK_CERT_AND_ALGORITHM:dh key too small:s3_clnt.c:3435:

Ok most of my informations come from here:


I don’t know the status of the home-assistant component, so I start from the basic.

The first problem is that the AC uses a weak DH key, so in order to communicate we need to use the correct cipher, after some trial I’ve been able to ko past the dh key too small error with those:
-cipher 'HIGH:!DH:!aNULL'

so for curl:
curl -k --cert cert.pem https://192.168.1.166:2878 --ciphers 'HIGH:!DH:!aNULL'
and openssl:
openssl s_client -connect 192.168.1.166:2878 -cert cert.pem -cipher 'HIGH:!DH:!aNULL'

after I got an xml response now I have to understand how to request the token to authenticate

another little progress, by using the ruby code I found here:
https://bitbucket.org/CloCkWeRX/samsung-remote
made by some people hacking on samsung ACs

I’ve been able to see token exchange, still got a lot of errors, but at least I’ve been able to communicate with the AC
The only modification needed is to add this line of code:
context.ciphers = 'HIGH:!DH:!aNULL'
in lib/samsung.rb, after:
context = OpenSSL::SSL::SSLContext.new

to force ruby to not expose DH key exchange methods, which are deprecated in modern SSL libraries

now the next task is to port all of this to python, and see how to integrate with home-assistant, I have to see if there is still some code that is already in place

EDIT
Today I retried using openssl s_client command, and instead of immediately close the session this time I can send commands, so using:

openssl s_client -connect 192.168.1.202:2878 -cipher 'HIGH:!DH:!aNULL'
(differently from what stated in the openhab link the app certificate is not needed)
and pasting

after
DRC-1.00
<?xml version="1.0" encoding="utf-8" ?><Update Type="InvalidateAccount"/>

I get the token back

`<?xml version="1.0" encoding="utf-8" ?><Response Type="GetToken" Status="Ready"/>`
`<?xml version="1.0" encoding="utf-8" ?><Update Type="GetToken" Status="Completed" Token="33965903-XXXX-XXXX-XXXX-373832354144"/>`

and sending the request with token:
<Request Type="AuthToken"><User Token="33965903-XXXX-XXXX-XXXX-373832354144" /></Request>
I can authenticate
<?xml version="1.0" encoding="utf-8" ?><Response Type="AuthToken" Status="Okay" StartFrom="2017-05-15/15:10:39"/>

and check for status or turn on the AC
<Request Type="DeviceState" DUID="XXXXXXXXXXXX"></Request>

Here there is a node version of the connection code:


The best thing is that there are defined command names.
So here is my checklist:
  • Port the basic auth and send command code to python (this should be fairly easy to do)

  • Implement this as a hass component (this is a little bit harder)

  • Code the autodiscovery part (this is supported from the unit, but for me it’s already difficult code the component part)

2 Likes

Any updates on this ?

Hi, How’s it going.

I’m the guy that originally broke the reliance on samsung servers back in 2014 with Daniel O’Connor, and I’ve been pretty quiet on that front ever since (I’ve simply been content to ssh into my server and run the 3 commands I need against my AC)

But now I’m back, I’ve discovered Hass (and am using it, in fact about half way though the house rewire), and MQTT.

I’m not the greatest fan of Python any more, but I’m thinking about making a MQTT bridge to cover the basic functions like on, off, mode, temperature select.

Depending on how I go, I might make a direct connector for HASS (would probably still require an external daemon)

Would anyone be interested in such a diversion?

I should add, that initially I will only be coding up support for my units, but that in theory should give us quite a bit of compatibility, as far as I know the protocol hasn’t changed much tho the handshake might have.

3 Likes

Hi Freman. I have a Samsung F-AR24FSSSBWK1 wi-fi AC (uses https://www.samsungsmartappliance.com).

I am interested to try your solution!

id be very keen @Freman

Hi,
I have my key, how can I control the air conditioner?

Thanks

Until not officially integrated Samsung Air Conditioner (new protocol, port 8888). Here is my solution for that:

  1. Get your AC’s token. Follow this instructions: https://community.openhab.org/t/newgen-samsung-ac-protocol/33805/6

  2. Create a file control_samsungac.sh in HA config directory, and paste the following content:
    http://mieletunkhosting.com/control_samsungac.txt

  3. Replace the followings:
    a: 192.168.1.XX to your AC ip address
    b: rXXXXXXXXc to your token key
    c: /var/packages/homeassistant/target/var/cert.pem to your exactly path of the cert file

  4. Add this to configuration.yaml:
    configuration.yaml (1.5 KB)
    Change this /var/packages/homeassistant/target/var/control_samsungac.sh to your real path of your control_samsungac.sh

  5. Add this into automations.yaml:

automations.yaml (1.4 KB)

  1. And finally Group it via groups.yaml:

groups.yaml (239 Bytes)

And finally you get the following:

samsung_ac

Enjoy! If you have question, let me know!

3 Likes

HI,

Where should take those files: server.py, actest.py from ?

This is require only one time, so you can take anywhere. After you got the token key, you can delete them.

I meant where from should i take them :slight_smile: What script should them contain ?

As this is in the Openhab link:
actest.py:
http://mieletunkhosting.com/actest.py

Replace the AC IP and the cert file real path.

server.py:
http://mieletunkhosting.com/server.py

Replace the cert file real path.

If you need the cert file too, then: http://mieletunkhosting.com/cert.pem

:wink:

Do i also need the “test.py” ?

I see, so the test.py is the equal with the server.py :slight_smile:

  1. step: turn off your Samsung AC
  2. step: first terminal: python3 server.py
  3. step: second terminal: python3 actest.py
  4. step: power on the Samsung AC

first terminal output look like:

root@DS214Plus:/volume1/homes/admin# python3 server.py
Listening on localhost:8889

----- Request Start ----->

Request path: /devicetoken/response
Content Length: 0
Request headers: Host: 192.168.1.XXX:8889
Accept: /

X-API-Version : v1.0.0
Content-Type: application/json
Content-Length: 28

Request payload: b’{“DeviceToken”:“rXXXXXXXXc”}’
Body: <main.RequestHandler object at 0x2b360c30>
<----- Request End -----

192.168.1.XX - - [08/Jan/2019 14:44:23] “POST /devicetoken/response HTTP/1.1” 200 -

Thanks.
This is my output ( cant see the token ).

Listening on localhost:8889

----- Request Start ----->

Request path: /devicetoken/response
Content Length: 0
Request headers: Host: 192.168.0.41:8889
Accept: /

X-API-Version : v1.0.0
Content-Type: application/json
Content-Length: 28

Request payload: b’’
Body: <main.RequestHandler object at 0x76b24530>
<----- Request End -----

Sorry, please replace the row 30 to:
print(“Request payload:”, self.rfile.read(28))

Anyway reuploaded to http://mieletunkhosting.com/server.py

OK i managed to do this. After restart of HA i get the error:
“[homeassistant.components.sensor.command_line] Command failed: /home/HA_0.80.3/control_samsungac.sh”

When tried to turn the AC on i got:

ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall shell_command.set_ac_power_boolean (c:5a30f748a4b34021a232181a00bbd3e2)>
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/core.py”, line 1177, in _event_to_service_call
await service_handler.func(service_call)
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/shell_command.py”, line 86, in async_service_handler
process = await create_process
File “/usr/local/lib/python3.6/asyncio/subprocess.py”, line 225, in create_subprocess_exec
stderr=stderr, **kwds)
File “uvloop/loop.pyx”, line 2603, in subprocess_exec
File “uvloop/loop.pyx”, line 2563, in __subprocess_run
File “uvloop/handles/process.pyx”, line 595, in uvloop.loop.UVProcessTransport.new
File “uvloop/handles/process.pyx”, line 102, in uvloop.loop.UVProcess._init
FileNotFoundError: [Errno 2] No such file or directory
2019-01-08 17:38:13 ERROR (MainThread) [homeassistant.core] Error executing service <ServiceCall shell_command.set_ac_temperature_slider (c:5a30f748a4b34021a232181a00bbd3e2)>
Traceback (most recent call last):
File “/usr/local/lib/python3.6/site-packages/homeassistant/core.py”, line 1177, in _event_to_service_call
await service_handler.func(service_call)
File “/usr/local/lib/python3.6/site-packages/homeassistant/components/shell_command.py”, line 86, in async_service_handler
process = await create_process
File “/usr/local/lib/python3.6/asyncio/subprocess.py”, line 225, in create_subprocess_exec
stderr=stderr, **kwds)
File “uvloop/loop.pyx”, line 2603, in subprocess_exec
File “uvloop/loop.pyx”, line 2563, in __subprocess_run
File “uvloop/handles/process.pyx”, line 595, in uvloop.loop.UVProcessTransport.new
File “uvloop/handles/process.pyx”, line 102, in uvloop.loop.UVProcess._init
FileNotFoundError: [Errno 2] No such file or directory
2019-01-08 17:38:13 ERROR (SyncWorker_18) [homeassistant.components.sensor.command_line] Command failed: /home/HA_0.80.3/control_samsungac.sh

I’ve been browsing all the issues and forums about controlling Samsung ACs, but all the solutions fail for me simply because the AC is not listening on either of those ports. I’ve tried turning it on and off around, but still nothing.
I have the Windfree AC model (if that somehow helps)

~ # nmap -sS -p 2878,8888 192.168.1.11
Starting Nmap 7.70 ( https://nmap.org ) at 2019-01-27 18:25 UTC
Nmap scan report for 192.168.1.11
Host is up (0.053s latency).

PORT     STATE  SERVICE
2878/tcp closed aap
8888/tcp closed sun-answerbook
MAC Address: 70:2C:1F:5F:2A:C1 (Wisol)

Nmap done: 1 IP address (1 host up) scanned in 1.12 seconds