How to ignore unknown value

I used this:

template:
  - sensor:
    - name: 'Daily Consumed Total'
      device_class: energy
      unit_of_measurement: kWh
      state: >
        {% if is_number(states('sensor.daily_consumed_low')) and is_number(states('sensor.daily_consumed_high')) %}
          {{ (states('sensor.daily_consumed_low') + states('sensor.daily_consumed_high')) | float }}
        {% else %}
          None
        {% endif %}
        
    - name: 'Daily Produced Total'
      device_class: energy
      unit_of_measurement: kWh
      state: >
        {% if is_number(states('sensor.daily_produced_low')) and is_number(states('sensor.daily_produced_high')) %}
          {{ (states('sensor.daily_produced_low') + states('sensor.daily_produced_high')) | float }}
        {% else %}
          None
        {% endif %}

But sometimes the sensors have a unknown value, how would I ignore this and have an always “working” Daily Consumed Total and Daily Produced Total.

I found some examples here but how would I change the above state?

Suggestion. Change

{% if is_number(states(‘sensor.daily_consumed_low’)) and is_number(states(‘sensor.daily_consumed_high’)) %}

to

{% if (states(‘sensor.daily_consumed_low’) != ‘unavailable’) and (states('sensor.daily_consumed_high) != ‘unavailable’) %}

Thanks, would this be an option: https://community.home-assistant.io/t/json-sensor-data-unknown-replace-with-value/78178

Cause I think I need a value of at least “0”

Tried your change but getting error:

Invalid config for [template]: invalid template (TemplateSyntaxError: unexpected char ‘‘’ at 14) for dictionary value @ data[‘sensor’][0][‘state’]. Got “{% if (states(‘sensor.daily_consumed_low’) != ‘unavailable’) and (states('sensor.daily_consumed_high) != ‘unavailable’) %}\n {{ (states(‘sensor.daily_consumed_low’) + states(‘sensor.daily_consumed_high’)) | float }}\n {% else %}\n None\n {% endif %}\n \n”. (See /config/configuration.yaml, line 188).

Try

{% if (states('sensor.daily_consumed_low') != "unavailable") and (states('sensor.daily_consumed_high') != "unavailable") %}
  {{ (states('sensor.daily_consumed_low') + states('sensor.daily_consumed_high')) | float }}
{% else %}
  0
{% endif %}

But first I would try to avoid having sensors with ‘unknown value’

You may need to rethink your strategy for extracting the data and I advise you to use Utility Meter - Home Assistant

Hi, already was using the utility meter but needed the sum of two utility values.
I searched here and solved it by using this:

      daily_consumed_total:
        friendly_name: "Daily Consumed Total"
        device_class: energy
        unit_of_measurement: "kWh"
        value_template: "{{ states('sensor.daily_consumed_low') |float(0) + states('sensor.daily_consumed_high') | float(0) }}"
      daily_produced_total:
        friendly_name: "Daily Produced Total"
        device_class: energy
        unit_of_measurement: "kWh"
        value_template: "{{ states('sensor.daily_produced_low') |float(0) + states('sensor.daily_produced_high') | float(0) }}"

That’s because @oalbaf didn’t format the code properly in the first post, and you copied and pasted the “smart quotes”.

Certain. Rookie mistake. I have learned for the following contribution. Sorry!