Knx.send problem - button card

Hello,

I want to create a button card with following function:

If I click on the button I want to check if a light is turned on and then send 1 to a group address on the knx bus. I’m a beginner and I don’t know how to do this.
I created a template but i doesn’t work:

switch:
  - platform: template
    switches:
      kuche_bwm1.lock:
        value_template: "{% is_state('light.kuche_deckenspots', 'on') %}"
        turn_on:
          domain: knx
          service: send
          service Data: { "address": "2/4/20", "payload": 1, "type": "switch" }
          device_id: kuche_bwm1.lock
        turn_off:
          domain: knx
          service: send
          service Data: { "address": "2/4/20", "payload": 1, "type": "switch" }
          device_id: kuche_bwm1.lock

Can somebody help me please…
Thanks a lot!!

Hi :wave:!

It seems you are trying to do the same thing, regardless if the switch is turned ON or OFF. If so consider just using a button (a knx button just sends your payload on press - stateless).

The thing you apparently copied from the documentation is not the correct service notation, but just a documentation schema for services. See the examples or service documentation for the correct notation. Here is an example:

service: knx.send
data:
  address: 1/1/0
  payload: 1

Here you can try these things and even fill the yaml text-field with more-or-less usefull example data: Open your Home Assistant instance and show your service developer tools.

There is no type: switch. If you want to knx.send binary data (DPT1) just send a numeric payload of 0 or 1 without type.

Maybe I phrased something wrong. Actually, I don’t want a switch, just a button that I can press.
If I press it sends a value to the KNX bus (to a group address) based on the state of a switch… in this case 1
Can you give me a little example? I’m a beginner and if I can see an example it would help me very much to understand it better.

Then just use a KNX button. You’ll find examples in the docs.

Can I do it this way?

knx:
  button:
    - name: "DPT 1 - True button"
      address: "2/4/20"
      {% if states.light.kuche_deckenspots.state == 'off' %} 
        payload: 1
      {% else %} 
        payload: 0
      {% endif %}

I need a IF-Query inside… so if light.kuche_deckenspots is on send 1 to address: "2/4/20"

I don’t know how to do this?

No, a Knx button entity always sends the same payload. Templates can’t be used there.

Is light.kuechenspots a Knx entity? Then you could maybe use its GA as state of an Knx Switch and the address you want to send to as address - not sure if this works, you’ll have to try.

Otherwise create a HA script. This will look like a button (or HA scene) in Lovelace and you can use services (knx.send) and templates there.

Or create a template button (documentation for this seems quite sparse unfortunately).