KNX Expose support template

A lot of times when exposing an attribute to KNX, conversions or calculations need to be done to send data to bus. Can we add support for using templates for values/data to be pushed. I wouldn’t mind trying to code the same, but I have never done any coding on this codebase, so if someone can mentor me would be great to contribute as well.

For example,
to expose Home Assistant Climate Status to KNX I need to use below binary template sensor:
{% if is_state('climate.xxx_device_id_xxx', 'off') %}4{% else %}1{% endif %}

Hi :wave:!

I think it would be a great feature.

I wanted to implement this myself some time ago and started with sensors to accept value_template. Since this was not accepted I refrain from doing the same for expose. Maybe things are different now, or maybe it would be accepted for expose after all, I don’t know.
See KNX sensor value_template by farmio · Pull Request #47734 · home-assistant/core · GitHub

Some things to consider: If you have a template refering to some other entitys state or something, I guess this would have to change (extend) the trigger for that expose-function.

Feel free to join our xknx discord server to talk about the KNX integration and its driver or ask on HAs discord for more general (non-Knx) advice.

If you are looking for a workaround for your specific problem: just use an automaiton with the knx.send service instead of expose. It will happily let you branch out different payloads.

1 Like

Thank you quick and precise reply. Perhaps I will try creation a blueprint/automation to avoid using shell entities.

Also wanted to add that knx integration works great and thank you for your contribution. I will start with HAs discord to understand basics first and then hopefully join xknx if i am able to get a hang of the basics.

1 Like