KNX Switch/light custom payload data

Hi
I have an old KNX system with a tebis ts. I found out that i can switch off lights by adding a switch or a light but not turn on. In order to turn on i need to send payload [2, 12, 22, 32].


It works if i use the knx.send service then i can send it as an array, Is it possible to configure a switch or a light to send custom data for on/off. It only sends 0 or 1 now,
1 Like

This is really odd. How is this turned on by your knx wall switches?

You could create an HA automation that listens to the switch and triggers knx.send

yes by wall switches.
Automation How? Can you intercept the outgoing event and change the payload?
I tried to make a template switch to call knx.send. But the template switch resets to onto off by auto because it needs value_template. How can i make a switch that just calls knx.send and pass adress and payload. Input boolean? Or can i just change the default payload for the knx switch in som file?

switch:
  - platform: template
    switches:
      skylight:
        value_template: "{{ is_state('lights_living', 'on') }}"
        turn_on:
          service: knx.send
          data:
            address: "1/0/11"
            payload: [2, 12, 22, 32]
        turn_off:

          service: knx.send
          data:
            address: "1/0/11"
            payload: [0, 10, 20, 30]

I’d look into making 2 scripts, one to turn off and another to turn on.

Ive managed to create an automation, but it is possible to load the adress dynamicly from the light. Otherwise i have to create one automation per light

id: ‘1566215459582’
alias: knx
trigger:

  • entity_id: light.knx_light
    from: ‘off’
    platform: state
    to: ‘on’
    condition: []
    action:
  • data:
    address: 1/0/11 //can this be dynamic?
    payload:
    • 2
    • 12
    • 22
    • 32
      service: knx.send
  • id: ‘1566215459582’
    alias: knx
    trigger:
    • entity_id: light.knx_light
      from: ‘on’
      platform: state
      to: ‘off’
      condition: []
      action:
    • data:
      address: 1/0/11 //can this be dynamic?
      payload:
      • 0
      • 10
      • 20
      • 30
        service: knx.send

If you want to edit the knx implementation (eg. of light) for your needs:
Clone xknx and use it as a custom component
Replace the switch class in the light device with RemoteValueSensor with value_type ‘DPT-12’


and edit set_on() and set_off() to await self.switch.set(YourValueAsIntegerHere) and edit state().

Thanks, i think this is the way forward. Sorry but I dont quite follow, im new to this.
Should these be like this

async def set_on(self):
      """Switch light on."""
    await self.switch.set([2, 12, 22, 32])

  async def set_off(self):
      """Switch light off."""
      await self.switch.set([0, 10, 20, 30]) 

Can they be Arrays, you wrote integer?

Replace

self.switch = RemoteValueSwitch(
          xknx,
          group_address_switch,
          group_address_switch_state,
          device_name=self.name,
          after_update_cb=self.after_update)

with this?

 RemoteValueSensor="DPT-12"

What about state()?

Yes Int. DPT-12 will convert the raw bytes to int and vice versa - see xknx.knx.DPT4ByteUnsigned
[2, 12, 22, 32] -> 34742834
[0, 10, 20, 30] -> 1056816

The state will always be true because Python will evaluate eighter value as True -> bool(1056816) == True
so replace this with something like

if self.switch.value == 34742834: 
    return True
return False

thank you, i am probably slow but.
Should i remove this

self.switch = RemoteValueSwitch(
          xknx,
          group_address_switch,
          group_address_switch_state,
          device_name=self.name,
          after_update_cb=self.after_update)

and use this

 RemoteValueSensor="DPT-12"

async def set_on(self):
      """Switch light on."""
    await self.switch.set(34742834)

  async def set_off(self):
      """Switch light off."""
      await self.switch.set(1056816) 

  if self.switch.value == 34742834: 
    return True
return False

no this won’t work.

self.switch = RemoteValueSensor(
          xknx,
          group_address_switch,
          group_address_switch_state,
          sync_state=True,
          value_type="DPT-12",
          device_name=self.name,
          after_update_cb=self.after_update)

The if statement goes in the state function instead of return bool(self.switch.value)

1 Like

Thanks, now it works :slight_smile:
It is not updating the state of the light if i press the wall switch, i can se the knx event but i guess i have to live with that

I get an error when i use the wall switch. It seems like its trying to parse the message but fail i guess because the message is not standard knx. Do you know how to change so it can parse?

"2019-08-20 09:58:37 ERROR (MainThread) [xknx.log] Error while processing telegram <CouldNotParseTelegram description="payload invalid" device_name="Kontor höger taklampa" group_address="1/0/12" payload="<DPTArray value="[0x10]" />"/>"

Ive managed to create an automation, but it is possible to load the adress dynamicly from the light. Otherwise i have to create one automation per light

If you use scripts instead of automations you are able to pass on the address of a light as as variable :slight_smile:

How can I send data more than 6 bits (so, list) through template?
this doesn’t work, says it expected int

      data_template:
        address: "2/0/{{ trigger.to_state.name[-2:] }}"
        payload: "{{ [trigger.to_state.state | int] }}"
1 Like