If it is a single line value (not multiline string, with > or |) then starting with { has a special meaning. It starts a dictionary. That is not what you want here. So you need to make it a string first, before you can start the template. That is why it needs the quotes.
Yes, if put in the respective places. But either norm or keuze is currently undefined. As norm looks fine, is states(‘sensor.speedtest_download’) returning the right value in the developer tools template tester?
You can write ‘{{ iif(keuze|int(0) > norm|int(0), ‘ok’, ‘nok’) }} to make the default 0.
Also, just found info about “iif”:
Syntax: iif(condition, if_true, if_false, if_none), looks like the if_none-part is missing in your code, I think that might be the reason for the ERROR.
The defaults will hide the fact that the value you need isn’t there, so you should definitely look why it is unavailable and if that is really the case before you start protecting against unavailbility.
keuze: “{{ states(‘sensor.speedtest_download’) | int | int(default=‘0’) }}”
norm: 600
mode: “{{ iif(keuze | int > norm, ‘ok’, ‘nok’) }}”
Problem is (thanks edwin_d) that the speedtest integration isnt always stable, so the sensor value is not there…
In that case there isnt a value for the sensor.
I do a reload for this integration and that solves the other problem…
I doubt it is solved. Here you convert to int twice, but only the second time you have a default. Once is enough, but it must have a default. Also, your default is a string, which is weird if you wanted an int This should be enough:
Oh, sorrt. It seems like IOS did it’s nasty trick again to change normal quotes into beautiful, but non working curly quotes. You need the straight, real quotes for it to work. I have it set to off in the keyboard settings, so I do not know how and why it was activated anyway. I edited them back (click on the pen above to see the subtle, but deadly difference).
The “oud” lines will still give you errors though.
@pvklink If you don’t format your code properly with the </> button, you’re going to keep finding errors with quotes even without iOS trying to to us all up.