You still need to supply float with a default value but the availability template ensures the state template’s calculation is never performed when either sensor’s value is unavailable.
If you want it to be more thorough, use this:
availability: >
{{ states('sensor.openweathermap_temperature') not in ['unavailable', 'unknown'] and
states('sensor.openweathermap_humidity') not in ['unavailable', 'unknown'] }}
Yes. All that was needed was to copy-paste the code I posted to the sensor’s configuration.
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 is resolved. This helps other users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.
I didn’t see your second question get answered, and it doesn’t look applicable with your new code, but figured an answer might still be appreciated. Also, for future reference, it helps if you specify the error that you are seeing when asking about why you’re getting an error.
Anyway, you’re getting an error because of incorrect formatting in the if statement; only one if is needed, even with multiple checks. Also, I’m not too familiar with the tilde operation, but it seemed like a weird use to me, so I replaced it with an and:
It’s used for concatenating strings and its usage in the original example is completely incorrect. It’s probably the root cause of the Template Editor’s complaint and not this:
The fact is, without the % symbol, the resulting Jinja2 brackets are definitely invalid and don’t form a proper statement.