Brightness in toggle and entity differ

I got a Shelly Dimmer 2 that I wrote some automation for to increase the brightness when my TV turns off, and it’s not already above a certain brightness.

alias: Nach Ausschalten von Shield Licht Couch auf 3% setzen
description: ""
triggers:
  - type: turned_off
    device_id: 2c604168eacd9f7d402cbbc62be15a27
    entity_id: 81c94c492e3f7faface655e3bcbf257c
    domain: remote
    trigger: device
conditions:
  - condition: numeric_state
    entity_id: light.licht_couch
    attribute: brightness
    below: 2
actions:
  - type: turn_on
    device_id: c9d902cf185e86540f2f90b08fafddfc
    entity_id: f9d040b10bdb9255352308a4355ec6d8
    domain: light
    brightness_pct: 3
mode: single

The automation works fine, except for the brightness condition. I assumed that the brightness attribute of the entity would be equal to what is shown in the toggle button in the dashboard. For example, this is the toggle for that entity when it is on and set to 20%. As you can see in the settings of that toggle button, it belongs to that entity. But in the developer tools, the brightness value of that entity is completely different (51):

I am very confused by this and must be gettings something completely wrong. Where are the brightness values of that entity coming from, how can I reference the value that I as a simple user can see in the UI of the dashboard button, and how am I supposed to discover this myself?

Brightness is going to be on a scale of 0-255, not based off a percentage.

The 0-255 scale is associated with RGB as well as Brightness or intensity of the color/light

Makes sense. But, still, the discrepancy between the value in the dashboard (0-100) and the property value (0-255) is very confusing to me. Is there a way to achieve my goal of setting the brightness to a value between 0 and 100 without manually converting the value?

The dashboard is converting the brightness from 0-255 to a scale of 0-100% for you.

Your question is slighty confusing. The automation code you posted is setting the brightness by percentage, but the condition is on a scale of 0-255 for the attribute.

From my understanding the percentage isn’t available via the UI for conditions, only for action

The Brightness attribute is what it is. A template or conversion is needed from my perspective.

You can’t change what attributes are available on the entity; that’s up to the integration. If you want to use the percent value in a condition without having to do the math yourself, you could create a template sensor using a template like this:

{{ (state_attr('light.licht_couch','brightness') * 100 / 255) | round(0) }}

You may see log errors if you don’t define the default with round

{{ (state_attr('light.licht_couch','brightness') * 100 / 255) |round(0, default=0) }}

Sorry, my mistake. Of course, I wanted to ask about how to check the brightness of that entity in percent. Obviously, setting that value in percent is possible, as shown in my automation. And my wish would be to have the percentage available as well in the automation UI (and YAML), which would make it more intuitive.

Thanks everyone for the clarifications and help!

1 Like