KNX Button with template value

Hello,

TL;DR: I can’t set a value for a knx button to a state of an entity using a template. Is this not possible or am I doing it wrong?

Details:
I have a set of MDT Glastaster to which I want to send a string via the ‘state text’ communication object on the press of a button. Everything works fine, if I hardcode a string in the knx button.

knx:
  button:
    - name: Glastaster Status 1
      address: "0/2/15"
      type: string
      value: "Hallo Welt!"

But I would like to set the value to the state of a input_text

input_text:
  knx_glastaster_status_text:
    name: Glastaster Status Text
    icon: mdi:message-text-outline
    initial: ""
    max: 14

knx:
  button:
    - name: Glastaster Status 1
      address: "0/2/15"
      type: string
      value: {{ states('input_text.knx_glastaster_status_text') }}

But on checking the config it shows this error:

Error loading /config/configuration.yaml: invalid key: "OrderedDict([("states('input_text.knx_glastaster_status_text')", None)])"

I’m relativly new to templating. So I checked the template {{ states('input_text.knx_glastaster_status_text') }} in Developer Tools → Template and there it works fine.

Therefore I have the question: Are templates even supported as a value for a knx button?

No, templates are not supported here.
Use a HA script or template Button with knx.send service instead.

1 Like

Sadly this still gives me the same error.
My bad. I missed the quotation marks around the "{{ states('input_text.knx_glastaster_status_text') }}".
Now it works.

input_text:
  knx_glastaster_status_text:
    name: KNX Glastaster Status Text
    icon: mdi:message-text-outline
    initial: ""
    max: 14

input_button:
  knx_glastaster_status1:
    name: KNX Glastaster Status 1
    icon: mdi:message-arrow-right-outline

automation SendMsg1:
  alias: "KNX Glastaster Status 1"
  id: b729d108-bfd8-4d0d-8f6b-8989ca669bf7
  trigger:
    - platform: state
      entity_id: input_button.knx_glastaster_status1
  action:
    - service: knx.send
      data:
        address: 0/2/15
        type: string
        payload: "{{ states('input_text.knx_glastaster_status_text') }}"

So I tried creating the automation using the UI. It won’t give me an error, but

payload: {{ states('input_text.knx_glastaster_status_text') }}

gets replaced by

payload:
  '[object Object]':

automaticly in the automations.yaml. No warning or error shown, but needless to say: It still does not work.

1 Like