Python Plugin: LG Smart AC (SmartThinQ) Topic is solved

Python and python framework

Moderator: leecollings

jsmit
Posts: 28
Joined: Wednesday 02 November 2016 19:02
Target OS: Raspberry Pi / ODroid
Domoticz version: v2020.2
Location: Nearby Hoorn NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by jsmit »

@Pietje1951,

I had the same message about command not found.
I add the next rule at line 1 of LGACServerNew.py:
#!/usr/bin/python3

Jacco
jsmit
Posts: 28
Joined: Wednesday 02 November 2016 19:02
Target OS: Raspberry Pi / ODroid
Domoticz version: v2020.2
Location: Nearby Hoorn NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by jsmit »

heggink wrote: Saturday 21 November 2020 11:03 OK, more progress which is good. By the looks of it, after issuing the "pip install -e ." command, everything got installed properly, correct? (no error messages)..

what changes did you make when you did the "nano wideq.py" command? nano is an editor that lets you edit wideq.py. In wideq.py, you need to make some changes that will allow the plugin to access your airconditioner. In my case I needed to make the following changes:
COUNTRY = 'NL'
LANGUAGE = 'en-EN'
OAUTH_SECRET_KEY = 'you need to fill in your specific key'

The key above (login authentication for the LG smartthinq service) and the device number (identifying your Airco) you can get by following the instructions on the plugin page:

python3 example.py
open browser, log in , ...

easiest if you can do that from your raspberry pi. Mine is headless (no keyboartd/monitor) so I did that from another computer which works fine as well.

Let me know how you progress. It looks like you are close to getting your auth token. Once you have that, the rest should be 'easy'.

H
Heggink,

What do you mean by OAUTH_SECRET_KEY?

https://kr.m.lgaccount.com/login/iabClo ... api.com%2F

Is that state or code, or am i missing something?
Try both and not working.

Jacco
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by heggink »

My bad: I thought you needed to fill in your own key after OATH_SECRET_KEY but I noticed that you can just leave it as is:
OAUTH_SECRET_KEY = 'c053c2a6ddeb7ad97cb0eed0dcb31cf8'
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by heggink »

Correct. Either call LGACServerNew with python3 (python3 LGACServerNew.py) or add #!/ust/bin/python3 as the first line
I have made that change in my updated version of the plugin now.
jsmit wrote: Saturday 21 November 2020 21:37 @Pietje1951,

I had the same message about command not found.
I add the next rule at line 1 of LGACServerNew.py:
#!/usr/bin/python3

Jacco
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
jsmit
Posts: 28
Joined: Wednesday 02 November 2016 19:02
Target OS: Raspberry Pi / ODroid
Domoticz version: v2020.2
Location: Nearby Hoorn NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by jsmit »

Heggink,

Thanks for your update.

I have still an error when i run the LGAServerNew

pi@raspberrypi:~/LGAC_SmartT $ ./LGACServerNew.py
server: Starting server on 127.0.0.1 22233
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
File "./LGACServerNew.py", line 98, in ac_commands_handler
client = wideq.Client.from_token(token)
File "/home/pi/LGAC_SmartT/wideq.py", line 556, in from_token
client.refresh()
File "/home/pi/LGAC_SmartT/wideq.py", line 543, in refresh
self._session, self._devices = self.auth.start_session()
File "/home/pi/LGAC_SmartT/wideq.py", line 258, in start_session
return Session(self, session_id), as_list(session_info['item'])
KeyError: 'item'
2020-11-23T10:01:07Z <Greenlet at 0x75397660: ac_commands_handler('0ffa2f76-fd2b-16c2-a237-402f86876675', 'e71f260781e4b68e1f00098689ecd0fc52a309d5f3308d88c, <Queue at 0x753737d8>)> failed with KeyError

when i start another sesion
pi@raspberrypi:~/LGAC_SmartT $ sudo python3 testServer.py
test: trying connect to 127.0.0.1:22233
test: sent request to server [status]
test: reading response...
testServer.py:31: DeprecationWarning: encoding is deprecated, Use raw=False instead.
unpacker = Unpacker(encoding='utf-8')

the answer is
server: connected ('127.0.0.1', 33848)
server: got socket msg: [b'status']


Jacco
Last edited by jsmit on Monday 23 November 2020 11:44, edited 1 time in total.
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by heggink »

Hi Jacco,

As mentioned before, I did not create the plugin myself. Since olinek2 doesn't seem to maintain it anymore, I just decided to try to fix some things that were failing on my end. Also, I harldy qualify as a python programmer (I am an old unix/C programmer who ended up in sales ;-).

With those disclaimers in mind :D :D , what I would suggest is that you put a few print statements in the code to see what it does. From the below, it's clear that something is going wrong in start_session in wideq.py (before line258). I had a quick look at that piece of code:

Code: Select all

    def start_session(self):
        """Start an API session for the logged-in user. Return the
        Session object and a list of the user's devices.
        """

        session_info = login(self.gateway.api_root, self.access_token)
        session_id = session_info['jsessionId']
        return Session(self, session_id), as_list(session_info['item'])
It looks like the issue is with the return status where 'item' is not in the login response. The plugin does very little in either debug statements or error handling and assumes everything works fine. what I would suggest is that you put in a couple of print statments just after the login statement to see what you get back from that login. I am not sure but you may just be able to print the entire response if it's a strong with print(session_info)
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
jsmit
Posts: 28
Joined: Wednesday 02 November 2016 19:02
Target OS: Raspberry Pi / ODroid
Domoticz version: v2020.2
Location: Nearby Hoorn NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by jsmit »

Heggink,

I have made a print of the access token.
This one in not the same one as mine in the wideq_state.json
It changes every time i start the LGACServerNew

You are right, no item:
{'returnCd': '0000', 'returnMsg': 'OK', 'jsessionId': '566F766DB24DC406E1039F750 7D6323C.nodes_sadap_02', 'userId': 'NL2010206479725', 'clauseReAgree': 'N', 'acc ount': '[email protected]', 'accountType': 'LGE', 'mbrNo': 'NL2010206479725', 'c ountryCode': 'NL', 'noticeSeq': '', 'noticeTitle': '', 'notice': '', 'noticeLink Title': '', 'noticeLink': '', 'empOauthErrorYn': 'N'}
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by heggink »

OK, then start putting in more print statements where it starts connecting both in wideq.py and in LGACServernew.py.
Are you starting LGACServernew.py in the same directory where your wideq_state.json is located (stating the obvious, I know)?
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
jsmit
Posts: 28
Joined: Wednesday 02 November 2016 19:02
Target OS: Raspberry Pi / ODroid
Domoticz version: v2020.2
Location: Nearby Hoorn NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by jsmit »

No, i have the folowing maps:
/home/pi/LGAC_SmartT
and
/home/pi/LGAC_SmartT/wideq

Do they need to be installed in the same directory?
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by heggink »

I don;t think that is needed BUT you do need to run LGACServernew from the same directory where wideq_state.json resides (when you ran python3 example.py).

When you are starting to get the server bit to work, you have to remember that the plugin consists of 2 parts: a server component that connects with the LG smartthinq webservice, adn a domoticz plugin piece that does the interfacing between domoticz and the server component. The server component needs wideq_state.json to function. The domoticz plugin only needs to know how to connect to the server (you need to enter the IP address and port since the server can run on a different platform).
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
jsmit
Posts: 28
Joined: Wednesday 02 November 2016 19:02
Target OS: Raspberry Pi / ODroid
Domoticz version: v2020.2
Location: Nearby Hoorn NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by jsmit »

I paste the wideq directory into the LGAC_SmartT directory.

Now i get:
pi@raspberrypi:~/LGAC_SmartT $ ./LGACServerNew.py
server: Starting server on 127.0.0.1 22233
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
File "./LGACServerNew.py", line 98, in ac_commands_handler
client = wideq.Client.from_token(token)
File "/home/pi/LGAC_SmartT/wideq/client.py", line 215, in from_token
client._auth = core.Auth(client.gateway, None, refresh_token)
TypeError: __init__() missing 2 required positional arguments: 'refresh_token' and 'user_number'
2020-11-23T13:30:32Z <Greenlet at 0x75358ae0: ac_commands_handler('0ffa2f76-fd2b-16c2-a237-402f86876675', 'ea5f135ff64019cf47e0a73100f44cecb53cd39c1624986e4, <Queue at 0x75313260>)> failed with TypeError

So it seems to be really makes a difference.
I will try this evening from the scratch.
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by heggink »

Here is what I don;t understand in your case: when doing a git pull with my modified plugin, it already has wideq.py in the base directory. There is NO wideq directory. I believe olinek2 modified wideq.py for use with his plugin. Did you install a different wideq library? If so then that will likely fail.
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
jsmit
Posts: 28
Joined: Wednesday 02 November 2016 19:02
Target OS: Raspberry Pi / ODroid
Domoticz version: v2020.2
Location: Nearby Hoorn NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by jsmit »

Yes, i have a different wideq installed because with your wideq i did not see my AC's.
This has probebly something to do with api2 (I am a new user of LG)
When i use the wideq of gladhorn (https://github.com/gladhorn/wideq) I get a list of my AC's
I thought that is only for example.py
But now I think that I need to change the wideq.py
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by heggink »

Ah, OK. I recall having looked at that in the past when trying to fix some of the underlying issues. it seemed like olinek2's wideq.py was a mixture of multiple files. I ended up fixing them in the plugin's wideq version as that was a lot less work and still works for me.

Why did you use gladhorn instead of sampsyo (I think gladhorn is a fork of sampsyo but I may be wrong)?

What I can say is that it will take a bit of work for this to work with an updated/official wideq version. It would be a lot better if that would be done but I didn't/don't have the time :-(.
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by heggink »

NVM, API2 is only in gladhorn.
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
jsmit
Posts: 28
Joined: Wednesday 02 November 2016 19:02
Target OS: Raspberry Pi / ODroid
Domoticz version: v2020.2
Location: Nearby Hoorn NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by jsmit »

Thanks for the help.
I have tried to understand the wideq plugin, but it is above my program skills.
I hope someone with more knowledge can adapt the plugin on api2.
Until then unfortunately without air conditioning in domoticz....

Jacco
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by heggink »

The best way forward would be to revert back to the original implementation of wideq instead of the changed version. That way, any future changes in wideq won't require changes in this plugin and 'just' a git pull.

That said, this is quite a bit of work and not something I have time for in the near future. Also, it will require a new, stable version of wideq that supports V2 auth as well as V1 as maintaining 2 versions of the plugin is a hassle.

Let's see what happens in terms of wideq over the next couple of months. Maybe by the time we need airco control, we can get to something stable.
Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Devious
Posts: 20
Joined: Sunday 30 December 2018 19:02
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: Oss NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by Devious »

jsmit wrote: Monday 23 November 2020 15:36 This has probebly something to do with api2 (I am a new user of LG)
This will probebly be my issue as well.
AC units are installed this summer.

we are stuck with domoticz notifications and LG app for now :roll:
User avatar
heggink
Posts: 972
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by heggink »

Just checked the developments on wideq v2 (and others). Unfortunately little progress and no workable v2 just yet.

Sent from my SM-G980F using Tapatalk

Docker in Truenas scale, close to latest beta
DASHTICZ 🙃
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
pietje1951
Posts: 11
Joined: Sunday 08 November 2020 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: LG Smart AC (SmartThinQ)

Post by pietje1951 »

Thank you,

It's a pity, but hope for the best.....
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest