I have a template light, the following code works fine. With the exception that i cannot get the feedback of the actual light value. Is it not possible to set up the “value_template” as a sensor directly as i have done here? And if no, what should i do different?
Thanks, that works, but i got another weird problem, the underlying code now works, with the exeption that the sensor returns 100 as max light, so the “level_template” doesn’t show the right level.
There is no configuration directly, it is a sensor generated by a custom component, it returns the light level from 0-100, it at the moment returns “98.8”
Hmm, how can i check? If i write {{states.sensor.lx_trappelys.state|int}} it seems to work (except that it jumps to the wrong value, it show about 1/3 of full of the light is on 100%), but it might be the int-part making the string into a number?
You said the sensor is produced by a custom component so I would check the component’s code.
Or just assume it is a string and convert it to a number using int (integer numbers) or float (floating point numbers).
That may be due to a miscalculation when converting between Home Assistant’s brightness range of 0-255, to the device’s range of 0-100. 100 is approximately 1/3 of 255.
Both return the expected results for me in the template editor. The value template work fine if i comment out the “level_template” if i keep it in, it doesn’t work. I am totally confused.
I think I’m out of ideas at this point. As far as I can see it should all be working with your “non-working” code.
the only other thing I see is that your indentation is off in the turn_on & turn_off sections. the stuff in those sections need moved back to the left a couple of spaces. And in the set_level section the brightness: needs moved two spaces left too. I’m not sure if that’s a copy/paste error tho since you said the other code is working and it looks the same. But it’s something to check tho.
You said sensor.lx_trappelys reports a value from 0 to 100. Your level_template multiplies it by 2.55 which produces a floating-point number. However Home Assistant’s brightness is an integer number between 0 and 255.
I was about to tell @123 that you already tried that but then I looked again at your non-working code and I think I just found your problem in the code.
You only have one ) at the end right after “float” in the level_template but none at the beginning -
Thanks to everyone, it was a combination of different things i think, the missing ) for one of the lines, and also the custom component suddenly stopped functioning sometime during the day without me noticing. It works now. I am very appreciative of all the help