Blueprint to switch and sync between KNX switch and Zigbee2MQTT lights

Hi,

I am using KNX and Zigbee in my house.

I would like to be able to switch the zigbee lights from a KNX wall switch. So when I press a button on the wall switch, the service light.turn_on (or off) should be called. Also, the status of the Zigbee lamp shall be sent back to KNX, so that the wall switch inbdicates the status and sends correct on / off telegrams.

An example for a KNX lamp that’s set up:

knx:
  light:
    - name: "Licht Wand"
      address: "1/1/64"
      state_address: "1/4/64"

I tried putting a blueprint together, but I can never wrap my head around programming. This is the result:

blueprint:
  name: Synchronisierung zwischen KNX und Zigbee
  description: sendet einen Befehl von KNX an Zigbee und meldet den Status zurück an KNX
  domain: automation
  input:
    entity_knx:
      name: KNX Entität
      description: KNX Licht (Schalten und Status)
      selector:
        entity:
    entity_zigbee:
      name: Zigbee Entität      description: Zigbee Leuchte 
      selector:
        entity:
          domain: light

trigger:
  - platform: state
    entity_id: !input entity_knx
  - platform: state
    entity_id: !input entity_zigbee

action:
  - choose:
      - conditions: "{{ trigger.entity_id == entity_knx }}"
        sequence:
          - service: >
              {% if is_state(trigger.entity_id, 'on') %}
              light.turn_on
              {% else %}
              light.turn_off
              {% endif %}
            target:
              entity_id: !input entity_zigbee
      - conditions: "{{ trigger.entity_id == entity_zigbee }}"
        sequence:
          - service: knx.send
            data:
              address: "{{ state_attr(entity_knx, 'state_address') }}"
              payload: "{{ is_state(entity_zigbee, 'on') }}"

When I press the wall buttonl, I see that the automation is triggered. but nothing happens. Can you help me make this work?

Have a look here KNX - relative dimming for lights blueprint · GitHub or here Advanced control of any light entity from KNX (state,brightness,dim,color + states feedback)

I think it would make more sense to only have 1 light entity - of that integration the light is from. Not 2 light entities - one of them a “dummy entity” that is just synced to the other.

2 Likes

Hi,

What I have done with similar situation (knx-hue), is to create a group of those entities and use the group to switch them on/off.

At this point I would like to mention that I’m pretty new to HA so maybe your way is more correct :slightly_smiling_face:

1 Like

entity_knx’ and ‘entity_zigbee’ needs to be put into a variable before it can be seen in a template, so that needs to be changed. Lots of examples in the BP Exchange, look at other BP;s and see how that’s done.

Personally I would add an id: to each of the triggers, then in the choose statement test for trigger_id: is one or the other.

1 Like

Thank you all for your replies!

The “Advanced Control…” blueprint which @farmio linked did the trick at the first try.
I also tried the group sawitch approach, which didn’t work for me.
It’s possible that the variables approach woudl have worked as well, but I’m happy to do without programming. It’s a weak spot for me.

Anyway, a huge headache solved that I wasted so much time on!

2 Likes