Tutorial for fastest possible knx integration into home assistant

Hi
I figured out a way to transfer knx addresses into home assistant relatively quickly. It’s not exactly pretty, but it works. I made a tutorial which also servers as a quick and dirty beginners guide for HA.

Just to get all you KNX folks into home assistant! :slight_smile:

3 Likes

Hi there - very cool tutorial, well done!

I have a different question - I would like to organize the YAML files around an object in KNX, kind of in a similiar way or manner like I organize the group addresses in KNX around certain subjects.

For instance, let’s say I have a water pump that I can switch on/off and via the KNX actuator I also measure the power consumption and maybe the temperature of the water.

in KNX I would do the group addresses like this:

1/0/0 - SWITCH Pump Cold Water (switch)
1/0/1 - STATUS Pump Cold Water (state)
1/0/2 - POWER Pump Cold Water (power)
1/0/3 - TEMPERATURE Cold Water (temperature)

And then maybe I have a simple Light Switch with an integrated presence sensor:

2/0/0 - SWITCH Lights Office (switch)
2/0/1 - STATUS Lights Office (state)
2/0/2 - PRESENCE Office (state)

As you can see from above, in the KNX Group Address environment I can “mix” various types of objects such as switch, state, power, temperature in adjacent group addresses.

When I create the YAML file in Home Assistant, I would like to do the same thing:

KNX:

#START EVERYTHING AROUND PUMPS
  switch:
    -name: "Switch Pump Cold Water"
     address: "1/0/0"
     state_address: "1/0/1"

  sensor:
    -name: "Power Consumption Pump Cold Water"
     state_address: "1/0/2"
     type power
    -name: "Temperature Cold Water"
     state_address: "1/0/3"
     type: temperature
#END EVERYTHING AROUND PUMPS  


#START EVERYTHING AROUND OFFICE
  switch:
    -name: "Switch Office Lights"
     address: "2/0/0"
     state_address: "2/0/1"

  binary_sensor:
     -name: "Presence Office"
     state_address: "2/0/2"

#END EVERYTHING AROUND LIGHTS

The issue is that Home Assistant accepts the YAML files when checking it under Developer tools/Check configuration, but somehow the KNX objects are not created correctly within the Devices/Entities.

I checked the Debug File and found the following errors (ignore the file name that are not corresponding to the above sample which is for illustration purpose only):

2023-06-02 18:00:17.111 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /config/inc_knx.yaml contains duplicate key "switch". Check lines 4 and 40
2023-06-02 18:00:17.111 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /config/inc_knx.yaml contains duplicate key "switch". Check lines 40 and 50
2023-06-02 18:00:17.111 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /config/inc_knx.yaml contains duplicate key "sensor". Check lines 17 and 59
2023-06-02 18:00:17.111 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /config/inc_knx.yaml contains duplicate key "switch". Check lines 50 and 115
2023-06-02 18:00:17.111 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /config/inc_knx.yaml contains duplicate key "switch". Check lines 115 and 121
2023-06-02 18:00:17.111 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /config/inc_knx.yaml contains duplicate key "sensor". Check lines 59 and 133
2023-06-02 18:00:17.111 WARNING (SyncWorker_0) [homeassistant.util.yaml.loader] YAML file /config/inc_knx.yaml contains duplicate key "binary_sensor". Check lines 129 and 145

In a nutshell, home assistant KNX integration does not like to have switches, sensors, binary sensors etc defined more than once.

My question is if that is correct which means I must just re-organize my YAML file(s).

A bit annoying, as it is logically so much nicer to organize objects around its purpose, and not around its technical abilities.

Has anyone had a similiar problem, and maybe found a work-around?

Thanks
Martin

1 Like

I suppose I could have figure this out myself - but the PACKAGES concept helped a lot…

Hello.
this is a great tutorial, However i need your help with knx to home assistant. is there a n option to contact you directly ?

Hi Martin,

Were you able to find a solution for this ?

Karthik

@kartmys yes the packages concept helps.

See example below:

in configuration.yaml I have:

homeassistant:
  # KNX integration via packages
  packages: !include_dir_merge_named inc_packages/

then I have a directory inc_packages with lots of inc_*.yaml files:

and in each of them I can re-use switches, sensors etc for instance:

#included file from ../configurations.yaml

pack_pool:
  knx:
    switch:
      #pumps
      - name: "G150 Pool Pump"
        address: "2/3/0"
        state_address: "2/3/2"
      - name: "G151 Pool Chlorinator"
        address: "2/3/4"
        state_address: "2/3/6"

    sensor:
      #Watt Consumption
      - name: "G150 Pool Pump"
        state_address: "2/3/3"
        type: power
      - name: "G151 Pool Chlorinator"
        state_address: "2/3/7"
        type: power
      - name: "G150 Pool Temperature"
        state_address: "2/5/23"
        type: temperature

  binary_sensor:
    - platform: threshold
      #G151 Pool Chlorinator Status: when chlorinator uses more than 40 watt then its properly running--> set status to on
      name: G151 Pool Chlorinator Status
      entity_id: sensor.g151_pool_chlorinator
      upper: 40
      hysteresis: 2
      device_class: running

Keep in mind that you have to have a unique package definition, in this case in the file inc_pool.yaml I use “pack_pool:” as the definition. I have plenty of include files all around various subjects to organize my yaml files better.

If you need more help around packages use this link to the documentation:

Best,
Martin

1 Like