I have a setup with multiple KNX room thermostats and correspondingly electrical heaters attached to Shelly switches. Thermostats each send a binary object to control heating, thus I created automations to switch on and off respective Shellys, with e. g. triggers
condition: state
entity_id: binary_sensor.knx_interface_7
state:
- "on"
This works nicely to switch on the respective heater. Unfortunately, the other way with state == off is never executed, thus I’d like to understand how to create a proper trigger to switch off again.
Furthermore, since I have a bunch of heaters / thermostats, it would be great to kind of transfer the status of the KNX binary object onto the respective switch, without creating individual on / off automations. I strongly assume this works with templates / scripts, but so far no clue on how to tackle this.
thanks for the explanation. Overall I got the idea to use the (Jinja) templates. But I have problems to understand the details, which code I need to include in the state box of the binary sensor template, assuming my (simplified) automation so far looks like this:
Can you give me few more hints what the template should look like in this case?
Furthermore I’m not sure if the template should include the KNX trigger at all or if I should rather have a single heating automation catching the respective KNX group trigger and subsequently executing a bunch of template to just map known conditions to specific actions?
Initially I tried to trigger right on the binary state change of the KNX entity, but this didn’t work. Hence I’m now triggering with the KNX entity itself and afterwards evaluating the state of entity, with separate rules for on and off. Now I “templated” the action part like this, but likely made a mistake, since the Shelly output doesn’t change.
actions:
- action: |
{% if binary_sensor.heizung_buro_eg %}
switch.heizung_buro_eg.turn_on
{% else %}
switch.heizung_buro_eg.turn_off
{% endif %}
mode: single
Assuming I would include multiple templates for the different mapping, I also need to replace / change the “mode: single”, or?
Ok, what I understand from automation actions I should do it like this, but it still doesn’t change the relay state. What is still missing / incorrect there?
This doesn’t check or compare the state of that entity id.
You’ll probably want states("binary_sensor...") == "on" or something. Try it in developer tools.
Or use two triggers and assign each a different trigger id. Then use a choose block to branch out for on / off. You wouldn’t need templates that way.
Thanks a lot! After all it’s working nicely also with multiple actions to a single KNX trigger. I think this is the more convenient way, since I just need to copy & past respective templates now.