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
I pieced together the bits of configs mentioned above for an ESPHome Tuya dimmer with min/max of 15%/100%, and it mostly worked. However the dimmer value of the template light didn’t update in Home Assistant when I adjusted the dimmer level on the device itself. So I needed to add a reverse mapping in level_template (which was suggested before, but for value_template, which I think is a typo?). Anyway, here’s a full working config:
I’m wondering how to get the remapping working with an RGBWW light-component. I’m using a Texas Instrument TLC59208F Output component for controlling LED-strip. The nature of this 94Khz PWM signal causes non-linearity. Below 15% brightess is basically lights off.
I tried to add examples to output and light component but ESPHome complains about non-existing type. Do I need to configure 5 of these template outputs because using RBGWW? Where to find properties like “value_template” and “level_template”. Can’t find in search. Help is appreciated!
[EDIT]
Larger snippet with context of platform:output would be helpful.
I think a feature request would be a good thing. I can image how many are out there that want light brightness scale remapping.
I managed through automations to deal with low brightness levels, which the LED lamps still easily handles once they are turned on, by shortly putting the lamps at their threshold level they need to actually get going and light up, and set them back to the previous lower level using a scene.create service.
But with automations it is not possible to limit the scale on te low end in a good manner, because once you set the light below the low threshold at which it actually will turn off, the automation that would prevent this is too late.
Some feature request about this subject that I had found:
You can define min_power: 30% in the output component to remap the brightness range of light between 30-100%. Home Assistant frontend will consider 30% as 0%. This can be achieved when using a RobotDyn AC dimmer.
here’s my ESPHome monochromatic light dimmer configuration:
I was looking for the same thing, meaning I wanted to scale my LED lamp because it starts at 22% DC. So I found this thread.
And yes, one might use home assistant template sensors but I’d rather have it done in the ESP32. I think the hint of @koencomposer is very helpful and showed me the way to go:
I was facing a similar issue with a 0-10v dimmer where the light would turn off at 22%. I tried using templates but then I discovered the HA HACS integrations lightener. Releases · fredck/lightener (github.com). It’s all done via the GUI. I set the Brightnes mapping as such.