sampsyo / hass-smartthinq

Home Assistant component for LG SmartThinQ HVAC devices
MIT License
285 stars 98 forks source link

Integration with HA #1

Open bmwm69 opened 6 years ago

bmwm69 commented 6 years ago

Hello,

how integrate that with HA ?

sampsyo commented 6 years ago

Please see: https://home-assistant.io/developers/development_101/

This repository needs to be cloned into custom_components in your Home Assisrsnt directory. It also needs this Python dependency installed with pip: https://github.com/sampsyo/wideq

wkd8176 commented 6 years ago

Hi I installed wideq with pip, and cloned smartthinq.py in custom_components.

How to register my AC in HA?

sampsyo commented 6 years ago

Good question! I added some instructions to the README just now. Let me know if that's not clear.

bmwm69 commented 6 years ago

Nice new readme file ! :) For hass.io system some alternative to install wideq ?

sampsyo commented 6 years ago

Sorry, I’m not familiar with hass.io. Maybe there’s some way to specify WideQ as a dependency?

wkd8176 commented 6 years ago

Thank you the updated README. I logged in the lgaccount, site said 'Invalid request parameter'

What can i do more? please help

sampsyo commented 6 years ago

Huh! I don’t know what’s wrong, but I do know that some folks on the Ha forum have found that they need to adjust the initial login endpoint to match their country. Taking a look there might reveal some clues.

wkd8176 commented 6 years ago

Oh, it was problem of internet browsers. I retried this in iExplorer, it worked.

and I also changed wideq.py little bit.(Because I live in South Korea)

There is another problem. I got a refresh token, and paste it in the configuration.yaml and i got an error like this

2018-04-03 00:34:21 WARNING (MainThread) [homeassistant.components.climate] Setup of platform smartthinq is taking over 10 seconds. 2018-04-03 00:34:21 ERROR (MainThread) [homeassistant.components.climate] Error while setting up platform smartthinq Traceback (most recent call last): File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 84, in async_setup SLOW_SETUP_MAX_WAIT, loop=hass.loop) File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for return fut.result() File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result raise self._exception File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run result = self.fn(*self.args, **self.kwargs) File "/config/custom_components/climate/smartthinq.py", line 35, in setup_platform add_devices(LGDevice(client, device) for device in client.devices) File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 121, in _schedule_add_entities self._async_schedule_add_entities, list(new_entities), File "/config/custom_components/climate/smartthinq.py", line 35, in add_devices(LGDevice(client, device) for device in client.devices) File "/config/custom_components/climate/smartthinq.py", line 56, in init self.update() File "/config/custom_components/climate/smartthinq.py", line 180, in update state = self._ac.poll() File "/config/wideq.py", line 693, in poll res = self.mon.poll() File "/config/wideq.py", line 354, in poll

sampsyo commented 6 years ago

That traceback is cut off. Can you try pasting again, and this time use Markdown code fences so it's readable?

wkd8176 commented 6 years ago

Sorry. I paste it again I'm using HA on docker, synology nas.

Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 84, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/climate/smartthinq.py", line 35, in setup_platform
    add_devices(LGDevice(client, device) for device in client.devices)
  File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 121, in _schedule_add_entities
    self._async_schedule_add_entities, list(new_entities),
  File "/config/custom_components/climate/smartthinq.py", line 35, in <genexpr>
    add_devices(LGDevice(client, device) for device in client.devices)
  File "/config/custom_components/climate/smartthinq.py", line 56, in __init__
    self.update()
  File "/config/custom_components/climate/smartthinq.py", line 180, in update
    state = self._ac.poll()
  File "/root/wideq/wideq.py", line 693, in poll
    res = self.mon.poll()
  File "/root/wideq/wideq.py", line 354, in poll
    return self.session.monitor_poll(self.device_id, self.work_id)
  File "/root/wideq/wideq.py", line 309, in monitor_poll
    base64.b64decode(res['returnData']).decode('utf8')
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 6: invalid start byte
sampsyo commented 6 years ago

Interesting! I can see what’s going wrong (non-UTF-8 data for the JSON response) but I’m not sure what to fix it (i.e., what the right encoding is). Any chance you’d be willing to give me a credential (i.e., an access token) privately so I can investigate further? I promise not to change any settings... :smiley:

wkd8176 commented 6 years ago

I sent a mail inside of ‘wideq_state.json’ Please check your mail

sampsyo commented 6 years ago

Thanks!

The problem was that you have other, non-AC devices on your account. I only have AC devices from LG, so I just used all the associated devices and assumed they were AC devices. It turns out that other things (e.g., refrigerators) report their status in a very different way.

Anyway, I've now added some code to WideQ to detect the types of devices. This plugin now uses that to only try to use AC devices. If you update both the WideQ library and this plugin, you should be in business.

bmwm69 commented 6 years ago

Hello,

Steps by step to install in Hass.io

Install Phyton $apk add --no-cache python3 $ git clone https://github.com/sampsyo/wideq.git $ cd wideq $ pip3 install -e . $ cd /config $ mkdir custom_components $ cd custom_components $ git clone https://github.com/sampsyo/hass-smartthinq.git climate $cd /wideq

In my case I modify wideq.py COUNTRY = 'PT' LANGUAGE = 'pt-PT'

The file wideq_state.json apear with refres_token

After config configuration.yaml

climate:

I received error :|

The following components and platforms could not be set up: climate.smartthinq

sampsyo commented 6 years ago

Hmm, is there any more detail in the log? That message could mean anything…

bmwm69 commented 6 years ago

2018-04-03 21:35:30 ERROR (SyncWorker_2) [homeassistant.util.package] Unable to install package wideq: Could not find a version that satisfies the requirement wideq (from versions: ) No matching distribution found for wideq 2018-04-03 21:35:30 ERROR (MainThread) [homeassistant.requirements] Not initializing climate.smartthinq because could not install requirement wideq 2018-04-03 21:35:30 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform climate.smartthinq: Could not install all requirements.

bmwm69 commented 6 years ago

Pip3 Install Log

core-ssh:/wideq# pip3 install -e . Obtaining file:///wideq Collecting requests (from wideq==0.0.0) Downloading requests-2.18.4-py2.py3-none-any.whl (88kB) 100% |████████████████████████████████| 92kB 728kB/s Collecting certifi>=2017.4.17 (from requests->wideq==0.0.0) Downloading certifi-2018.1.18-py2.py3-none-any.whl (151kB) 100% |████████████████████████████████| 153kB 585kB/s Collecting chardet<3.1.0,>=3.0.2 (from requests->wideq==0.0.0) Downloading chardet-3.0.4-py2.py3-none-any.whl (133kB) 100% |████████████████████████████████| 143kB 650kB/s Collecting urllib3<1.23,>=1.21.1 (from requests->wideq==0.0.0) Downloading urllib3-1.22-py2.py3-none-any.whl (132kB) 100% |████████████████████████████████| 133kB 636kB/s Collecting idna<2.7,>=2.5 (from requests->wideq==0.0.0) Downloading idna-2.6-py2.py3-none-any.whl (56kB) 100% |████████████████████████████████| 61kB 634kB/s Installing collected packages: certifi, chardet, urllib3, idna, requests, wideq Running setup.py develop for wideq Successfully installed certifi-2018.1.18 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22 wideq

sampsyo commented 6 years ago

Strange! I'm not sure what to recommend. It looks like wideq installed correctly, but the Python instance that's running Home Assistant can't find it. I don't know the inner workings of the hass.io image setup, but maybe asking about the issue generically (i.e., dependency installed with pip install -e can't be found when setting up a component) in the HA forums.

wkd8176 commented 6 years ago

Thanks the update. I cleared that problem, and has another problem.... :( I have a climate device, nest, is it related this problem?

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/src/app/homeassistant/helpers/entity_platform.py", line 253, in _async_add_entity
    'Invalid entity id: {}'.format(entity.entity_id))
homeassistant.exceptions.HomeAssistantError: Invalid entity id: climate.
sampsyo commented 6 years ago

Sorry; I don't recognize this error. Looks like it's inside the HA code. As in the previous case, it might be best to ask on the HA forums or something.

For posterity, you might also consider recording the solution to your previous problem here.

wkd8176 commented 6 years ago

Oh, i solved the ‘Invalid entity_id’ issue. My AC had korean name so i changed it english in smartthinq app, the error was cleared.

Could you update the readme.md, include command set?

sampsyo commented 6 years ago

Actually, in the spirit of open-source collaboration, can you please do it? Please open a PR with the changes you want to see and we’ll go from there.

bmwm69 commented 6 years ago

After install Raspbian all now works fine ! But with application I increase 1ºc by 1ºc, with HA integration temperature increases with strange values 20.8º , 21.3º , 21.8º ..

sampsyo commented 6 years ago

Hmm, yes, I've currently hard-coded the plugin to use Fahrenheit, so you're probably seeing rounding errors. This is the relevant line: https://github.com/sampsyo/hass-smartthinq/blob/c5541db7957d5030e8b525e87113d71564bcdd08/smartthinq.py#L43

If you change that to False, you should get Celsius. I should figure out how to make that a configurable option…

Pharizna commented 6 years ago

@bmwm69 (@sampsyo)

I have the same problem as you ... but I'm using Raspbian and not Hass.io

"2018-04-03 21:35:30 ERROR (SyncWorker_2) [homeassistant.util.package] Unable to install package wideq: Could not find a version that satisfies the requirement wideq (from versions: ) No matching distribution found for wideq 2018-04-03 21:35:30 ERROR (MainThread) [homeassistant.requirements] Not initializing climate.smartthinq because could not install requirement wideq 2018-04-03 21:35:30 ERROR (MainThread) [homeassistant.setup] Unable to prepare setup for platform climate.smartthinq: Could not install all requirements."

How did you solve your problem? Installing and using Raspbian instead Hass.io?

Have you installed wideq in the root folder?

Pharizna commented 6 years ago

Help, please :)

sampsyo commented 6 years ago

Hi, @Pharizna—posting updates like this, or the one in https://github.com/sampsyo/hass-smartthinq/issues/6#issuecomment-402801885, is not helpful. We (the community) have already weighed in and helped however we could—we didn't just forget about the thread. Please try asking elsewhere and updating here if you learn anything useful.

Pharizna commented 6 years ago

Sorry :(

Pharizna commented 6 years ago

Solved :)

$ sudo su -s /bin/bash homeassistant $ source /srv/homeassistant/bin/activate

$ git clone https://github.com/sampsyo/wideq.git $ cd wideq $ pip3 install -e .

((wideq folder owner has to be homeassistant, of course))

image

ctih commented 5 years ago

https://github.com/sampsyo/hass-smartthinq/issues/1#issuecomment-403733310 Is this done using Hass.io?

SylvainGa commented 4 years ago

Hi, first post of 2020 :-)

On hass.io V0.105, when I run "pip3 install -e ." from /root/wideq

I get: ERROR: File "setup.py" not found. Directory cannot be installed in editable mode: /root/wideq (A "pyproject.toml" file was found, but editable mode currently requires a setup.py based build.) WARNING: You are using pip version 19.2.3, however version 19.3.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command.

Running pip install --upgrade pip returns -bash: pip: command not found

Man hass.io can be a pain sometimes...

morettty commented 4 years ago

Hello, sorry for the writing I use the translator. I am new and I am trying to integrate two lg air conditioners but I have the following problem: root @ SYNOLOGY: /volume1/hassio/hass.io/homeassistant/custom_components/smartthinq/wideq-master# python3 example.py -l es -c es-ES File “example.py”, line 233 help = f’one of: {"," .join (EXAMPLE_COMMANDS)} ') ^

synology doesn't have python 3.6 native package.