amosyuen / ha-eight-sleep-climate

Climate entity for controlling eight sleep bed
MIT License
10 stars 3 forks source link

Strange behaviour when device temperature is in Celsius #7

Open jaco opened 2 years ago

jaco commented 2 years ago

Thank you for your great work! Finally, I can control pod from the apple watch (via the homekit controller). By the way, buy me a coffee link seems broken :)

It seems like the device temperature setting is a backend, not a client thing. I have my device in Celsius and no matter what unit is active in HA, I get numbers like -28 F :)

When I changed device unit in the EightSleep app, then it works great both in C and F in HA.

amosyuen commented 2 years ago

Thanks for your report. I fixed the coffee link.

I tried setting my eight sleep to celcius and it looks like the reading is correct, but it is unable to set the value. The error comes from the official eight sleep integration.

Logs

2022-08-31 23:01:24.210 ERROR (MainThread) [pyeight.eight] Error puting Eight data. 500, message='Internal Server Error', url=URL('https://client-api.8slp.net/v1/devices/<device_id>')
2022-08-31 23:01:24.213 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/pyeight/eight.py", line 246, in api_request
    resp = await self._api_session.request(
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client.py", line 640, in _request
    resp.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1004, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 500, message='Internal Server Error', url=URL('https://client-api.8slp.net/v1/devices/<device_id>')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 447, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 680, in _async_call_service_step
    await service_task
  File "/usr/src/homeassistant/homeassistant/core.py", line 1713, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1750, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 751, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 676, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 930, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 713, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/eight_sleep/__init__.py", line 219, in async_heat_set
    await self._user_obj.set_heating_level(target, duration)
  File "/usr/local/lib/python3.10/site-packages/pyeight/user.py", line 648, in set_heating_level
    set_heat = await self.device.api_request("put", url, data=data_duration)
  File "/usr/local/lib/python3.10/site-packages/pyeight/eight.py", line 259, in api_request
    raise RequestError from err
pyeight.exceptions.RequestError
amosyuen commented 2 years ago

Hmm, seems like maybe it was a temporary server thing, the next day it was working fine with my eight sleep in Celsius. Could you confirm what number was -28? Was that the temperature setting of the climate in HA?

jaco commented 2 years ago

I really can’t figure that out :) I have switched my pod to celsius and “show real temperature”.

When I set my desired 23° C in HA, I get 31° C in eight sleep app. To achieve 23 ° C in the app I have to set -30° C in HA.

It looks like some relative scale and… maybe it’s correct? Service from base integration expects value from -100..100.

Should I expect real temperature or -100..100 scale? :)

amosyuen commented 2 years ago

Ah ok, I think the misunderstanding here is on the HA units. The HA thermostat is always -100 to 100. You should really think of the HA thermostat representing percent. This is b/c eight sleep API doesn't return realtime units, it's always -100 to 100.

jaco commented 2 years ago

Great to know :) I hacked some linear conversion based on few points, it's pretty accurate (0-1° C degree difference on the app). The code is far from perfect (ie. validation now is in bad place) but it works…

I will try to prepare proper pull request later.

https://github.com/jaco/ha-eight-sleep-climate

ha app
Sanher commented 11 hours ago

Good day @amosyuen, thank you for your work. Regarding this strange behaviour, it is possible that for Celsius degrees (even i didnt try with Farenheit) the temperature is got from the bed_state parameter from Eight api, instead from bed_temperature:

Here is a screenshot from IOS Home App: image

I set the temperature to 1ºC which is the current temperature from the bed (which is not possible). In Home assistant I see that this value is got from bed_state and not from bed_temperature: image

I tried to contribute and correct it but im afraid im not familiar with eight API and not really a python lover 😅

I hope it helps and thank you!