Utility meter not returning number?

Hi, I am trying to sum up three energy sources to determine daily totals. I’m using HA 2023.10.3.

1 sensor is from an Emporia Vue 2 which has a daily sensor feeding into HA (sensor.hot_water_tank_8_1d’)
The other 2 sensors are from Switchbot smart plugs which only report instantaneous power consumption.

I’m doing left, Reimann sums on those two plugs:

sensor:
  - platform: integration
    source: sensor.mini_tank_power 
    unique_id: mini_tank_kwh_total
    name: Mini tank kwh total
    unit_prefix: k
    unit_time: h
    method: left
  
  - platform: integration
    source: sensor.tankless_water_heater_power 
    unique_id: tankless_water_heater_kwh_total
    name: Tankless water heater kwh total
    unit_prefix: k
    unit_time: h
    method: left

I also have utility meters set up for these cycling daily:

utility_meter:
  mini_tank_kwh_daily:
    unique_id: mini_tank_kwh_daily
    source: sensor.mini_tank_kwh_total
    name: Mini tank kWh daily
    cycle: daily
  
  tankless_water_heater_kwh_daily:
    unique_id: tankless_water_heater_kwh_daily
    source: sensor.tankless_water_heater_kwh_total
    name: Tankless water heater kWh daily
    cycle: daily

The Emporia sensor and the two meters show have valid states in the Dev tools: States and I can see the values in Dashboards just fine:

Screenshot from 2023-10-22 10-15-42

(See the problem in above figure with ‘Hot water total 1 day’)

Then I sum them with a template sensor:

  - sensor:
      - name: "Hot water total 1 day"
        unique_id: hot_water_total_1_day
        device_class: energy
        unit_of_measurement: "kWh"
        state_class: total_increasing
        icon: mdi:lightning-bolt
        state: >-
          {{ (states('sensor.hot_water_tank_8_1d') | float + states('mini_tank_kwh_daily') | float + states('tankless_water_heater_kwh_daily') | float ) }}

In the log the template sensor is throwing a value error:

ValueError: Template error: float got invalid input 'unknown' when rendering template '{{ (states('sensor.hot_water_tank_8_1d') | float + states('mini_tank_kwh_daily') | float + states('tankless_water_heater_kwh_daily') | float ) }}' but no default was specified

By subbing in defaults [e.g. float(default(10) ] I can see that the problem is that these two values:

states('mini_tank_kwh_daily') | float
tates('tankless_water_heater_kwh_daily') | float 

are coming back as ‘unknown’. If I default them to 0 then they are just ignored in the calculation, I I just get returned the value of the states(‘sensor.hot_water_tank_8_1d’) as the total.

I am not understanding why they are coming back in the calculation as unknown if I can see a valid states.

What am I missing here?

You’re missing the domain part of the entity ID.

states('mini_tank_kwh_daily')
versus
states('sensor.mini_tank_kwh_daily')

And you should also include defaults for your float filters and an availability template or you are going to have a bad time when one or more of the sensors is unavailable or unknown.

- sensor:
      - name: "Hot water total 1 day"
        unique_id: hot_water_total_1_day
        device_class: energy
        unit_of_measurement: "kWh"
        state_class: total_increasing
        icon: mdi:lightning-bolt
        state: >
          {{ states('sensor.hot_water_tank_8_1d') | float(0) + states('sensor.mini_tank_kwh_daily') | float(0) + states('sensor.tankless_water_heater_kwh_daily') | float }}
        availability: >
          {{ has_value('sensor.hot_water_tank_8_1d') and has_value('sensor.mini_tank_kwh_daily') and has_value('sensor.tankless_water_heater_kwh_daily') }}

Oh wow. So…not smart…on my end. Thanks @ mekaneck for catching that!

Thank @ tom_l .
So I wasn’t really aware of the availability template. So the purpose is for the sensor to return unavailable rather than throw errors which may lead to less desireable outcomes, correct?

It is particularly important if you are using this sensor in the energy dashboard. If one or more of your sensors becomes unavailable momentarily then this can cause your total to decrease then increase. This is seen as a reset for a total_increasing sensor. By showing unavailable unless all your source sensors are present you can avoid energy dashboard glitches.

Ah ok. That’s good to know. I’m fairly new to HA and I am using the Energy dashboard and have noticed it can be a bit finicky.