The problem with regex_findall is that if it doesn’t find a match for its pattern, it fails with an error. Ideally it should return None or something to indicate “failed to find a match”. Basically, for this application, it works no better than split failing if the value has no comma.
Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information refer to guideline 21 in the FAQ.
I think a better method is to split on the space and replace the comma with dot to make it a float.
{{ state_attr('sensor.coinbase_eth_wallet', 'Balance in native currency').split(" ")[0].replace(",", ".") | int }}
This way it will not fail if there is no comma.
But it will fail if there is no space on the other hand, but since the currency is in the string that seems to be a sure thing.
If the currency is always EUR then the easiest is perhaps to remove EUR and replace the comma.
{{ state_attr('sensor.coinbase_eth_wallet', 'Balance in native currency').replace(" EUR", "").replace(",", ".") | int }}
There are two string escaping characters. ' or ".
here: {{as_timestamp(state_attr ('sun.sun','next_noon')) | timestamp_custom("%H:%M", true)}}
both is used.
So adding a " on the outside will cause "{{as_timestamp(state_attr ('sun.sun','next_noon')) | timestamp_custom("%H:%M", true)}}"
when you use >- and a line break you can use both in the string since none of them is needed to enclose the template.
When HA saves templates it’s usually converted to:
So in short there is many ways to do it. I should have used ' as you did in the timestamp_custom but I didn’t think about it.
Since I usually do these mistakes with using both, I have started using >- to my sensors.
Thanks for the explanation. Maybe i’ll start doing the same.
It took some time for me to figure out why it wasn’t working. that’s mainly because I solve these things with trial and error. I mentioned it in the thread so that if someone runs in to the same thing they have an idea what to look for.
I’d love to have some more in depth knowledge on this programming language but I just don’t have the time to study it. So these little bits of info I get from knowledgeable people like you are extremely valuable. I’m sure that goes for many HA enthusiasts here. So thanks again.