How to check if entity value is "Unknown"

Hi everyone,
I am trying to create a sensor that converts the battery states into values (better to work with).
But I would like to ensure that when the sensor is unavailable, a certain value is assigned.

    value_template: >
          {% if value_json.battery == "GOOD" %}
          {% elif value_json.battery == "" %}
          {% else %}
          {% endif %}  

But this is not working.
I also tried == “Unknown” but that also does not work.

Is there a way to check if there is no value to rule out wrong values from system restarts?

Thank you :slight_smile:

Post all of the sensor’s configuration.

If this is a legacy Template Sensor, I am wondering why you are using value_json in the template. This is an MQTT Sensor?

If it is an MQTT Sensor, post an example of the payload it receives.

Try lowercase, "unknown", and/or "unavailable".

It is in MQTT sensor. As I said, the payloads are fine. It is just about finding out how Home Assistant states the “Unknown”. This is not a value that is being sent as a payload but just what HA uses until is has received data.

I will try “unknown” next. But will this be language dependent? so if I ever switched my server to German, would the automation then break?

I think I understand the issue but it’s preferable if you post the MQTT Sensor’s complete configuration and not just its value_template.

The solution is to either make the source of the data publish it as a retained message or add availability_topic.

1 Like