Sync KNX Dummy Buttons on Startup

Hi there,

Unfortunately I still have some difficulties to find my way in yaml with templates.

I have created some dummy switches to control my Ikea lamps via my KNX light switches. I syncronize these switches with the status of my ikea switches when they are turned on or off.

After starting the server these switches are unfortunately not syncron until they have been pressed once.

So I wanted to create an automation that would initialize the switches when starting the server. The script does not report an error but unfortunately the automation is also without function.

Please, can someone tell me where the error is?

  - alias: Mirror Dummy Switches at Startup
    trigger:
    - platform: homeassistant
      event: start
    action:
      - service_template: "switch.turn_{{ light.nachttischlampe.state }}"
        entity_id:
          - switch.knx_dummy_nachttischlampe
      - service_template: "switch.turn_{{ light.ballonlicht.state }}"
        entity_id:
          - switch.knx_dummy_ballonlicht
      - service_template: "switch.turn_{{ light.esszimmer.state }}"
        entity_id:
          - switch.knx_dummy_esstisch
      - service_template: "switch.turn_{{ light.gaestezimmer.state }}"
        entity_id:
          - switch.knx_dummy_gaestezimmer
      - service_template: "switch.turn_{{ light.stehlampe.state }}"
        entity_id:
          - switch.knx_dummy_stehlampe

Can you show how you configure your switches? Do they get out of sync if you toggle the lights via Ikea app (or whatever they can be toggled with that is not knx and not HA)?

I think you could expose the entity_id to knx (https://www.home-assistant.io/integrations/knx#exposing-sensor-values-or-time-to-knx-bus) and use this GA as listening address on your switch. Exposures send on HA start. It may double-send the status then - to avoid this you can (if you have) omit the state_address of your switch as the exposure takes care of this.

Hi Matthias,

thanks for your quick reply.

Thats my current configuratio. I will post the code of one light only to keep it simple.

Thats my Ikea Trädfri light:
light.esszimmer

To toggle that light via KNX bus i’ve created a group address in ETS which has no connection to any KNX actors.
Then i have created a switch in HA:

switch:
# KNX Dummy Lights Esszimmer
  - platform: knx
    name: 'KNX Dummy Esstisch'
    address: '4/0/1'

This automation will switch the light if the physical KNX switch is pressed (which is only working if the KNX dummy switch and the light have the same state):

automation:   
 - alias: 'Turn OnOff Esstisch Light'
    initial_state: true
    trigger:
      platform: state
      entity_id: switch.knx_dummy_esstisch
    action:
      service_template: "light.turn_{{ trigger.to_state.state }}"
      entity_id:
        - light.esszimmer

The following automation will mirror the state of the light back to the KNX bus if i turn off the light via the IKEA switch or App.

automation:  
- alias: Mirror Switch Esszimmer
    trigger:
    - platform: state
      entity_id:
      - light.esszimmer
    action:
      service_template: "switch.turn_{{ trigger.to_state.state }}"
      entity_id:
        - switch.knx_dummy_esstisch

So far so good, but if i restart the HA server and the light is still turned ON the KNX switch will remain OFF.
Before i can switch off the light via the KNX switch i have to press ON on the KNX switch to mirror the state and after that i am able to control the light as usual.

Exposing the light to knx sounds like a good plan to reduce many automations
but as the light is not assigned to any KNX actors, i will not have a state_address on the KNX bus.
I will try that later today and post the result.

Whats the correct sensor type in HA to represent a switch 1.001 1bit?
I tried to expose it as a binary but switching the light On or Off from HA will not send any messages to the KNX bus.

  expose:
    - type: 'binary'
      entity_id: 'light.esszimmer'
      address: '4/0/1'

The knx switch has an internal state (on or off) and on every press it sends the other one. Every time a value is received over the bus the state gets updated - this way every switch stays in sync.

I think the switch device only sends when it is used (the switch itself it toggled). The expose device should send on every update.

knx:
  expose:
    - type: 'binary'
      entity_id: 'light.esszimmer'
      address: '4/0/1'

switch:
  - platform: knx
    name: 'KNX Dummy Esstisch'
    address: '4/0/1'
    state_address: '4/0/1'

If this doesn’t do the trick I’m at the end of my wisdom. I’m afraid I have no device to test such things.

I’m afraid somehow that doesn’t want to actually work.
Do you have any idea why this code doesn’t work?
Then I would use it until I found a better solution.

- alias: Mirror Dummy Switches at Startup
    trigger:
    - platform: homeassistant
      event: start
    action:
      - service_template: "switch.turn_{{ light.nachttischlampe.state }}"
        entity_id:
          - switch.knx_dummy_nachttischlampe
      - service_template: "switch.turn_{{ light.ballonlicht.state }}"
        entity_id:
          - switch.knx_dummy_ballonlicht
      - service_template: "switch.turn_{{ light.esszimmer.state }}"
        entity_id:
          - switch.knx_dummy_esstisch
      - service_template: "switch.turn_{{ light.gaestezimmer.state }}"
        entity_id:
          - switch.knx_dummy_gaestezimmer
      - service_template: "switch.turn_{{ light.stehlampe.state }}"
        entity_id:
          - switch.knx_dummy_stehlampe

I have tried
- service_template: "switch.turn_{{ light.stehlampe.to_state.state }}"
but even without success.

Is there anything wrong with the template?

Hi,

i found the solution by myself:

      - service_template: "switch.turn_{{ states('light.ballonlicht') }}"
        entity_id:
          - switch.knx_dummy_ballonlicht

Now, the switches are synchronized when the server is restarted.

1 Like

Hi Oliver,

I want to use a button on my universal interface (KNX) switch to communicate with an HA automation.
The button is not allocated with an actuator.
Do you have an idea how I can get that working?

Maybe you can provide some screenshots of the ETS configuration you used for that groupaddress?

Hi,

you just need to create a new group address and assign the On/Off function from the switch to it.

In HA you can create a dummy switch:

switch:
# KNX Dummy Lights Gaestezimmer
  - platform: knx
    name: 'KNX Dummy Gaestezimmer'
    address: '6/0/0'
1 Like

Hey,
if you still have this topic open, send me a message. I have several of this dummy buttons, but that belongs not to this thread.

Hi, I was able to get it working thanks guys.