I’m still having issues with gas measurements in the energy dashboard. I know some changes were made in November around permissible measuring units for gas which broke my system, and many others. I thought these had been reversed, but I’m still having issues. I’m running 2022.12.7.
These appear in two ways. First, my daily gas standing charge calculation doesn’t work and just produces £0.00 instead of the correct calculated value. Secondly, I get these errors logged every midnight:
2023-01-01 00:00:00.020 ERROR (MainThread) [homeassistant.helpers.event] Error while processing state change for sensor.gas_standing_charge
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/util/unit_conversion.py", line 71, in convert
from_ratio = cls._UNIT_CONVERSION[from_unit]
KeyError: 'Wh'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 288, in _async_state_change_dispatcher
hass.async_run_hass_job(job, event)
File "/usr/src/homeassistant/homeassistant/core.py", line 574, in async_run_hass_job
hassjob.target(*args)
File "/usr/src/homeassistant/homeassistant/components/energy/sensor.py", line 424, in async_state_changed_listener
self._update_cost()
File "/usr/src/homeassistant/homeassistant/components/energy/sensor.py", line 390, in _update_cost
converted_energy_price = converter(
File "/usr/src/homeassistant/homeassistant/util/unit_conversion.py", line 73, in convert
raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Wh is not a recognized volume unit.
Some background… I calculate a daily standing charge by using pseudo metered values for gas and electricity which both increment by 1Wh at midnight daily. I then take this and multiply by the actual standing charge x 1000. This then adds the standing charge to my energy dashboard whilst only adding 1Wh to the total energy readings. The YAML to do this is…
- name: "Elec Standing Charge"
unique_id: standing_charge_counter_elec
unit_of_measurement: "Wh"
device_class: energy
state_class: total_increasing
state: >
{{ (as_timestamp(states('sensor.date_time_iso')) // 86400) }}
- name: "Gas Standing Charge"
unique_id: standing_charge_counter_gas
unit_of_measurement: "Wh"
device_class: energy
state_class: total_increasing
state: >
{{ (as_timestamp(states('sensor.date_time_iso')) // 86400) }}
- name: "Elec Standing Charge x 1000"
unique_id: elec_standing_charge_x1000
device_class: monetary
state_class: measurement
unit_of_measurement: "GBP/kWh"
icon: mdi:cash
state: "{{ states('sensor.smart_meter_electricity_import_standing_charge') |float * 1000 }}"
- name: "Gas Standing Charge x 1000"
unique_id: gas_standing_charge_x1000
device_class: monetary
state_class: measurement
unit_of_measurement: "GBP/kWh"
icon: mdi:cash
state: "{{ states('sensor.smart_meter_gas_import_standing_charge') | float * 1000 }}"
These variables produce the right data in the overview…
This all used to work fine, including in the energy dashboard. Now, the gas standing charge calculation is broken. Here’s the config…
So, I’m multiplying the daily 1Wh increment by the charge x 1000 in GBP/kWh. It should work and used to but is now broken. I can see that Wh is not a volume unit (as the error says!) but the dashboard should work ok with Wh as the config page states.
Help!