Thanks for your help! Any other suggestions? It sounds like a class in PHP which I can implement but no idea how that works in Python. When I inherit it I can implement some functions and do the http requests there to get it working? What about a loop so the sensors will be updated every minute?
If you override the method should_poll and return true the default polling interval is 60 seconds. So every 60 seconds the method def update(self): will be called for your platform. Inside that method you would need to make your network call, (call to your library which makes a call to the API)
Thanks again! I’m going to experiment with it. Your last line, is a library needed? Because there isn’t one I think. It’s possible to do the http request in that update method directly right? Let’s see how it goes, to be continued!
It is recommend that a library be used. Not sure it will get approved without using/making one to use. We don’t make to limit the use of the code to HA and should make/use a generic library that other people can use for other things.
The library seems really old, last update was 3 years back. Probably would be best to start a new one, but you could use that one as a starting place for how to create yours.
The way most of the components work in HA is during setup they call out to whatever library it is using passing it username and password or whatever, and then it stores all of the device information inside a library object. Then home assistant would ask that library for the store device information in the libraries object (in memory) the only time an API call (I/O operation) should be run is during the update method. Since this happens during the creation of the platform once it is added to HA it will have up-to-date info (you wont have to wait 60 for the first update)
Anything showing as Unknown would do so because you are returning None from, for example current_temperature. I assume that means self.data is None.
To force an update immediately after you made a change so you don’t have to wait 60 seconds for the next poll you can call self.schedule_update_ha_state(True) which should force a call to update.
Is this room_temp_set_1_lsb unique to your setup? Like a name? If so, can it not be pulled from some generic endpoint? If not, it would probably be best to make that a config entry option so other users can pass it in via their config.
So I have made several library for use with HA. Here is a simple library I made https://github.com/w1ll1am23/pytrackr that is pretty basic. That library is then push to pypi.org so Home Assistant can pull it automatically.
Creating a library is a little bit too much for me with my limited Python knowledge. So I keep it this way for now, drawback of that is that it probably won’t get accepted as PR into the core. I’ll put it on Github so maybe someone else with more knowledge of Python and Home Assistant can do that. See: https://github.com/royduin/home-assistant-incomfort
I’ve checked the features but the InComfort thermostat is very basic. Just a current and target temperature, that’s it. In that json is a lot more information but that’s not very relevant to display in Home Assistant I think.
I’ve fixed the “Unknown”, just had to set a state. But problem 3 is still there. When I (re)start Home Assistant I’ve to wait for 1 minute to get data. Is it possible to trigger the update when starting so I don’t have to wait 1 minute? Putting self.schedule_update_ha_state(True) in the init method doesn’t work.
And no room_temp_set_1_lsb is not unique, it’s the same for every InComfort gateway.
Hi,
i have the same issue in a modbus climate controls. I fixed the original code due it stopped to works and it returns uncorrect value. but I have the unknown on the setpoint description
Nothing in the logs. I have a newer version of the gateway. In the documentation it is mentioning automatic restarts to ensure the connection doesn’t drop maybe this is the problem… Which version of the gateway do you have?
2019-03-10 22:21:35 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.InComfort.climate. Make sure all dependencies are installed Traceback (most recent call last): File “/usr/local/lib/python3.7/site-packages/homeassistant/loader.py”, line 166, in _load_file module = importlib.import_module(path) File “/usr/local/lib/python3.7/importlib/init.py”, line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File “<frozen importlib._bootstrap>”, line 1006, in _gcd_import File “<frozen importlib._bootstrap>”, line 983, in _find_and_load File “<frozen importlib._bootstrap>”, line 967, in _find_and_load_unlocked File “<frozen importlib._bootstrap>”, line 677, in _load_unlocked File “<frozen importlib._bootstrap_external>”, line 728, in exec_module File “<frozen importlib._bootstrap>”, line 219, in _call_with_frames_removed File “/config/custom_components/InComfort/climate.py”, line 8, in <module> from homeassistant.components.climate import ( ImportError: cannot import name ‘STATE_HEAT’ from ‘homeassistant.components.climate’ (/usr/local/lib/python3.7/site-packages/homeassistant/components/climate/init.py) 2019-03-10 22:21:35 ERROR (MainThread) [homeassistant.loader] Unable to find platform InComfort.
from homeassistant.components.climate import ( STATE_HEAT, ClimateDevice, SUPPORT_TARGET_TEMPERATURE, PLATFORM_SCHEMA)
to
from homeassistant.components.climate import (ClimateDevice, PLATFORM_SCHEMA) from homeassistant.components.climate.const import (STATE_HEAT, SUPPORT_TARGET_TEMPERATURE)