Samsung Smart Air Conditioner - OpenHAB 2.0

Hi Jan,
I got the binding imported successful in OH3.0.1 but I am a bit stuck with getting the token.
What I did so far:

  1. Created (and formatted) the server.py and token.py inside /usr/share/openhab/addons
  2. Pulled the ac14k_.pem from here and renamed it to cert.pem
  3. Moved cert.pem to /etc/openhab/services
  4. I then executed `sudo python3 server.py’ whereas see following errors/output:
Error code

Traceback (most recent call last):
File “server.py”, line 1, in
from http.server import HTTPServer, BaseHTTPRequestHandler
File “/usr/lib/python3.7/http/server.py”, line 100, in
import shutil
File “/usr/lib/python3.7/shutil.py”, line 22, in
import bz2
File “/usr/lib/python3.7/bz2.py”, line 17, in
from threading import RLock
File “/usr/lib/python3.7/threading.py”, line 8, in
from traceback import format_exc as _format_exc
File “/usr/lib/python3.7/traceback.py”, line 5, in
import linecache
File “/usr/lib/python3.7/linecache.py”, line 11, in
import tokenize
File “/usr/lib/python3.7/tokenize.py”, line 35, in
from token import *
File “/usr/share/openhab/addons/token.py”, line 1, in
import requests
File “/usr/lib/python3/dist-packages/requests/init.py”, line 43, in
import urllib3
File “/usr/lib/python3/dist-packages/urllib3/init.py”, line 8, in
from .connectionpool import (
File “/usr/lib/python3/dist-packages/urllib3/connectionpool.py”, line 3, in
import logging
File “/usr/lib/python3.7/logging/init.py”, line 210, in
_lock = threading.RLock()
AttributeError: module ‘threading’ has no attribute ‘RLock’

I am a bit stuck :roll_eyes:

1 Like

I’m having the same issue. Hoping someone can help us :pray:

Try renaming your server.py, to something else, like sd_server.py. I think there is a conflicting module in python, named server.py

1 Like

There might be some ssl errors. If experienced, try implementing the solution at ssl - Certificate error after upgrade to 20.04 - Ask Ubuntu

Hi @jag
Thank you for the suggestion.
I tried changing the fike name, but I still get an error message.

pi@raspberrypi:/usr/share/openhab2/addons $ sudo mv server.py sd_server.py
pi@raspberrypi:/usr/share/openhab2/addons $ sudo python3 sd_server.py
Traceback (most recent call last):
  File "sd_server.py", line 1, in <module>
    from http.server import HTTPServer, BaseHTTPRequestHandler
  File "/usr/lib/python3.7/http/server.py", line 100, in <module>
    import shutil
  File "/usr/lib/python3.7/shutil.py", line 22, in <module>
    import bz2
  File "/usr/lib/python3.7/bz2.py", line 17, in <module>
    from threading import RLock
  File "/usr/lib/python3.7/threading.py", line 8, in <module>
    from traceback import format_exc as _format_exc
  File "/usr/lib/python3.7/traceback.py", line 5, in <module>
    import linecache
  File "/usr/lib/python3.7/linecache.py", line 11, in <module>
    import tokenize
  File "/usr/lib/python3.7/tokenize.py", line 35, in <module>
    from token import *
  File "/usr/share/openhab2/addons/token.py", line 1, in <module>
    import requests
  File "/usr/lib/python3/dist-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/usr/lib/python3/dist-packages/urllib3/__init__.py", line 8, in <module>
    from .connectionpool import (
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 3, in <module>
    import logging
  File "/usr/lib/python3.7/logging/__init__.py", line 210, in <module>
    _lock = threading.RLock()
AttributeError: module 'threading' has no attribute 'RLock'

Thanks Jan!
I got a step further, whereas not with your file.

Steps and status:
  1. I did a sudo git clone https://github.com/cicciovo/homebridge-samsung-airconditioner.git of this github repo
  2. Followed the advice given here as per your remark Jan
  3. Executed sudo python Server8889.py which successfully starts the server listening on port 8889
  4. In a new shell, executed curl -k -H "Content-Type: application/json" -H "DeviceToken: xxxxxxxxxxx" --cert /usr/local/lib/node_modules/homebridge-samsung-airconditioner/ac14k_m.pem --insecure -X POST https://192.168.1.152:8888/devicetoken/request changing the IP
  5. Sadly I am stuck as I get a curl: (7) Failed to connect to IP port 8888: Connection refused

I assume above is connected to the port (8888) which might be different ?!

edit: it might also be connected to this change Samsung did…

edit2: Did a port scan via NMAP and indeed it shows only ports 49153/49154/49155 UDP open…
samsungac.xml (15.2 KB)

@chrismast, your portscan does not find any tcp ports open. You could try to power off, and power on again. Then try curl (or portscan) within 3o seconds.
But may be Samsung AC has to be registered with Samsung Smart Things, to enable the http interface?
I don’t understand how the AC can be managed from SST, with only UDP open.

Port scan of my Samsung Digital Inverter

PORT     STATE SERVICE
8888/tcp open  sun-answerbook

Hello guys,

any updates on this here?
I got also new Samsung AC Windfree climate units with integrated WIFI modules (Modeltype AR07TXFCAWKNEU, Windfree Comfort NASA) which I want to integrate to openhab 2.5 .

I tried the Samsung a/c binding - which doesn´t work. Guess it´s quite old version and was running well with openhab1.x but not with newer versions of openhab / samsung AC´s.

So I also tried to use the Samsung Smartthings binding but obviously I would need to buy a Samsung Smartthings Hub? I´m using Hue Bridge already and don´t want to use another Hub from Samsung…I also was reading that Samsung discontinued the Hub already?

So long question short: How to get my Samsung Wifi AC units to openhab? Which binding to use? Any documentation available?

Thank you and best regards,
Mario

Hello.
To use the binding for Samsung Digital Inverter, you have to download a token, which is unique for your device. This must be done before configuring thee binding.
I don’t know if you device will accept http, as others have had problems connecting to newer devices (Windfree). If your device does not support http, then my binding will not support it.

I followed the instrucstions → start openhab2 service in debug mode and searched the logs for AirConditioner. Turned on and off the AC but I don´t get one single entry in my log files like described here:

WARN  o.b.o.s.c.AirConditioner[:179]- NO TOKEN SET! Please switch off and on the air conditioner within 30 seconds  

So at the moment I don´t know how to continue…

Hello @Mario084 , seems like you are using the binding for the old type of Air Conditioner, I do not know that binding, and doubt it will work with modern devices. The old devices used XML, whereas the newer ones use json as information bearer.

Yes - that´s the version I can install directly under Add-Ons / Bindings.

Do you have a newer one?
Where to download?

Thx!

Okay I found your latest Binding and instructions…

The webserver is up and running

[21:49:40] openhabian@openhab:/usr/share/openhab2/addons$ sudo python3 sdi_server.py
Listening on localhost:8889

But when I want to start the sdi_token.py I receive the following errors:

[21:58:59] openhabian@openhab:/usr/share/openhab2/addons$ sudo python3 sdi_token.py
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 159, in _new_conn
    (self._dns_host, self.port), self.timeout, **extra_kw)
  File "/usr/lib/python3/dist-packages/urllib3/util/connection.py", line 57, in create_connection
    for res in socket.getaddrinfo(host, port, family, socket.SOCK_STREAM):
  File "/usr/lib/python3.7/socket.py", line 748, in getaddrinfo
    for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -5] No address associated with hostname

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 600, in urlopen
    chunked=chunked)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 343, in _make_request
    self._validate_conn(conn)
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 841, in _validate_conn
    conn.connect()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 301, in connect
    conn = self._new_conn()
  File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 168, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
urllib3.exceptions.NewConnectionError: <urllib3.connection.VerifiedHTTPSConnection object at 0xb5f9fa90>: Failed to establish a new connection: [Errno -5] No address associated with hostname

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='samsungdi', port=8888): Max retries exceeded with url: /devicetoken/request (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb5f9fa90>: Failed to establish a new connection: [Errno -5] No address associated with hostname'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "sdi_token.py", line 4, in <module>
    resp = s.post("https://SamsungDI:8888/devicetoken/request", data={"DeviceToken":"xxxxxxxxxxx"}, headers=headers, stream=True, verify=False, cert='/etc/openhab2/services/cert.pem')
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 581, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "/usr/lib/python3/dist-packages/requests/adapters.py", line 516, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='samsungdi', port=8888): Max retries exceeded with url: /devicetoken/request (Caused by NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0xb5f9fa90>: Failed to establish a new connection: [Errno -5] No address associated with hostname'))

Any ideas how to fix this?

Thank you!

Br,
Mario

Meanwhile I port scanned the Samsung AC unit with the following result:

Bildschirmfoto 2021-04-04 um 22.15.42

With command openssl I am also able connect through this port:

[22:02:39] openhabian@openhab:/usr/share/openhab2/addons$ openssl s_client -connect 192.168.1.150:8443 -cert cert.pem
CONNECTED(00000003)
Can't use SSL_get_servername
depth=1 CN = Samsung Electronics OCF HA Device SubCA v1, OU = OCF HA Device SubCA, O = Samsung Electronics, C = KR
verify error:num=20:unable to get local issuer certificate
verify return:1
depth=0 CN = OCF Device: Appliance PUF (7837eaf5-8781-4d05-83a3-b91d0e1ff4ae), OU = OCF HA Device, O = Samsung Electronics, C = KR
verify return:1
---
Certificate chain
 0 s:CN = OCF Device: Appliance PUF (7837eaf5-8781-4d05-83a3-b91d0e1ff4ae), OU = OCF HA Device, O = Samsung Electronics, C = KR
   i:CN = Samsung Electronics OCF HA Device SubCA v1, OU = OCF HA Device SubCA, O = Samsung Electronics, C = KR
 1 s:CN = Samsung Electronics OCF HA Device SubCA v1, OU = OCF HA Device SubCA, O = Samsung Electronics, C = KR
   i:CN = Samsung Electronics OCF Root CA, OU = OCF Root CA, O = Samsung Electronics, C = KR
---
Server certificate
-----BEGIN CERTIFICATE-----
MIICmjCCAj6gAwIBAgIUSEEwMVAyMDAxMDgwNDAwNjQzNDUwDAYIKoZIzj0EAwIF
ADB+MTMwMQYDVQQDEypTYW1zdW5nIEVsZWN0cm9uaWNzIE9DRiBIQSBEZXZpY2Ug
U3ViQ0EgdjExHDAaBgNVBAsTE09DRiBIQSBEZXZpY2UgU3ViQ0ExHDAaBgNVBAoT
E1NhbXN1bmcgRWxlY3Ryb25pY3MxCzAJBgNVBAYTAktSMCAXDTIwMDEwNzIyMzUx
MFoYDzIwNjkxMjMxMTQ1OTU5WjCBjjFJMEcGA1UEAxNAT0NGIERldmljZTogQXBw
bGlhbmNlIFBVRiAoNzgzN2VhZjUtODc4MS00ZDA1LTgzYTMtYjkxZDBlMWZmNGFl
KTEWMBQGA1UECxMNT0NGIEhBIERldmljZTEcMBoGA1UEChMTU2Ftc3VuZyBFbGVj
dHJvbmljczELMAkGA1UEBhMCS1IwWTATBgcqhkjOPQIBBggqhkjOPQMBBwNCAAT6
YwcQU9EJ9Wlb2mZUMEJt+lrZhujDyndMSjvRtuBcTksv22n8aBse4E+aKgkEX+q9
MNykwXOopEvrbZfKiX7Go4GEMIGBMDcGCCsGAQUFBwEBBCswKTAnBggrBgEFBQcw
....................

Any suggestions how to continue ?

Update from 05.04.2021:

So the port is also changing of my 2021 Samsung Windfree unit. Today it´s running on port 1857.

So any chance to use this binding even with changing ports or is it waste of time?

Otherwise I try to use the Rest API for Smartthings to work…

Thanks!

Hi @jag!
I’ve got Samsung Windfree ACs installed yesterday as well, so I am now highly interested in seeing official support in openHAB3 for that. :slight_smile:
Would it make sense that your create a PR against openhab-addons for your binding? We could then collaborate on that PR and I could help getting the token retrieval as part of the binding as well as this currently seems to be a step that many people struggle with. Wdyt?

2 Likes

In moments like these, I wish I had the coding expertise to help you guys develop the official binding. Unfortunately, I don’t :frowning:
But for what it’s worth, I can offer my help with any beta testing needed :pray:

1 Like

Same here guys, happy to test any beta version on my test OH VM. Got a windfree AC readily available.

Hi @Kai
It would be a honor to have my binding as an official binding with OH.
I strongly agree about the token part. It takes som technical knowledge that not everybody has. I really ned some help with the PR.

2 Likes

@jag Small question,
Could it be that the process to getting the token fails, because we have our Windfree AC’s also connected to the Samsung SmartThings app?

I just realized that when I configured the OpenHAB Broadlink binding, we had to make sure not to connect our Broadlink RM devices to the phone app.

Hi @jag,

I have created an initial PR against the openHAB repo at Initial contribution of SamsungAC binding by kaikreuzer · Pull Request #10938 · openhab/openhab-addons · GitHub.
I did some clean-up of the code base and adjusted it to the required format. I also took the liberty to rename it to “samsungac” as this is what we had for openHAB 1.x (although those were older models, I know) - but digital inverters are also in refridgerators and tumble tryers from Samsung and I doubt that we’ll support those device types in the binding as well.

The PR isn’t yet working - still want to find a solution for the token retrieval and need to refactor the power consumption (as I’ve removed the dependency to sqlite, I don’t see the need for a database for this as it makes the binding much more complex - I’d hope that an in-memory cache should suffice).

Feel free (anyone) to do PRs against my PR with improvements, fixes, etc. I’m happy for any collaboration to get this binding in a mergeable state!

2 Likes