Categories

Keywords

Python IHC soap client

Yet another ihc soap client - this time for python. This is work in progress as I am trying to get this integrated into Home Assistant.

I have not been working much in python before,  but since that is the language for Home Assistant I will give it a try. I am publishing this separately in case someone has other use for it. The Home Assistant part will follow later.

Download and install

ihcsdk is now availble in PyPi so you can install it using;

pip install ihcsdk

Or get it from github here:

https://github.com/dingusdk/PythonIhcSdk

Example

The example folder has a ihctest.py example. Run it using

python ihctest.py http://myihcip ihcusername ihcpassword ihcresourceid

The ihcresourceid should be a boolean resource. The example will connec and authenticate with the ihc controller, then read the resource, toggle it to the opposite and then setup a notification on the same resource. Try to change the resource value on the controller and you will see the example output the change.

Implementation

This is more or less the functionallity from my ihc soap client library for esp8266 ported to python. It has authentication, get and set runtime values and notification.

For now I will not document the functionality further until I know if this is something that is going to be more than a experiment.

Comments

The comments below has been imported from the old website. Currently comments are readonly, meaning you can not make new comments. You will be able to do that when it is ready. For now if you want to get in touch, you can send me an email. If you have problems with something that has a github repository, please make a github issue.

Hi, Great work and thank you for making me aware of Home Assistant. I have been trying the python script localy on my PC and it works great. I am though a bit unsure about how to make the correct IHC Soap client setup running HASS.IO on a Rasberry. Is this something you have tried? Best, MortenI have not tried using hass.io, but I have tried on a raspberry pi with raspbian and installing home assistant manually. (in a virtual enviroment - instructions are on the home assistant web site). This was working ok, so you should also be able to do it on hass.io. I am now running it on an odroid board with ubuntu.I have been looking for this for a longtime (IHC integration into Homeassistant). Thx I have a question about the site-packages folder. I dont have it... but i do have python2.6 2.7 3 and 3.5 installed on my RPI3. Should i create it? and if so, in folder python3.5? thank u in advance. JohanHome assistant is running with python 3.5 - so it will be the python3.5 folder. The location of the folder depends on your setup. It should exist with some other libraries already installed. You can get the location location using python3 -m site --user-site And you need to run the above in the same context as you are running home assistant. If you have installed in a virtualenv (from instruction on the home assistant website) - the location will be /srv/homeassistant/lib/python3.5/site-packages Also remember to have the access rights set so the homeassistant user can access the files. Let me know if you can't get it working (and it would also be nice to hear when you get it working:-)Okey, sorry im not so good at linux. But when u say context you meen same user as HASS?, IE. user homeassistant Running the command gives me this: python3 -m site –user-site /usr/lib/python3.5/site.py [--user-base] [--user-site] Without arguments print some useful information With arguments print the value of USER_BASE and/or USER_SITE separated by ':'. Exit codes with --user-base or --user-site: 0 - user site directory is enabled 1 - user site directory is disabled by user 2 - uses site directory is disabled by super user or for security reasons >2 - unknown error So i should create the site-packages folder at "/usr/lib/python3.5/"? Thank you for your help =) JohanYes - by context I mean the same user as your are running home assistant.I think you are missing a "minus" before "user-site" - it should be a double "minus" before "user-site". It may be wordpress that has changed it, but I get the same result as you if I use a single "-". P.S. I will try to get the python ihc lib into PyPi (The python package index) - this will make is easier to install, but I have not done this before so I need to find out how that is done.The python ihcsdk should now be available in PyPi - so you can install it doing: pip install ihcsdk Now I am missing to have it installed automatically from within home assistant, for some unknown reason it is not working.I got it working now - if you download the latest release 1.0.1 of haihc from github, it should be able have home assistant automatically download and install the ihcsdk library from PyPi.Thx for your effort. Found out that command: python3.5 -m site give me: sys.path = [ '/home/pi', '/usr/lib/python35.zip', '/usr/lib/python3.5', '/usr/lib/python3.5/plat-arm-linux-gnueabihf', '/usr/lib/python3.5/lib-dynload', '/usr/local/lib/python3.5/dist-packages', '/usr/lib/python3/dist-packages', ] USER_BASE: '/home/pi/.local' (exists) USER_SITE: '/home/pi/.local/lib/python3.5/site-packages' (doesn't exist) ENABLE_USER_SITE: True After running "pip install ihcsdk" i get the files here: /home/pi/.local/lib/python2.7/site-packages/ihcsdk So it does not install with python3.5 (maybe something i need to change?) Also; Files from haihc i used WinSCP to place in folder: /home/homeassistant/.homeassistant/custom_components Correct? Sorry for all questions; HASS and linux, is still totally out of my comfort zone but im trying to learn. Thank you for your patience!If you download the latest version 1.0.1 of haihc I made yesterday: https://github.com/dingusdk/haihc Then you should not need to install the python ihcsdk manually - it will be installed automatically automatically by HA.Followed instruction on the github and placed custom_components as subfolder to configuration folder. They are all owned by homeassistant. Also inserted these lines into configuration.yaml: ihc: url: 'http://192.168.1.200' username: myuser password: mypwd info: True light: - platform: ihc autosetup: True Now i have this error msgs in my log 2017-10-28 23:46:37 ERROR (MainThread) [homeassistant.setup] Error during setup of component ihc Traceback (most recent call last): File "/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/homeassistant/setup.py", line 194, in _async_setup_component component.setup, hass, processed_config) File "/usr/lib/python3.5/asyncio/futures.py", line 380, in __iter__ yield self # This tells Task to wait for completion. File "/usr/lib/python3.5/asyncio/tasks.py", line 304, in _wakeup future.result() File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result raise self._exception File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run result = self.fn(*self.args, **self.kwargs) File "/home/homeassistant/.homeassistant/custom_components/ihc.py", line 19, in setup if not ihc.Authenticate(): File "/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/ihcsdk/ihccontroller.py", line 20, in Authenticate if not self.client.Authenticate( self._username,self._password): File "/srv/homeassistant/homeassistant_venv/lib/python3.5/site-packages/ihcsdk/ihcclient.py", line 46, in Authenticate xdoc = xml.etree.ElementTree.fromstring( response.text) File "/usr/lib/python3.5/xml/etree/ElementTree.py", line 1344, in XML parser.feed(text) File "", line None xml.etree.ElementTree.ParseError: mismatched tag: line 1, column 224 2017-10-28 23:46:46 WARNING (MainThread) [homeassistant.setup] Setup of light is taking over 10 seconds. 2017-10-28 23:46:46 WARNING (MainThread) [homeassistant.components.light] Setup of platform ihc is taking over 10 seconds. 2017-10-28 23:47:43 ERROR (MainThread) [homeassistant.components.light] Setup of platform ihc is taking longer than 60 seconds. Startup will proceed without waiting any longer. What can be the problem and how do i fix this? Thanks in advance JohanThe problem is the answer from the authenticate to the controller is not a proper xml answer, and the xml parser will fail to recognize it. (I should probably have check for this in the code to give a better error). The cause could be if you have now allowed access in the ihc controller. If you open the IHC administrator program and go to access control, you should have a check mark in "Service view" and "thirdparty products" under "local net". You should also try to reboot your ihc controller - I have experienced a few times that this can solve it.Ouch, will be a problem then, I am running the ELKO version called Living system, and im guessing you use the LK version. I cant find the 3rd party setting in administrator program for ELKO. The administrator program is only accessable through the IP address right?, not standalone software?Yes I use the LK version, it did not have the 3rd party setting at the beginning, so do you have the latest firmware version for you controller? The administrator program is a java application you download from the controller and run from within you browser, but it will launch as a separate java application. (One of the thing a hate about the IHC controller, because it can not run with the latest java version - I have a separate post about this) Also have you tried to reboot your controller - just to see if that will fix it.Also. I did get this to work in openhab earlier. So 3rd party can be used but maybe not download the file from controller... (i had to enter IDs)If your controller has been working with openhab I think you should be able to have it work with with my code too. Do you still have openhab running? When i tried openhab long time ago - one of the reasons I did stopped using it was because after it had been running for a while I could not connect to the controller any more. Even a reboot of the controller would not help if openhab was still running. Openhab was in a state where it keeps connecting and blocking everything else. Try to stop your openhab and reboot your IHC controller.Tried restarting IHC, no luck. Dont know if it is the newest since i find no such information on elko website but it is as follows: HW: 6.2 SW: 2.7.144It looks like the same version number as for the LK controller. I have HW 6.1 (that is an older HW version), and SW 2.7.220. Since you have 6.2. I would assume you could get a newer update 2.8.4. But looking at the Swedish elko website: http://www.elko.se/support/programvara/ it looks like the newest version is 2.7.190 However an not sure it will change anything regarding this problem, I have been connecting with similar code to my controller with at least to previous 2 version of the IHC firmware. If anybody else with the elko controller is reading this and have it working - please replySorry Jens, that cant be the problem. I gave up openhab for homeassistant. Its not running anymore... Is it possible to do another way where u download the project file. I could not run the alternative service program u made either. U know anyone else that run elko version that got ur code working?The problem is downloading the project file from controller right?, What about downloading it manually instead? There is nothing else iv couldve done wrong in my setup?It is not only the download of the project file that fails, it is also the authentication (login with username/password). I can see that from the error log you posted. (If it was only the project file then you can set the autosetup to False - then the project will not be downloaded) If you are into coding/programming - you should start by trying to get the example working (that is easier than having all Home Assistant running) I don't think I can help you further with this without having access to a similar controller. Is somebody else with an Elko controller or LK HW 6.2 version has it working, then a comment here would be nice.I have both an LK HW 6.1 and LK HW 6.2 in my installation and I can connect to them without any issues (unfortunately not at the same time though). I haven't a check in "thirdparty products” but it doesn't seems to be an issue. @Johan: I got mine working from a hass.io image on a Py3 and then followed the instructions on http://www.dingus.dk/home-assistant-ihc-integration/#more-461 . I cannot see any differences connecting to either HW 6.1 or 6.2. Can you connect to your installation with the Alternative Service View (http://www.dingus.dk/updated-ihc-alternative-service-view)?Thanks for the feedback Morten - I was not sure about if the "thirdparty product" access was needed, it was just in case the Elko controller is different than the LK (The soap functions should behave like the LK service view app). I think the Elko and LK controllers are the same since it is the same HW and firmware versions. P.s. I have just updated Alternative Service View to include temperature products (so this can be include in Home Assistant later). Johan: can you try the Alternative Service View and see how far you get (The important step is to get past the authenticate)Thanks for trying guys but no, Alternative Service View doesnt work either. I can see a box popup and dissapear real quick after i write IP/User/PW and hit enter. But i dont get further than that. Can u see anything that your code is handling different than the OpenHAB? http://docs.openhab.org/addons/bindings/ihc1/readme.htmlI will take a look at the openhab code, but I don't think it will help. I assume openhab use some kind of java soap library to communicate with the controller. The python code I have made is very simplified because I more or less just ported the code I have from my arduino ihc soap library.Thank you for that Jens. IHC captain is working also with my IHC controller. But i miss the home assistant integration..Jens! i now have proof that this is an issue with the ELKO version of IHC. I actually installed the newest version of the LK firmware and, suddenly 2 lamps was shown in home assistant. Hope i can get the rest to work =)Ok, it is strange that is not the same, but good to know you can install the LK version. I have also been looking at how openhab is doing the interfaecing to ihc, and it is more or less the same as I do. I did however remove as much as I could from the XML code in my arduino/esp8266 project - to save memory, but I will add this to the python code again just in case it makes a difference. I will probably make a new release later this weekend.Exited about your new version.:) LK programs doesnt seem to work 100% for me. But maybe that is just finding right java version... Also, your alternative service program works for me now. But i only get 2 outputs to show up in HA. Adding them manually doesnt work either with the ID...Never mind what i said about ID, it works perfectly now. And your Alternative service program is awsome!. Good job!Please let me know if anyone get this to work with hass.io. I'm new to Linux and Python so needs a bit of advise ;-)After upgrading my Pi to a Pi 3 i got it working on Hassio! :-) It works very nice! It might have been too much for the old Pi to handle. I have two IHC controllers in my house. Is is possible to register both in configuration.yaml? And how without overriding?Nice that you got it working. It is not possible to have more than one IHC controller as it is now. You will need to make some changes to the code to handle more than one controller.Support for more controllers would be awesome! Do you plan to support IHC sensors like temperature too (I have my floor heating via IHC)?I will look into the temperature sensor, that should not be so difficult. I only have one controller in my setup, so that may be a bit more difficult for me to do, and I am not sure exactly how that is working. Are the 2 controllers completely separated each with their own project? (this also means you can have conflicting resource ids)In my setup the two controllers (one for each floor) runs with their own project. As far as I know that is the only way to set it up (and the way described in the documentation http://www.lk.dk/globalassets/pdf-arkiv/download/Manualer/IHCControl200_maj2006.pdf page 20). The controllers are linked so they can exchange data but are otherwise treated like two independent installations. I'm not aware of any conflicting IDs in my installation (will review later and check). I will be more than happy to check it out if you give it a go :-)Temperature, Humidity and light sensors are now supported in the new release 1.0.2 I have just madeI got my two controllers working simultaneous in hass. No conflicts so far. I made some small code changes to let them run on two individual domains ihc1 and ihc2. It was a quick and easy way of testing it out ;-)In the new release 1.02 it should be easier. In the main file change DOMAIN and in each platform file change the IHCDATA (both in the beginning of the file).Can you make a short example of how this looks for a two controller setup? I have been looking in your updated code and is a bit unsure how you mean.You make a copy of all the ihc.py files to ihc2.py. The main file is in the custom_components folder and then there is one file in each platform folder: switch, light e.t.c In the main ihc.py you change DOMAIN to DOMAIN="ihc2" and in the others you change IHCDATA to IHCDATA="ihc2" In you configuration you make an ihc2 section for the second controller, and for each secondary platform you write ihc2 like this: light: - platform: ihc2 ... Since I only have one controller I have not tried it, but I think it will work.Thanks! Then it is similar to the hack I made earlier. I read your update note as if I could avoide duplicating the files, which would have been an elegant solution ;-). This works though well enough for me!When you have connected your IHC system to HA with Jens's client it's time to add some automation. I'm no fan of the YAML format used by HA and if you have a large setup it gets soon pretty tricky. A few days ago I installed Node-RED on top of HA and I LOVE it! It makes automation fun and easy. You can find a pretty good introduction here: http://diyfuturism.com/index.php/2017/11/26/the-open-source-smart-home-getting-started-with-home-assistant-node-red/ I will strongly recommend you to check it out!! :-)
(c) 2010-2023 dingus.dk