On all 2023.4.X front ends, the sensors work perfectly, however, as soon as I update to 2023.5.X the custom sensors become unavailable.
>
> - platform: template
> sensors:
> # Sensor to check from a goodwe sensor what the differential is between buy and sell
> munic_meter_reading_differential:
> friendly_name: 'Buy Sell Differential (Calculation)'
> value_template: "{{ (states('sensor.energy_buy_sum')|float - states('sensor.energy_sell_sum')|float)|round(3) }}"
> unit_of_measurement: "kWh"
>
> # Sensor for Munic Power Current Reading at the meter
> munic_meter_reading:
> friendly_name: 'Munic meter current reading'
> value_template: "{{ (states('counter.munic_calibration_meter_reading')|float + states('sensor.munic_meter_reading_differential')|float)|round(3) }}"
> unit_of_measurement: "kWh"
>
> # Sensor to check the meter status (How many are actualy used)
> previous_munic_meter_reading:
> friendly_name: 'Munic electricity usage'
> value_template: "{{ (states('sensor.munic_meter_reading')|float - states('counter.munic_previous_meter_reading')|float)|round(3) }}"
> unit_of_measurement: "kWh"
>
What’s different in version 2023.5.X is that when you include the unit_of_measurement option, the sensor’s value must be numeric. Your sensor values appear to be numeric (although when using the float filter you should supply it with a default value) so there must be something else. Are there any related error messages in the Log?
If the value of either sensor.energy_buy_sum or sensor.energy_sell_sum is unavailable or unknown, it will be replaced by zero. So let’s say the value of both sensors is non-numeric, the calculation becomes (0 - 0) | round(3) which will report zero.
It looks like this is all related to the breaking change in the Riemann sum calculations, where if the lookup sensor hits “0” the state changes to unavailable, and breaks the integration.