Change brightness from 0-255 to 0-100

I use the following setup to control a light that takes REST-commands as input:

rest_command:
  set_brightness:
    url: 'http://192.168.1.12/dev/sps/io/Skap_led_v/{{ brightness }}'
    method: POST


- platform: template
  lights:
    led_lights:
      friendly_name: "Theater Lights"
      turn_on:
          service: rest_command.set_brightness
          data_template:
            brightness: 100
      turn_off:
          service: rest_command.set_brightness
          data_template:
            brightness: 0
      set_level:
        service: rest_command.set_brightness
        data_template:
            brightness: "{{ brightness }}"

It works, but controlling the light sends 0-255 (255 is 100% brightness), but the light needs 0-100 as input. I tried to do the following int he last part:

brightness: "{{ brightness / 255 *100}}
brightness: "{{ brightness // 2.55}}
and brightness_pct: "{{ brightness }}

But neither of those seem to do the trick. Any suggestions on how to do this?

does this help you ?

{{ '%02.f'%((states('input_number.dimmer1') | float / 255 ) * 100) }}

1 Like

used it somewhere in a script/shell command

I tried exchanging the last part for

brightness: “{{ ((brightness | float / 255 ) * 100) }}”

That seems to do the trick, thanks.

np

glad its working :slight_smile: