First off…not a programmer, lol. Ive only made a couple basic sensors as well so very new to this.
Trying to get a template setup to convert dimmer power level to wattage. I know this isnt the best way without an actual energy meter device but its what im working with at the moment unitl i decide on an appropriate hardware device for true monitoring/calcs. Not so simple for 240v 2-phase apparently.
I verified the energy usage at each dimmer percentage using a watt meter so i should be in the ball park which is all that really matters for what im going to use this for. I have esphome locked to 5% steps.
This basically works as is right but is not handling the situation where the dimmer is in an off state and i just cant seem to wedge a test for that in my mess. Im sure this is spaghetti mess but gotta start somewhere Open to a much more elegant way to do this …lm all ears.
Could someone throw me hand in wedging in a test for when the dimmer is off?
code:
{% set powerlevel = (state_attr('light.leddriver', 'brightness') / 255 * 100 | round(0) )| float(0) %}
{% if is_number(powerlevel) and powerlevel | float >= 90 %}
880
{% elif is_number(powerlevel) and powerlevel | float >= 85 %}
820
{% elif is_number(powerlevel) and powerlevel | float >= 80 %}
745
{% elif is_number(powerlevel) and powerlevel | float >= 75 %}
680
{% elif is_number(powerlevel) and powerlevel | float >= 70 %}
613
{% elif is_number(powerlevel) and powerlevel | float >= 65 %}
559
{% elif is_number(powerlevel) and powerlevel | float >= 60 %}
500
{% elif is_number(powerlevel) and powerlevel | float >= 55 %}
447
{% elif is_number(powerlevel) and powerlevel | float >= 50 %}
399
{% elif is_number(powerlevel) and powerlevel | float >= 45 %}
349
{% elif is_number(powerlevel) and powerlevel | float >= 40 %}
302
{% elif is_number(powerlevel) and powerlevel | float >= 35 %}
250
{% elif is_number(powerlevel) and powerlevel | float >= 30 %}
205
{% elif is_number(powerlevel) and powerlevel | float >= 25 %}
168
{% elif is_number(powerlevel) and powerlevel | float >= 20 %}
128
{% elif is_number(powerlevel) and powerlevel | float >= 15 %}
90.5
{% elif is_number(powerlevel) and powerlevel | float < 11 %}
0
{% endif %}