Hi there,
I’m in the process of moving from OpenHAB (+Node Red) to Home Assistant (+Node Red) and am struggling with understanding how to translate an event value to an action to be performed on different lights. Hoping you can help!!
My installation has an old KNX/EIB system with devices (input sensors on buttons, dimmers, and relays to control lights) set up in KNX Easy Mode. This means I can’t use the KNX integration in its ‘normal’ mode (ie can’t read existing states, can’t control dimming levels, can’t use normal way to turn on the relays, etc etc).
What I can do instead is receive events when a button is pressed and send events to turn lights on/off. This works well in the existing solution, but I’m really struggling to get my head around how to do it in HASS.
Ideally what I’d like to do is something along the lines of:
- Set up virtual (template?) ‘lights’ in HASS to represent each of my 23 physical lights
- Bind Homekit to each ‘light’ so that I can see their status & turn them on/off with Homekit
- Have the ‘lights’ receive events from the KNX bus when physical buttons are pressed to reflect the new on/off status
- Have the ‘lights’ send events to the KNX bus to turn physical lights on/off when turned on/off in Homekit
- Also be able to use automations, Node Red, etc turn the ‘lights’ on/off as required
The events I receive in HASS from the KNX bus look like:
{
"event_type": "knx_event",
"data": {
"data": [
190
],
"destination": "1/0/10",
"direction": "Incoming",
"value": 190,
"source": "0.15.1",
"telegramtype": "GroupValueWrite"
},
"origin": "LOCAL",
"time_fired": "2022-01-17T00:24:49.138103+00:00",
"context": {
"id": "a5e99080a7af3d75a51e6aa90cc124ef",
"parent_id": null,
"user_id": null
}
}
The key pieces of data to look for are destination and value.
Destination is the “group address” of one of the lights on the KNX bus, and typically looks like ‘1/0/1’, ‘1/0/3’… etc (23 different group addresses for my lights)
The on/off state of the light is reflected in bit 1 (starting from bit 0, big-endian) of the value byte. Simple logic such as ((trigger.event.data.value | bitwise_and(2)) > 0) gives you the on/off state.
So, ideally, what I would have is some mechanism whereby, whenever a KNX event is received, the on/off state and light address are decoded, and that state is sent to the appropriate light. I would hope that either this can be done by a function that looks up the correct ‘light’ from an address table, or done directly by the ‘lights’ looking for events that correspond to their group address.
On the send side I guess the light can invoke a script with address & state values which then sends the appropriate command on the KNX bus (again, because of the type of KNX implementation, I can’t use the integration built-in functionality. Instead I need to send an event to the respective group address with a byte value of either ‘2’ (0x02) for ‘on’ or ‘0’ (0x00) for 'off.
I also -if possible- need to address the issue of ‘command duplication’. What I want to avoid if possible is the situation whereby, if a light is turned on/off by a physical KNX button press, that event changes the state of the corresponding ‘light’ in HASS, which then triggers a send event for the new state back to the KNX bus (that is, the destination light sees, for example, ‘on’ from button 5, and then also another ‘on’ from HASS). I can live with it if it’s unavoidable, but it sometimes causes funny issues with bus contention if several things happen all at once, so would prefer that we didn’t do that…
I think I sort of understand how to do the send side, but really need help to work out how to do the receive side. My feeling is that I need an automation that detects the event that fires a script that translates the destination & state, that then updates the appropriate ‘light’… but I’m really not sure that’s the ‘best’ way and sort of lost with how to do all that ‘properly’
Any hints are much appreciated!!! Thank you ![:slight_smile: :slight_smile:]()
1 post - 1 participant
Read full topic