Customizing Home Assistent IHC auto setup
I have had some questions about the auto setup of IHC in Home Assistant, and since this is not described on the Home Assistant documentation pages, this post will be about how you can customize the auto setup.
How does the auto setup work?
The auto setup is done by searching in the IHC project for patterns of predefined component. The IHC project file is a XML file. The search is done using xpath (this is a standard expression for selecting nodes in XML). I will not describe it further here, you can do a search for xpath tutorial in google and you can find plenty of information about it. The home assistant IHC integration has a predefined ihc_auto_setup.yaml file in the homeassistant/components/ihc folder. This file already has setup for the most commonly used products. The file has a section for binary_sensor, sensor, light and switch. All have the 2 variables:
The xpath expression to find the product
The name of the xml node containing the resource to map into home assistant
Below is the platform specific variables for binary_sensor, sensor, light and switch.
The IHC resource (refereed to by node) most be a boolean resource (on/off)
The binary sensor type in home assistant. Look in Home Assistant Binary Sensor for a list of build in types. (device classes)
The IHC resource referred be the node can be a integer of float resource.
The unit of measurement to be used in Home Assistant
Boolean (True/False). Set to True if the light is a dimmer. If you do not set this and the type of the resource is a integer (light level in the IHC project) the light will also be a dimmable.
Has no additional variable, The resource should be a boolean (on/off)
Customizing the auto setup
The first step is to copy the ihc_auto_setup.yaml into your configuration folder. If the configuration folder contains a ihc_auto_setup.yaml file this will replace the build in file. If you can not file the file (or have a docker installation where the file is more difficult to access), you can get is directly for the home assistant github page
Open the ihc_auto_setup.yaml file in whatever editor you use for yaml files.
Removing products from the auto setup
Find the product you don’t want and delete all the lines from “- xpath” under the product. Each product has a comment describing what it is. After making change to the auto setup you have to restart home assistant.
Adding a new product to the auto setup
Create a new IHC project only containing the product you want to used for auto setup. This makes is easier to identify in the project file. Save the project file and open it on a text editor, preferable one that can show xml syntax (or a browser)
I will give and example adding the an actuator ( “telestat” in danish – my ihc applications are in danish – and screen dumps will be in danish)
Looking in the saved ihc project we can find the “Telestat”:
<group id="_0x2132" name="Stue" icon="_0x15"> <product_dataline id="_0x5153" product_identifier="_0x220a" name="Telestat" locked="yes" icon="_0x84"> <dataline_output id="_0x525b" name="Udgang" backup="yes"/> </product_dataline> </group>
Now we need to write an xpath expression to select the product_dataline node. It is a good idea to have some kind of xpath tester when doing this. You can use an online tool like this xpath tester In the XML section paste the complete IHC project. In the xpath field write an xpath expression:
If you look at the above xpath you can see it is similar to some of the other xpath expressions from the auto setup. The only difference is that it has another product_identifier. Clicking the “test” button in the xpath tester we can see it will find the xml node we are looking for. We can also see the child node for the resource is the “dataline_output”, so that will be the “node” in the auto setup.
If you want to make sure the xpath expression does not find too many nodes (nodes you don’t want), it is a good idea to also test with a full IHC project in the xpath tester.
If we want to add this as a binary_sensor we will have:
- binary_sensor - xpath: './/product_dataline[@product_identifier="_0x220a"]' node: 'dataline_output' type: 'heat'
We could also have added the actuator as a switch is case we want to control it from home assistant. To do this you just move it to the “switch” section of the auto setup file, and remove the “type” variable.
Notes on editing yaml
When I stated using Home Assistant the most frustrating thing was the yaml files (I am still not a big fan, but I can live with it). To make it less frustrating make sure you have an yaml editor that can validate it and have syntax highlighting (Like Visual Studio Code with a yaml extension)
Secondly use the “Config validation” in home assistant before you restart home assistant