Template availability - quick question

Hi, I get an unavailable state on the sensor below.
Is this because only “power_prod_high_daily” reports data and “power_prod_low_daily” is not (at this moment?)

is it simple to just change “and” in the availability line to “or”?

because what I’m trying to achieve: it must always give data back when both sensors report something but also if one of the two report something.

      - name: "Power production daily"
        unique_id: power_prod_total_daily
        state: "{{ ( states('sensor.power_prod_high_daily')|float(0) + states('sensor.power_prod_low_daily')|float(0) ) }}"
        unit_of_measurement: "kWh"
        icon: mdi:lightning-bolt-outline
        availability: "{{ states('sensor.power_prod_high_daily') and states('sensor.power_prod_low_daily') }}"

Your state template is adding the values of two sensors. Ideally, both sensors should have valid values and not just one or the other. In other words, the value of each sensor should not be unknown or unavailable.

However, if your choice is to accept at least one valid sensor value, instead of two, then you should logically OR the tests using has_value.

      - name: "Power production daily"
        unique_id: power_prod_total_daily
        state: >
          {{ states('sensor.power_prod_high_daily')|float(0) + 
             states('sensor.power_prod_low_daily')|float(0) }}
        unit_of_measurement: "kWh"
        icon: mdi:lightning-bolt-outline
        availability: >
          {{ has_value('sensor.power_prod_high_daily') or 
             has_value('sensor.power_prod_low_daily') }}

Hi Taras, thanks for your reply.
I’ve looked at the sensors which have the current values:

power_prod_high_daily = 0.657
power_prod_low_daily = 0

the template sensor:
power_prod_total_daily = unavailable

is “0” a valid value? I think it is but how come the template sensor reports unavailable then, I though I was related to the availability line.

can I still use and try your solution?

You’re getting that result because the template used by your example’s availability option is inappropriate for the purpose of determining if the sensors have valid values.

Ah I think I understand, so it’s better to remove the availability line then?

I suggest you try the example I posted.

Your availability template was not testing for a valid value, it was performing a logical and on the states of the two sensors. Doing that will not achieve your goal.

1 Like