Integration Templates and Utility Templates suddenly "Unavailable"

Hello,
up until some update all my sensors worked fine, the integration sensors as well as the derived utility sensors.
Somehow now my Integration Sensors now show “Unavailable” as soon as the sensor it is based off has a value of 0…(edit: the value 0 is not the problem, as it has to be 0 from time to time)
Here is what it looks like when I display the entities…

Any help would be appreciated.

image
image

And here my config:

  - platform: template
    sensors:
      shelly_power_water:
        friendly_name: "Shelly Power Consumption Water"
        unit_of_measurement: 'W'
        value_template: >-
          {% if ( ( (states('sensor.shelly3em_channel_a_power')|float - states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float) > 0 ) and ( is_state('sensor.wkh_status_water', 'on') ) ) %}
            {{ states('sensor.shelly3em_channel_a_power')|float - states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability_template: "{{ 
            [ states('sensor.shelly3em_channel_a_power'),
              states('sensor.shelly3em_channel_b_power'),
              states('sensor.shelly3em_channel_c_power')
            ] | map('is_number') | min 
          }}"

This is the integration sensor which uses this template sensor:

sensor:
  - platform: integration
    source: sensor.shelly_power_water
    name: shelly_energy_water
    round: 2
    unit_prefix: k
    method: left

and these are the utility meters:

utility_meter:
  shelly_energy_water_daily:
    source: sensor.shelly_energy_water
    cycle: daily
    
  shelly_energy_water_monthly:
    source: sensor.shelly_energy_water
    cycle: monthly

  shelly_energy_water_yearly:
    source: sensor.shelly_energy_water
    cycle: yearly

It used to look like this and I really cant see the difference to the above sensors apart from the “is_state( )” in the value template.
image

      shelly_power:
        friendly_name: "Shelly Power Consumption"
        unit_of_measurement: 'W'
        value_template: >-
          {% if (states('sensor.shelly3em_channel_a_power')|float - states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float) > 0 %}
            {{ states('sensor.shelly3em_channel_a_power')|float - states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability_template: "{{
            [ states('sensor.shelly3em_channel_a_power'),
              states('sensor.shelly3em_channel_b_power'),
              states('sensor.shelly3em_channel_c_power')
            ] | map('is_number') | min
          }}"

So this is a template question and not a blueprint question, but that said, I noticed that you are using the float filter wrong. That needs to include a default value.

Thanks for the answer. After reading your link more thoroughly I found that as well and corrected it.

My problem is not the power sensors value 0 W. Actually I expect it to be 0W at that moment, since it is supposed to only have a value when the heating is running. Looking at the history that seems to work fine.

My problem is the integration beeing „unavailable“, and following that all utility meters, that are based off it.
This happens only when the power sensor is 0. when the heating is running the other sensors show a value.

It’s not a frontend question either. That is for dashboard configuration.

Try this:

      shelly_power:
        friendly_name: "Shelly Power Consumption"
        unit_of_measurement: 'W'
        device_class: power
        value_template: >-
          {% if (states('sensor.shelly3em_channel_a_power')|float - states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float) > 0 %}
            {{ states('sensor.shelly3em_channel_a_power')|float - states('sensor.shelly3em_channel_b_power')|float + states('sensor.shelly3em_channel_c_power')|float }}
          {% else %}
            {{ 0 }}
          {% endif %}
        availability_template: "{{
            [ states('sensor.shelly3em_channel_a_power'),
              states('sensor.shelly3em_channel_b_power'),
              states('sensor.shelly3em_channel_c_power')
            ] | map('is_number') | min
          }}"

Hello Tom,
sorry for wrong categorization. I somehow could not remove it via mobile…

I fixed the float(0) issue as well as added the “device_class” to power.

These are the entities when HEATING is working, Water has not worked that day
For explanation: Power sum sums up all power, and water/heating only get active when the respective service of the heatpump is online.

Now heating has worked and has stopped working - and sensors look like this after about 30 minutes:

Why do these sensors go back to “Unavailable” ?
Seems like the integration has problems with the zero-values.
Usually I would want them to show the last state that was valid
Here some screenshots of the data in grafana with "fill(null)

Seems like the availability_template section of the sensors was the cause. After removing that it works as before.

Try this:

        availability_template: >
          {{
            [ states('sensor.shelly3em_channel_a_power'),
              states('sensor.shelly3em_channel_b_power'),
              states('sensor.shelly3em_channel_c_power')
            ] | map('is_number') | min
          }}

I have the same issue with my shelly utility meters. What exactly did you change to fix the issue?
I noticed that if I turn on the shelly for a second or 2 that the utility meter shows as expected.

sensor: 
  - platform: integration
    source: sensor.shelly_2_5_48551902854f_power_1
    name: garage_light_energy_kwh
    unit_prefix: k
    round: 2

utility_meter:
  # ==================Light==================
  garage_light_daily_kwh:
    source: sensor.garage_light_energy_kwh
    cycle: daily

  garage_light_monthly_kwh:
    source: sensor.garage_light_energy_kwh
    cycle: monthly

Edit: Restarting HA fixes the issue temporally, I’ll test if manual reload of mqtt devices or enties/groups also fixes the issue.

I have the same problem you described. It doesn’t help either having, or not having, an ‘availability’ clause (I thought the new format was ‘availability’, not ‘availablity_template’?)

I’m measuring power imported and exported from the grid. If I restart HA or all YAML, either the imported integration OR the exported integration will be ‘unavailable’ depending on whether the house is currently exporting or importing energy. And vice versa. It’s bizarre.

@ItherNiT @spry-salt I assume you could change your value_template or state, so it will be 0, if unavailable:

Below is an example. Only if value is greater than 0, use the value, otherwise it will be 0.

Other ideas:
Also you might want to experiment with the float or float(0). That might get it to work.

Also note it is common that the daily and integration sensors need some data in order to work become available. The daily sensor should become available latest at 0:00 since it resets, so you could try to wait.
Integration sensor usually also takes some time to become available.

state: >- {% if ( (("sensor.inverter_active_power") |float) - (states("sensor.power_meter_active_power") |float) ) > 0 %} {{ (states("sensor.inverter_active_power") |float) - (states("sensor.power_meter_active_power") |float) }} {% else %} {{ 0 }} {% endif %}

Yes. But looking at some activity on GitHub it looks like it was a bug that’s now being fixed.

Same issue to me.

This seems to be happening since 2023.5.2

Hey,
Same problem… news on the fix?
Thanks!

I also face the same issue using 2023.8.1.
The integration sensor becomes unavailable once the source sensor is 0.
Does anyone know whether this is being fixed?

This seems to be fixed now