### EXAMPLE 1 ###
- platform: template
sensors:
dimmer_level_1:
friendly_name: "Dimmer Level_1"
value_template: >-
{% if is_state( "light.esp32_dimming_1", "on" ) %}
{{ "%2d" | format( states.light.esp32_dimming_1.attributes.brightness | float / 2.55 ) }}%
{% else %}
Off
{% endif %}
### EXAMPLE 2 ###
- platform: template
sensors:
dimmer_level_1:
friendly_name: "Dimmer Level_1"
value_template: >-
{% if is_state( "light.esp32_dimming_1", "on" ) %}
{{ "%2d" | format( states.light.esp32_dimming_1.attributes.brightness | float / 2.55 + 1 ) }}%
{% else %}
Off
{% endif %}
I am using this sensor to display the brightness percentage in the Frontend.
THE PROBLEM: Use example 1 when the light is at 100% the sensor correctly shows 100%. Anything lower and it’s off by 1. If i set the light to 95% it shows 94%, set it to 80% it shows 79%.
Use example 2, then everything shows up correct, except when the light is at 100%, then it shows 101%.
I have zero to minimal coding skills and put the above code together by copying and pasting things I found in this forum. Is there a way to make it so everything shows correct?
Thanks for any help anyone can give.