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:
(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?