Sure, it’s quite simple, but works fine. The the first button is the on/off toggle plus the volume, the other button is the selector of the source. I’m gonna refine it by making dynamic grouping of Sonos players (I have a bunch ) based on the presence in each room. Grouping in Sonos is quite slow sometimes, it cannot follow presence in real-time, but it gives a feeling.
Dear Farmio, all,
after hours of various trials, I definitely need your help…
I’ve a KNX Wall Switch operating as one button dimmer with the 2 objects (one is 1.001 and the other one 3.007), as per your example I believe.
I want to use this switch to control a SHELLY light through HA.
I do see the knx_event with the right data in the log, but the light doesn’t switch nor dimmer…
The Shelly light already works fine with a simple dimmer control in lovelace…
I’m using the HA core-2021.4.6.
I post here below the YAML conf I’ve in my light file package configuration:
Hi, I am new to HA and KNX, so please bear with me.
I want to connect a KNX wall switch with a Shelly Plug S to which I attached a light. The KNX wall switch is configured in ETS to “toggle”. It sends GA “3/0/0” and also reads GA “0/1/0” and “0/1/3” to sync its state with “global” actions like “All lights off” and “All lights in room (Wohnzimmer) off”. The connection between the KNX wall switch and the Shelly Plug S needs to be bidirectional: If I toggle the wall switch, the Shelly/light should toggle. If I toggle the Shelly/light via HA, the wall switch state should be synchronized to that the next toggle of the wall switch is correct.
In addition to this thread, I also read the following related topics several times.
Below you find my current solution. It works exactly as described above. So basically all good. However, I have a few questions:
Is this really the best, cleanest, minimal way to achieve this? I doubt that so many lines of “code” are required for such a “common” scenario.
If yes, how can I make this reusable? I have like 5+ same scenarios? Is this possible with scripts or templates? As said, I am new to HA and don’t know them yet.
My current solution:
Shelly integration provides:
light.wohnzimmer_stehlampe
KNX wall switch → Shelly/light:
knx:
binary_sensor:
- name: "Wohnzimmer Schalter Stehlampe"
state_address:
- "3/0/0"
- "0/1/0"
- "0/1/3"
automation:
- alias: "Wohnzimmer Stehlampe anschalten via KNX Schalter"
trigger:
- platform: state
entity_id: binary_sensor.wohnzimmer_schalter_stehlampe
to: "on"
action:
- service: light.turn_on
entity_id: light.wohnzimmer_stehlampe
- alias: "Wohnzimmer Stehlampe ausschalten via KNX Schalter"
trigger:
- platform: state
entity_id: binary_sensor.wohnzimmer_schalter_stehlampe
to: "off"
action:
- service: light.turn_off
entity_id: light.wohnzimmer_stehlampe
Be aware that a binary sensor sends GroupValueRead requests to its first state_address periodically by default. An expose on the other hand answers such - so HA is (maybe - depending on which telegram is faster) answering itself if you use the same addresses for these.
If 3/0/0 is exclusively used for this light I wouldn’t use a binary_sensor - it already has its HA entity from the shelly integration anyway. Just use a knx_event as trigger in an automation matching the 3 GAs and the payload (1 or 0) directly.
Enter the world of blueprints! About blueprints - Home Assistant
See also Topics tagged knx there are already 2 which could fit your needs (one of them is mine ). You can also just use them as examples on how to use knx_event.
Just be aware that reloading the KNX integration breaks register_event and register_expose services - so maybe better configure them in yaml.
I would have some last questions in case you ever find the time. Any feedback would be highly appreciated.
This is even more code than before. Do you see any options to minimize it?
On state change I see 2 knx_events, “Incoming” and “Outgoing”. The outgoing I actually do not need but I guess it’s because of the expose, right? BTW: I wonder why “Incoming” uses 0/1 while “Outgoing” uses false/true as data.
Is the knx_event solution better than binary_sensor with sync_state: init? binary_sensor would allow me to group the addresses (3 per wall switch) while event_filter seems to be just a long list containing addresses of all switches (5 * 3 = 15 in my case). I should at least separate them with a comment. On the other hand you are of course right, I don’t need the binary_sensor entity since I already have the Shelly entity.
In the current docs about KNX I could not find anything about event_filter, only about events which seems to be not valid anymore: KNX - Home Assistant
If I am not mistaken, blueprints are “only” for automations and work with the UI instead of YAML. Furthermore, you mentioned that the “KNX integration” breaks on reload if not specified in YAML. And last but not least my scenario needs not only automations but also knx: event_filter and knx: expose. So I don’t see any benefit of using blueprints for this. Did I miss something?
Maybe the destination matches can be templated with some kind of in([0/1/2, 0/1/4]) or something.
Or use a trigger_id.
event_filter was just deprecated in favor of event in 2021.12
you can use blueprints for the automation part, the event-GAs should be enabled in yaml. So should the expose be done in yaml. But in the end some copy&paste will do as well.
Only register_event and register_expose service doesn’t survive a reload.
I understood the “in(…)” idea but did not find a solution so far. I did not understand the “trigger_id” idea but will try to figure it out.
I assume no answer to question 2 means: This is expected.
I assume no answer to question 3 means: binary_sensor with sync_state: init is not a good solution.
I just updated to HA 2021.12.1. On startup it says “The ‘event_filter’ option is deprecated, please remove it from your configuration”. If I change it to ‘event’, it says ‘Invalid config’. So I assume I have to keep ‘event_filter’ for now.
Understood. Thanks. I won’t use blueprints in this case.
What I also don’t yet understand is how HA syncs the current state between my wall toggle switch and the Shelly/light on HA startup. I assume this is done implicitly by using expose.
In fact, I read the docs multiple times. When I tried event, the Studio Code Server Add-On said “Property event is not allowed.” and config verification failed with an error. Strangely enough, after reloading the KNX integration, the config verification succeeds. Studio Code Server still shows the same error even after restarting the whole OS. Anyways, it works.
I will stick with event instead of binary_sensor, will use no blueprints but check how to minimize my YAML code based on your suggestions.
Thanks for all your time and support. It wasn’t my intention to cause so much trouble.
Maybe the addon is not up to date.
If the actual config verification - the one ran by HA core on restart - fails with event then you are not on 2021.12 yet.
As said, I could not restart (via UI) because the config verification failed. So I assumed I am missing something or the docs are outdated. After reloading the KNX integration the verification worked and I could restart. Since then it works but VS Code still marks “event” as error. Never mind. All good. I am definitely on 2021.12.
My name is Dave and i’m an absolute HA beginner. Sorry for bumping this old topic. I was reading a lot the last days and tried even more but the more i read and try the more i get confused.
I’m trying to control a Zigbee thermostat via MDT Glastaster II. The thermostat is integrated to HA via zigbee2mqqt.
To start somewhere and to get an idea how things work i disabled the GT II 's internal temperature sensor and tried to send the thermostats target temperature to the bus using this code but i guess “attribute” is complete nonsense in this case?!
expose:
- type: temperature
entity_id: climate.heizung_buro
attribute: current_heating_setpoint/get
address: "1/3/1"
In the thermostat’s documentation i read
To read send a message to zigbee2mqtt/FRIENDLY_NAME/get with payload {"current_heating_setpoint": ""}
How do i send a message to zigbee2mqtt/climate.heizung_buro/get and ho do i use payload?
I hope someone can give me a hint to the right direction.
Now, however, I am also trying to make it louder/quieter. This I would solve via an automation, as already described above. Unfortunately, I can not control the volume. Do I have to create the individual KNX addresses in the Configuration.yaml?
With the commenting I meant if there is a way not to comment every single line with a #.
Above in my code I have some lines which follow together always have to comment with a #.
in C & C+ there is for example the possibility to make a mass comment with /* = start and */= end.
Ah, now I get it. Was confused by the C syntax
Yaml doesn’t support block comments.
Most editors support “commenting out selected lines” - on VSCode in macOS that would be Shift Cmd 7.