You might be like me, after all those years being happy on KNX you decided to add some non-KNX lights to the home and can’t turn them off with your magic bedside “All-Off” button.
Preparation
Create two new GA for this new function, one for switching and one for status. I’ll use 8/2/1
and 8/2/2
in the automation below.
Create a group in HASS with all the light you’d like to turn off. I’ll use “Vraies lumieres”.
Automation
To be copy-pasted into a blank automation and edited to your used case.
alias: "[Light] All-Off Parents"
description: ""
trigger:
- platform: homeassistant
event: start
- platform: event
event_type: automation_reloaded
- platform: event
event_type: knx_event
event_data:
destination: 8/2/1
action:
- choose:
- conditions:
- condition: template
value_template: >-
{{ trigger is defined and trigger.platform == "event" and
trigger.event.event_type == "knx_event" }}
sequence:
- choose:
- conditions:
- condition: template
value_template: >-
{{ trigger.event.data.destination == 8/2/1 and
trigger.event.data.data == 1 }}
enabled: true
sequence:
- service: light.turn_on
data:
entity_id: light.vraies_lumieres
enabled: false
- conditions:
- condition: template
value_template: >-
{{ trigger.event.data.destination == "8/2/1" and
trigger.event.data.data == 0 }}
sequence:
- service: light.turn_off
data:
entity_id: light.vraies_lumieres
- service: knx.send
data:
address: 8/2/2
payload: 0
- conditions:
condition: or
conditions:
- condition: template
value_template: "{{ trigger is not defined }}"
- condition: template
value_template: "{{ trigger.platform == \"homeassistant\" }}"
- condition: template
value_template: >-
{{ trigger.platform == "event" and trigger.event.event_type ==
"automation_reloaded" }}
sequence:
- service: knx.event_register
data:
address: 8/2/1
- service: knx.exposure_register
data:
address: 8/2/2
type: binary
entity_id: light.vraies_lumieres
How it works
This is based on the great examples found on the xknx discord.
Upon homeassitant start it checks that knx integration is loaded then registers a listener for the switching GA with the knx.event_register
service and exposes the state of the lights group to the other GA with knx.exposure_register
.
Conditional block ensures that we ask for Off ( payload = 0 ) before calling light light.turn_off
.
I’ve left the turn_on
part as disabled if you have any use for it.
Have fun!