The template light now controls the plinth lights. Turns on/off the lights and adjust the brightness.
However I still have a problem
The scale is 0 to 255 so changed this in the template formula but the template light adjusts the plinth light to the same brightness and does not seem to use the formula.
So the setup is that âKitchen plinth lightsâ is the entity visible in the frontend and what the user is in control of for turning on, off and dimming.
In the background there is an entity called âplinth lightsâ (generated from esphome). User has no access to this in the frontend.
so user adjusts âkitchen plinth lightsâ and HA passes the modified brightness levels and on/off state to âplinth lightsâ which controls the esphome dimmer.
This might be confusing, because you will be getting conflicting advice from me and @tom_l. But I think this is the correct code for brightness in your template light:
brightness: "{{ (0.698 * (brightness-255)) +255 | int }}"
This will map the range 0-255 to 77-255 (77 is 30% of 255).
Iâm not sure about your value_template. Perhaps you also need to adjust the range, but I am not sure. If it doesnât work properly right now, you might try:
This will map 77-255 to 0-255, so the other way around.
I donât have time to try this in my own setup right now. Perhaps @tom_l can lend a hand as well. Especially since we seem to have conflicting opinions about the right solution
Wouldnât be the first time I was wrong. Just double checked my calcs, not sure how I came up with the previous result, but the linear equation is actually:
Y = 0.7*Brigt +77
x=0 â y=77 (30.2% of 255)
x=255 â y=255.5
Yours is close but it gives 81 out for 0 in (32% of 255). As I said pretty close.
Should do it except for this problem I pointed out earlier:
Which is why you are seeing:
Say you start with a brightness of 77. The equation will set it to 0. Now your brightness is zero for the next time you go to change it but the minimum it ever should be is 77.
You need to separate the brightness attribute from the light slider. Not something that is possible if using the core light card.
The calculation, they might be a bit different but thatâs okay. I donât get why you are using the state attribute for brightness in the set_level part? It should be {{brightness}} in my opinion.
Iâm trying to replicate the above but I seems to be unable so. In principle I want to achieve the same. I have a light that only works between 48% and 100% of the brightness and therefore I want to create a template that remaps this range from 0 to 100%.
The template now looks as the below and as a result every brightness change in the template results in the light to be set to 30%. Brightness up/down does not alter the the original value unless this was not 30%. Also change the state.attribute to brightness throws me an error.
You need more parentheses I believe. ) before |int. Right now you are only converting 255 to integer. Not the whole calculation. Looking back, my example is incorrect