Display brifhtness as a value between 1-100

when i look at a light entity’s properties for brightness, i get a number between 1-255.
how do i convert that into a percentage for easier display between 1-100?

state_attr('light.backlights_wleds_hyperion','brightness'

I made this template to extract the number from the entity’s properties, and if i could divide it by 255 and multiply it by 100 ill get the right percentage, but how do i do that within the code to get it to display the “new” number?

the other way thought about is to create a number helper with 1-100 range, and display it’s properties instead, but how do i tie it to the light entity i wish to extract the brightens level from?

let me better explain the purpose…
I use a matrix led panel to display different values from various sensors, time etc. at night, when i use a dimmer switch-button to dim the lights, i find it to be useful to have some form of a “number” to represent the brightness for better control. as mentioned, now, i have the brightness display as a number between 1-255, and i want it to represent percentages instead.

there must be some easier way i’m overlooking…
let me know
cheers

Try this in your template:-

{{state_attr(‘light.changethis’,‘brightness’)|float(0)*100//255}}

That will give you the percentage rounded to a whole number.

EDIT, given you multiply first, you dont actually need a float, you could use an int instead

{{state_attr(‘light.changethis’,‘brightness’)|int(0)*100//255}}

my man (or woman)!
things r so easy when you have a clue… (or access to a community that does…!)

thanks
soon ill be laying in bed dimming my @ss-off, checking my led matrix…
:smiling_face_with_three_hearts:

Although your device is only reporting brightness in the range 0-255, you can actually control it in an automation using brightness_pct which is 0-100. Just something to think about.

correct, but i wanted my matrix to display the brightness regardless of an automation to run it to a specific brightness value.
i use zha button remotes to dim up and down, and your solution works perfect for my needs

Couldn’t you just use

state_attr('light.backlights_wleds_hyperion','brightness_pct')

As Rofo says ?

1 Like

hi @Holdestmade
what you quoted was closer to my original attempt not @Rofo suggestion (at list to my understanding, and if i get your question correctly).
as i said, that works but brings out a number between 1-255, and i wanted a 1-100% range result.
at 50% brightness these will be the outputs:
{{state_attr('light.changethis’,'brightness')}} = 127.5
{{state_attr('light.changethis’,'brightness_pct')}} = the added _pct = give my a none output
{{state_attr(‘light.changethis’,‘brightness’)|float(0)*100//255}} = 50.0
{{state_attr(‘light.changethis’,‘brightness’)|int(1)*100//255}} = 50 (without the decimal point)

and thank again to @Rofo for coming up with the solution i wanted
hope that clarifies it better.

That is strange, it doesn’t work for me either, pretty sure there used to be an attribute brightness_pct