# MQTT Light brightness scale percentage mapping

Hello, I just added some MQTT lights with `brightness_scale: 100`. Then I added a card in Lovelace for this light.
When choosing 1 percent in Lovelace, `brightness: 0` is sent to MQTT, and the mapping looks wrong for the entire scale:
1% = 0

50% = 49

99% = 98
100% = 100

Is this a bug? In that case, a known bug? If not, how should I proceed?

Do you really notice a 1% difference in brightness?

Looks like someone has truncated rather than used rounding when doing the conversion to an integer for percent.

The light card is sending in the percent straight to light.turn_on. That is making it here in mqtt light

``````       if (
ATTR_BRIGHTNESS in kwargs
and self._topic[CONF_BRIGHTNESS_COMMAND_TOPIC] is not None
):
percent_bright = float(kwargs[ATTR_BRIGHTNESS]) / 255
brightness_scale = self._config[CONF_BRIGHTNESS_SCALE]
device_brightness = min(
round(percent_bright * brightness_scale), brightness_scale
)
``````

So, 1/255 = 0.0039 * 100 = 0.39 --> rounded to 0. The light card isn’t using the light custom scale. It is using the default 0-255 value.

1 Like

@tom_l: The point here isn’t if I notice a 1% percent difference. It’s that when I choose 1% in Lovelace light card, 0 gets sent over MQTT.

@jocnnor: It looks like it takes ATTR_BRIGHTNESS and divides by 255? Do you mean it takes 1% directly from the light card? Or 1% of 255? I understand that the scale doesn’t map very well when using 1 (as in 1 of 255), but 1% should be `2.55: 2.55/255 = 0.01 * 100 = 1`.
1% or 2.55 should be sent to MQTT function from the Light card, IMO.

It’s converting your 0-100% to 0-255 (integer, no unit).

So if you want to avoid rounding errors use `brightness:` <0-255> instead of `brightness_pct:` <0-100>

It sends the % value directly from the light card. If you dial 1%, that is sent to home assistant and forwarded to the MQTT Light entity where it finally knows about the new scale and gets scaled to the actual value. The light card doesn’t know or care about the custom scale for sending values. So in this case, 1% gets rounded to 0% because of the new scale.

It’s NOT sending 1% of 255. Just 1%.

Ok, then I will change my solution to use 0-255 instead of 0-100. I can control the conversion in that end instead

1% is the treshhold most dimmers wont go under.

I have a Shelly dimmer for example and through the app I cannot dim the light to 0% (so basically turning it off). That is not how dimmers are supposed to be used.