Light template base on brightness

Hi
I have a question about lights and knx. at this moment I have at my home a knx -> dmx gateway.
each channel has a configuration of response type (1 bit / 1 byte).
in KNX:

  • 0/0/49 -> turn on / off channel
  • 0/0/50 -> absolute dimming
  • 0/0/51 -> Response state

the thing is when I have a configuration to get response as 1 bit and in HA like this:

- name: EntityName
  address: "0/0/49"
  state_address: "0/0/51"
  brightness_address: "0/0/50"
  brightness_state_address: "0/0/50"

then all is working fine. HA set the on / off and show the percent of brightness, all is ok on this side.
But in the case of the KNX buttons that show You brightness of channel etc, it is broken. the light can be off and the knx info show me the value of x%

in the case when I set the response type to 1 byte in KNX and HA config is

- name: EntityName
  address: "0/0/49"
  state_address: "0/0/49"
  brightness_address: "0/0/50"
  brightness_state_address: "0/0/51"

then in KNX buttons all is ok, I see the value of brightness, when light is off then I see 0%
but in this case of HA I see that the light is off and brightness is 0.
when for example the light is on with 50% of brightness (set from knx device) and in HA it shows that is off after click I see the correct value of brightness etc.

if I remove from HA info about state_address nothing is changed.

my question is has anybody an idea how can I solve the problem to have valid info on both sides? I want to let the response type in KNX on 1-byte value. But how can I solve it in HA?
is possible to make it with the light template?
I try to make it in this way but it is not working

light:
  - platform: template
    lights:
      testLight:
        friendly_name: "dmx light"
        value_template: "{{ states.sensor.ENTITYID.brightness|int > 0 }}"
        turn_on:
          service: light.turn_on
          entity_id: light.ENTITYID
        turn_off:
          service: light.turn_off
          entity_id: light.ENTITYID

value_template is for determining the state of the light. What you have said is “the light is on if the brightness is > 0”. And in this case, as you’ve said, the brightness is ALWAYS set, whether it’s on or off!

You need to define the level_template.

level_template: "{{ 0 if is_state('light.ENTITY_ID', 'off') else state_attr('light.ENTITY_ID', 'brightness') }}"

This says "if the light is off, just report 0 for the brightness. Else, report the actual brightness.

i have question if in developer tools, templates i have something like this
{{state_attr(‘light.podworko_podjazd’,‘brishtness’)}}
and the response type in knx is set to byte

after changing value direct in knx (not from HA) i see no value (“None”) then the solution from joconnor will not work or I’m wrong?

i try to test it in all (I think so) possible ways but with this same result. can anybody confirm this?

Yeah, you’ll have to convert that value to one between 0-255. I assumed it was already in that format.

level_template: >
  {% if is_state('light.podworko_podjazd', 'off') %}
    0
  {% else %}
    {% set raw = state_attr('light.podworko_podjazd','brishtness') %}
       ... insert code to convert payload to a number between 0-255 ...
  {% endif %}

I don’t know what the value looks like. If you can’t figure it out, post what the current brightness reports and I’ll convert it for you.