Rest Command brightness to build a template light

Hi, I’m trying to get my then expensive Luke Roberts lamp into HA, the only way is via the Rest Api, otherwise communication only works via BLE via app.
A Rest Switch with on off already works. Now I am facing the problem with the brightness, if I set the command in the payload with
payload: '{"brightness": "80"}' in the Rest command directly, the call works in the developer settings. However, since the goal is to ultimately create a light template, I need a functioning payload where I can specify the value separately.
I have tried different things payload: '{"brightness": {{ brightness }}}' doesn’t work after I read the tip.

 luke_dimming:  
    url: https://cloud.luke-roberts.com/api/v1/lamps/by_serial_number/1901ZH/command
    method: put
    headers:
      authorization: "Bearer XXXXXXXXX"
      accept: "application/json"
    payload: '{"brightness": "80"}'
    content_type: 'application/json'

does anyone have any ideas? thank you very much

Did you try

payload: '{"brightness": "{{ brightness }}" }'

That assumes you actually pass a brightness variable, ofc

thank you @koying for your help, unfortunately I am now at a point where I do not know if it works or not, I have entered a value of 10 in the developer settings as shown in the picture, but unfortunately nothing happens. In the logs I could not see anything wrong with the payload.Hm, the lamp is documented via Swagger API, there you have to specify as payload as an example ````{ “brightness”: 75, “relative”: false } ``` as an addition, why I do not know.
in the sparse API PDF I only find the following:

Supported payloads
On/Off
{“power”: “OFF”}
{“power”: “ON”}
Brightness (0…100 %)
{“brightness”: 42}
Color Temperature (2700…4000 K)
{“kelvin”: 3700}
Select Scene (0…31)
Screenshot 2024-02-07 190744

Strange data.

I would expect

service: rest_command.luke_dimmen
data:
  brightness: 10

You give both payloads where brightness is between double-quotes and not.
I not needed, try (notice the blank between the 3 “}”)

payload: '{"brightness": {{ brightness }} }'

thanks @koying that was the trick. sorry for the late response but my son had an operation.
Now I have created an input helper with which the light dimming works perfectly, unfortunately it does not seem to work in the UI. There the lamp in the UI has the really full brightness at about 50 percent. Below 50 percent and above 50 percent the light is very dimmed. Ok I thought this was due to the 255 value that Home Assistant gives out, I have installed the following but it still doesn’t seem to work.What can i do now? Thanks alot

  - platform: template
    lights:
      dein_rest_licht:
        friendly_name: "lukewz"
        turn_on:
          service: rest_command.luke_dimmen
          data_template:
            brightness: 100
        turn_off:
          service: rest_command.luke_dimmen
          data:
            brightness: 0  
        set_level:
          service: rest_command.luke_dimmen
          data_template:
            brightness: "{{ (brightness | float / 100 * 255) }}"  

Brightness is given 0-255, so you need

brightness: "{{ (brightness | float(128) / 255.0 * 100.0) | int(50) }}"  

to transform into percent.

1 Like