I should be able to integrate this or help you adapt my app to your needs. I need some more details from you.
You receive a telegram notification when you press a button on the wall switch? How do these notifications look like? How many buttons do you have and which button presses are supported (single click, double click, long press, long press release, etc.).
Hi Burningstone,
First, thanks a lot for your help. This has been bothering me since I started with HA, so if you can help me I would be really grateful!
You can find some info on my switches here.
Since they are knx, they are more or less configurable. I am using two buttons with a rocker dimmer function. They work like this:
Button A short: On
Button A long: Dimming up
Button A release after long: Stop dimming
Button B short: Off
Button B long: Dimming down
Button B release after long: Stop dimming
In the following image you can see the telegrams from the knx bus, the ones marked in blue are from up to down respectively:
Button A short: On ($01 | Ein)
Button B short: Off ($00 | Aus)
Button A long: Dimming up ($09 | Ein)
Button A release after long: Stop dimming ($00 | Aus)
Button B long: Dimming down ($01 | Ein)
Button B release after long: Stop dimming ($00 | Aus)
Seems to me like the switches are not sending a % value but only saying when to switch on/off or start/stop dimming
I don’t know if you are familiar with knx, butwant to signal to you that even if the same button (A or B) is pressed, each action (long or short) is sent to a different Goup Address (GA 5/1/19 or 5/2/19).
I don’t know if this is enough for you. I just fount out about AppDamon yesterday so I don’t know how, but If you tell me how to read the telegrams with AppDaemon I would gladly try.
The supported button presses are enough to make the dimming work.
Do you have an entity created for the switch in home assistant or do you see button presses trough events? Or how do you currently see if a button has been pressed? Can you maybe show me a Home Assistant automation you currently have for a KNX switch?
Hi, I went right to node-red for my automations and skipped HA’s… In the end I would like to move from node-red to AppDaemon, I have some experience with python and find it better than yaml and the nodes are getting unwieldy…
This is how I switch on/off right now:
This was a test to see what messages are sent by the knx bus:
But of course I could create entities (lights or switches) if that helps.
No need to create entities.
I never used Node-Red but how do you receive these events from KNX in the first node? Is this a HA event?
It’s a node-red knx integration, this is listening the knx bus trough the “T 13 AB” node, and when a telegram is fired tells HA to call a service “light:turn on/off”
There is some info on knx-ha automations here, in this Jypsy mentions how to control a knx light:
knx:
switch:
- platform: knx
# The normal on/off switch for the light
name: "Licht, Eltern Bett"
address: '1/2/12'
- platform: knx
# The switch that triggers the dim script
# This switch must be configured in ETS to send on when pressed and off when released
name: "Licht, Eltern Bett, Fadeout"
address: '1/2/17'
light:
# This is the light that we want to dim (more precisely it is the dimming actuator of the light).
# It is directly controlled through the first switch above.
# (Note that the switch shares its group address with this light and thus controls it over the KNX bus.)
- platform: knx
name: 'Eltern Bett'
address: '1/2/12'
state_address: '1/2/15'
brightness_address: '1/2/13'
brightness_state_address: '1/2/16'
automation:
# start the dim script, if the dim switch is pressed
- id: light_eltern_bett_fadeout
alias: Licht Eltern Bett Fade-Out
trigger:
- entity_id: switch.licht_eltern_bett_fadeout
platform: state
to: 'on'
condition: []
action:
# in case the script was already running, we first stop it
- service: script.turn_off
entity_id: script.light_eltern_bett_fadeout
- service: script.turn_on
entity_id: script.light_eltern_bett_fadeout
# stop the dim script, if light is switched manually
- id: light_eltern_bett_fadeout_stop
alias: Licht Eltern Bett Fade-Out STOP
trigger:
- entity_id: switch.licht_eltern_bett
platform: state
# no argument here = trigger with ANY state change
condition: []
action:
- service: script.turn_off
entity_id: script.light_eltern_bett_fadeout
script:
light_eltern_bett_fadeout:
alias: Licht Eltern Bett Fade-Out
sequence:
- service: light.turn_on
entity_id: light.eltern_bett
data:
brightness_pct: 80
- delay: '00:01:00'
- service: light.turn_on
entity_id: light.eltern_bett
data:
brightness_pct: 60
- delay: '00:01:00'
- service: light.turn_on
entity_id: light.eltern_bett
data:
brightness_pct: 40
- delay: '00:01:00'
- service: light.turn_on
entity_id: light.eltern_bett
data:
brightness_pct: 20
- delay: '00:01:00'
- service: light.turn_on
entity_id: light.eltern_bett
data:
brightness_pct: 10
- delay: '00:01:00'
- service: light.turn_off
entity_id: light.eltern_bett
or hue light:
knx:
sensor:
- platform: knx
name: "Licht, Couch DimAbs"
state_address: '1/1/52'
type: "percent"
- platform: knx
name: "Licht, Couch FarbTemp"
state_address: '1/1/54'
type: "percent"
automation:
# handle brightness values > 0
- id: light_knx_to_hue_couch_percent
alias: Licht Couch KNX an Hue PROZENT
initial_state: 'on'
trigger:
- platform: state
entity_id: sensor.licht_couch_dimabs
condition:
- condition: template
value_template: '{{ (float(trigger.to_state.state) > 0) }}'
action:
# turn on / set brightness for the Hue bulbs
- service: light.turn_on
data_template:
entity_id: light.hue_couch_1, light.hue_couch_2, light.hue_couch_3
brightness: '{{ (float(trigger.to_state.state) * 255 / 100) | round(0) }}'
# turn on the Osram on-off-plug
- service: light.turn_on
entity_id: light.steckdosenschalter_couch
# handle brightness value == 0 (which means OFF)
- id: light_knx_to_hue_couch_percent_off
alias: Licht Couch KNX an Hue PROZENT AUS
initial_state: 'on'
trigger:
- platform: state
entity_id: sensor.licht_couch_dimabs
to: '0'
condition:
action:
- service: light.turn_off
entity_id: light.hue_couch_1, light.hue_couch_2, light.hue_couch_3, light.steckdosenschalter_couch
# Handle color temp values
- id: light_knx_to_hue_couch_color
alias: Licht Couch KNX an Hue FARBE
initial_state: 'on'
trigger:
- platform: state
entity_id: sensor.licht_couch_farbtemp
condition:
action:
- service: light.turn_on
data_template:
entity_id: light.hue_couch_1, light.hue_couch_2, light.hue_couch_3
# Do some math to convert 0...100% into the min/medium/max color temperature of your bulbs.
# The color temperature is defined in Mireds instead of Kelvin (Mired = 1,000,000 / Kelvin).
# The lowest and highest available Mired value is read from the attributes of one of the bulbs,
# so this works with Hue as well as Trådfri.
color_temp: '{{ ((1 - float(trigger.to_state.state) / 100) * (states.light.hue_couch_1.attributes.max_mireds - states.light.hue_couch_1.attributes.min_mireds) + states.light.hue_couch_1.attributes.min_mireds) | round(0) }}'
I believe that the problems for me are:
A) I don’t have knx dimmer actuators and,
B) The switches that he is using have more in-built logic, so they can send an absolute value in %.
Because of that I believe that python’s for or while loops would be a good solution generate this logic…
Do I understand correctly that you don’t have KNX integrated in home assistant but only through the node red integration for KNX? If so, then I need to read up a bit on this integration first to see how I can get this into AppDaemon.
Hi, heating, covers, switches, sensors, etc are integrated in HA. I can also control my hue lights with the conbee + deconz + homeassistant interface combination. I am only using node-red to switch the hue lights on or off. So in the end everything is integrated in home assistant, with the exception of the switching action, this is done with node-red. This is mainly because I find node-red a lot easier than the home assistant automations.
I have the feeling that the challenge here is going to be finding out how to listen to the knx telegrams with AppDaemon, just like node-red is doing in the actual switching action that I created and that is posted above in this thread… I asked in the discord xknx chat if this is possible but there was no answer so far…
Sorry if I sound stupid, you say the switches are integrated in HA. Are you able to see in Home Assistant when a switch has been pressed and which button has been pressed or do you only see this in Node-Red?
Not stupid, I have the feeling that I have not been able to convey to you how my configuration work. You are trying to help and investing your time on this, so you can ask whatever you want. I am grateful for your help.
Back to your question, I made a mistake before when I said that everything but the switching action is integrated in HA, in reality the wall switches themselves are not integrated in HA. But I can see their actions in the HA interface, because when they are pressed node-red calls a “light turn on” service on a hue light that is controlled by the conbee stick. The hue lights are themselves integrated in the deconz app, so their states are visible to HA.
Hope that this helps!
Ok, I think I understood now. I will try to read up on how Node-Red reads the telegram notifications from the KNX bus and then try to port it to AppDaemon, or maybe I’ll find a python example somewhere.
If you would integrate the switch into HA, would you see which button has been pressed in HA?
Great!
I am not a home right now, but will try later when I’m there. I’ll let you know then if that works.
I checked the code for the Home Assistant KNX integration and it seems like I don’t need to code something to receive telegram commands, because HA does it already for me (you) and if I understand it correctly, you will receive an event in HA with type “knx_event”, which contains the address and the payload. If this is true, you can listen for these events under Developer Tools -> Events -> enter “knx_event” in the “Listen to events” box -> press start listening. Now press each possible variation (short press, long press, long press release etc.) to get the different events. You can then post these events here and I will help you create the appdaemon app.
I was about to ask you how to listen to the knx events. Let me see if it works…
Are you sure about the “knx_event”? Because I did this:
- platform: knx
name: Test Switch
address: '5/1/19'
state_address: '5/1/19'
- platform: knx
name: Test Dimmer
address: '5/2/19'
state_address: '5/2/19'
After restarting and trying to listen to the “knx_event” nothing happened. But both switches are there, added them to the ui:
Using “state_changed” got this:
Short Up
Event 0 fired 8:44 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "switch.test_switch",
"old_state": {
"entity_id": "switch.test_switch",
"state": "off",
"attributes": {
"friendly_name": "Test Switch"
},
"last_changed": "2020-01-06T19:43:29.745620+00:00",
"last_updated": "2020-01-06T19:43:29.745620+00:00",
"context": {
"id": "70782b8505854768b905fac61f788d07",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "switch.test_switch",
"state": "on",
"attributes": {
"friendly_name": "Test Switch"
},
"last_changed": "2020-01-06T19:44:27.683055+00:00",
"last_updated": "2020-01-06T19:44:27.683055+00:00",
"context": {
"id": "3cffaa7b1dbc42979c14b95d05bb97fc",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2020-01-06T19:44:27.683106+00:00",
"context": {
"id": "3cffaa7b1dbc42979c14b95d05bb97fc",
"parent_id": null,
"user_id": null
}
}
Short Down:
Event 3 fired 8:44 PM:
{
"event_type": "state_changed",
"data": {
"entity_id": "switch.test_switch",
"old_state": {
"entity_id": "switch.test_switch",
"state": "on",
"attributes": {
"friendly_name": "Test Switch"
},
"last_changed": "2020-01-06T19:44:27.683055+00:00",
"last_updated": "2020-01-06T19:44:27.683055+00:00",
"context": {
"id": "3cffaa7b1dbc42979c14b95d05bb97fc",
"parent_id": null,
"user_id": null
}
},
"new_state": {
"entity_id": "switch.test_switch",
"state": "off",
"attributes": {
"friendly_name": "Test Switch"
},
"last_changed": "2020-01-06T19:44:27.933081+00:00",
"last_updated": "2020-01-06T19:44:27.933081+00:00",
"context": {
"id": "6a32aa1550864f5cb7f5cfe765b59a53",
"parent_id": null,
"user_id": null
}
}
},
"origin": "LOCAL",
"time_fired": "2020-01-06T19:44:27.933153+00:00",
"context": {
"id": "6a32aa1550864f5cb7f5cfe765b59a53",
"parent_id": null,
"user_id": null
}
}
When testing dimming got only two events, was naturally expecting four. Seems to me like the knx integration doesn’t support one of the data types sent by the dimmer, maybe dpt 3.007.
I will try to change the switch configuration and see if I can get four events fired.
These are the events from home assistant due to the entity changing state, not the events I was looking for. Hmm need to check the code again…
Hi Burningstone,
If it helps, node-red does support dpt 3.007. Got this:
Short Up
1/6/2020, 9:06:07 PMnode: 74f87285.3f9d64
5/1/19 : msg : Object
object
topic: "5/1/19"
payload: object
decr_incr: 0
data: 1
knx: object
event: "GroupValue_Write"
dpt: "3.007"
dptDetails: object
basetype: object
bitlength: 4
valuetype: "composite"
desc: "4-bit relative dimming control"
subtypes: object
007: object
name: "DPT_Control_Dimming"
desc: "dimming control"
008: object
name: "DPT_Control_Blinds"
desc: "blinds control"
id: "DPT3"
fromBuffer: function
formatAPDU: function
subtypeid: "007"
subtype: object
name: "DPT_Control_Dimming"
desc: "dimming control"
source: "1.1.32"
destination: "5/1/19"
rawValue: buffer[1]
0: 0x1
_msgid: "2c58e96b.e2baa6"
Short Down:
1/6/2020, 9:06:08 PMnode: 74f87285.3f9d645/1/19 : msg : Object
object
topic: "5/1/19"
payload: object
decr_incr: 0
data: 0
knx: object
event: "GroupValue_Write"
dpt: "3.007"
dptDetails: object
basetype: object
bitlength: 4
valuetype: "composite"
desc: "4-bit relative dimming control"
subtypes: object
007: object
name: "DPT_Control_Dimming"
desc: "dimming control"
008: object
name: "DPT_Control_Blinds"
desc: "blinds control"
id: "DPT3"
fromBuffer: function
formatAPDU: function
subtypeid: "007"
subtype: object
name: "DPT_Control_Dimming"
desc: "dimming control"
source: "1.1.32"
destination: "5/1/19"
rawValue: buffer[1]
0: 0x0
_msgid: "bfeb7464.036828"
Long Up Press:
1/6/2020, 9:15:19 PMnode: 6fc9c6e.0a451b8
5/2/19 : msg : Object
object
topic: "5/2/19"
payload: object
decr_incr: 1
data: 1
knx: object
event: "GroupValue_Write"
dpt: "3.007"
dptDetails: object
basetype: object
bitlength: 4
valuetype: "composite"
desc: "4-bit relative dimming control"
subtypes: object
007: object
name: "DPT_Control_Dimming"
desc: "dimming control"
008: object
name: "DPT_Control_Blinds"
desc: "blinds control"
id: "DPT3"
fromBuffer: function
formatAPDU: function
subtypeid: "007"
subtype: object
name: "DPT_Control_Dimming"
desc: "dimming control"
source: "1.1.32"
destination: "5/2/19"
rawValue: buffer[1]
0: 0x9
_msgid: "b6478b20.de9878"
Long Up Release:
1/6/2020, 9:15:20 PMnode: e7484cb6.c024985/2/19 : msg : Object
object
topic: "5/2/19"
payload: object
decr_incr: 0
data: 0
knx: object
event: "GroupValue_Write"
dpt: "3.007"
dptDetails: object
basetype: object
bitlength: 4
valuetype: "composite"
desc: "4-bit relative dimming control"
subtypes: object
007: object
name: "DPT_Control_Dimming"
desc: "dimming control"
008: object
name: "DPT_Control_Blinds"
desc: "blinds control"
id: "DPT3"
fromBuffer: function
formatAPDU: function
subtypeid: "007"
subtype: object
name: "DPT_Control_Dimming"
desc: "dimming control"
source: "1.1.32"
destination: "5/2/19"
rawValue: buffer[1]
0: 0x0
_msgid: "1a036150.cc8f3f"
Long Down Press:
1/6/2020, 9:18:42 PMnode: a2930588.c531d8
5/2/19 : msg : Object
object
topic: "5/2/19"
payload: object
decr_incr: 0
data: 1
knx: object
event: "GroupValue_Write"
dpt: "3.007"
dptDetails: object
basetype: object
bitlength: 4
valuetype: "composite"
desc: "4-bit relative dimming control"
subtypes: object
007: object
name: "DPT_Control_Dimming"
desc: "dimming control"
008: object
name: "DPT_Control_Blinds"
desc: "blinds control"
id: "DPT3"
fromBuffer: function
formatAPDU: function
subtypeid: "007"
subtype: object
name: "DPT_Control_Dimming"
desc: "dimming control"
source: "1.1.32"
destination: "5/2/19"
rawValue: buffer[1]
0: 0x1
_msgid: "b077145a.bf8818"
Long Down Release:
1/6/2020, 9:18:43 PMnode: e7484cb6.c024985/2/19 : msg : Object
object
topic: "5/2/19"
payload: object
decr_incr: 0
data: 0
knx: object
event: "GroupValue_Write"
dpt: "3.007"
dptDetails: object
basetype: object
bitlength: 4
valuetype: "composite"
desc: "4-bit relative dimming control"
subtypes: object
007: object
name: "DPT_Control_Dimming"
desc: "dimming control"
008: object
name: "DPT_Control_Blinds"
desc: "blinds control"
id: "DPT3"
fromBuffer: function
formatAPDU: function
subtypeid: "007"
subtype: object
name: "DPT_Control_Dimming"
desc: "dimming control"
source: "1.1.32"
destination: "5/2/19"
rawValue: buffer[1]
0: 0x0
_msgid: "e674c199.01b75"
I am no expert but seems like “decr_incr” and “data” hold meaningful information…
Cheers.
Hi again,
Farmio shared this in the xknx discord chat.
Seems like the actual knx integration doen’t support dpt 3.007 and that is what my wall switches use to send dimming telegrams.
Ok I will take a look at it, but iw will take some time, maybe I’ll find some time to create something in the weekend, no promises.
No worries, I understand if it doesn’t works. Looks quite complicated, thanks for your efforts.