Thank you for your fast answer. But somehow I don’t get it to work. I’ve changed the code to what you suggested. But first, I get an error with the '. So tried it without ’ and with ". Both with no succes.
This is my code now, any pointers are more then welcome!
And check gives this:
Error loading /config/configuration.yaml: while parsing a block mapping
in “/config/sensor.yaml”, line 50, column 9
expected , but found ‘’
in “/config/sensor.yaml”, line 50, column 39
Yeah you have to be careful when you have quotes inside and outside your template. You end up with pairs of quotes like this if you don’t use single and double quotes:
The specs changed silently. Before, you were allowed to pipe with min / max. You are not anymore, and all templates with the very frequently used notation will just break. Example of what you could do before:
some_variable: some_other_variable * 1.5 | min(100)
meaning it will take some_other_variable, multiply with 1.5, but not allow it to go above 100.
Now you have to add even more parentheses and brackets and confusion, making typical templates start with {{((((
it is the min(100) part that breaks, as min (from now on) requires the argument to be an array to iterate through and pick the smallest value. And 100 is not an array, so it cannot iterate over that “int” thus the error printed that “int is not iterable” or similar.
Cannot do my_value | min(100) | max(1) to clamp a value between 1 and 100. You need to max([min([my_value, 100]),1])
Thank you for this! It solved my issue. I believe your closing brackets are wrong, though (first reversed, second too many). Took me a sec to see it and correct it to make it work.
In case it’s useful to someone, I wanted to convert a lux meter that ranges 10-10000 to a brightness 1-100%, by dividing by 100 (simple for now) but keeping it between 1 and 100 %. My end result was:
which is surprising it actually worked as the syntax is invalid in the world of Jinja. What you’re really doing is
{{ min(x, y) }}
without realizing it. Min or max always requires an iterator for the argument.
It only worked because home assistant wasn’t using the normal min/max function built into jinja. It was using pythons, which is more forgiving but you can end up with odd results if you don’t understand the syntax.
So then, what was possible before IS NOT possible anymore. Something changed.
{{ x | min(y) }} did work before, and is much more like how other things are working. E.g.
{{ x | int }} or {{ x | int(1) }} so why not {{ x | min(1) }} I’m not stupid, and I am a developer, so i see the difference; but we did in fact have breaking updates that broke most templates and it wasn’t preceded with deprecation warnings that is usually what one would do before removing functionality. Even if the functionality didn’t officially exist before, it did in fact work and was used frequently by most. So removing it was a breaking change.
First question - do I have the first part correct? Second question - what do I need to correct the array? I read something about setting a default and/or min max.
Please take the time to format your code and post it as text. People do not want to rewrite your entire configuration by looking at an image.
As for your issue, the image 1 seems to be fine but if you put it in the wrong spot, it won’t work. My guess is you’re incorrectly adding the first image to the template section.
Your second image is a combination of the old configuration and the new configuration. You have to use the new config or the old config, not a mixture of both.
It seems to be working fine but what alerted it to me was this error in the logs:
* Template warning: 'float' got invalid input 'unavailable' when rendering template '{{ states('sensor.freezer_sensor_temperature')|float > 25 }}' but no default was specified. Currently 'float' will return '0', however this template will fail to render in Home Assistant core 2022.1