ssenart / home-assistant-gazpar

GrDF Gazpar meter integration for Home Assistant
MIT License
43 stars 9 forks source link

[Bug] gas_energy not showing in the energy dashboard #24

Closed yodapotatofly closed 1 year ago

yodapotatofly commented 1 year ago

Only gas_volume is available in gaz energy dashboard

image

Logs shows :

Logger: homeassistant.components.sensor
Source: custom_components/gazpar/util.py:28
Integration: Capteur (documentation, issues)
First occurred: 23:07:27 (2 occurrences)
Last logged: 23:07:27

Error adding entities for domain sensor with platform gazpar
Error while setting up gazpar platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 692, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 789, in add_to_platform_finish
    self.async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 545, in async_write_ha_state
    self._async_write_ha_state()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 583, in _async_write_ha_state
    state = self._stringify_state(available)
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 551, in _stringify_state
    if (state := self.state) is None:
  File "/config/custom_components/gazpar/sensor.py", line 257, in state
    return Util.toState(self._dataByFrequency)
  File "/config/custom_components/gazpar/util.py", line 28, in toState
    dailyData = pygazparData[FrequencyStr.DAILY]
KeyError: <FrequencyStr.DAILY: 'daily'>
ssenart commented 1 year ago

This error is a bug. It should appear only at HA initialization. HA try to get some entity data despite data are not available yet.

However, this error is not related to the fact that your gas_energy is not displayed. Your entity data should be recorded with the recorder module and also ensure you have at least the following attributes;

state_class: total_increasing
unit_of_measurement: kWh
device_class: energy
icon: mdi:fire
friendly_name: gas_energy

I am still on HA version 2022.5.5.

On my setup, I have the same kind of issue as your have. I don't manage to show gas_volume entity.

yodapotatofly commented 1 year ago

the sensors are defined exactly as in the readme :

template:
  - sensor:
      - name: gas_volume
        unit_of_measurement: "m³"
        state: >
          {{ state_attr('sensor.gazpar', 'daily')[0]['end_index_m3'] | float(0) }}
        icon: mdi:fire
        device_class: gas
        state_class: total_increasing
      - name: gas_energy
        unit_of_measurement: "kWh"
        state: >
          {{ states('sensor.gazpar') | float(0) }}
        icon: mdi:fire
        device_class: energy
        state_class: total_increasing

So you're saying that on your end, you only have gas_energy and not gas_volume ?

I also tried inverting the two sensors order in the yaml, with no success

yodapotatofly commented 1 year ago

Ok, I guess I found the issue : to appear in the "gas" energy dashboard, device_class needs to be... 🥁🥁🥁 "gas" !

ssenart commented 1 year ago

I have just upgraded to HA 2022.11.4, and now sensor.gas_energy does not show up in gas section, but it is visible in electricity section.

I guess you're right. Now :

yodapotatofly commented 1 year ago

Yes, I can confirm that with gas in works properly. I'll let you correct the readme and close the issue ?

ssenart commented 1 year ago

In fact, it is identified as a regression in HA 2022.11.

See : https://github.com/home-assistant/frontend/issues/14292

purcell-lab commented 1 year ago

This issue appears to be fixed in the 2022.12 beta release.