Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'm³/h' and 'MJ' is not valid data type for device class ('gas') - (warning) #85905

Closed
Roving-Ronin opened this issue Jan 15, 2023 · 4 comments
Closed

Comments

@Roving-Ronin
Copy link
Contributor

The problem

Hi,
Since upgrading from 2023.1 yesterday, I am now getting the warning that 'm³/h' and 'MJ' (megajoules) are not valid units of measurements for the sensor class of gas.

Is this something that can be added into the sensor class to be supported, as:

  • As with use of pulse_meter for gas etc, there is the use of 'm³/h' to support monitoring the flow rate of the gas in general as well as being able to use it to notice and leaks.

  • In Australia (and probably other countries) we are billed upon the MJ of energy consumed (having to apply a correction factor x0.9775 in my gas network providers case, and then a conversion factor x38.29 to get from m3 to MJ) and not m³, ft³ or CCF.

Not sure if MJ is something that should be added to the SensorDeviceClass.GAS as it is technically a unit of energy ( https://www.elgas.com.au/blog/631-what-is-mj-mega-joule-megajoule-gas-heater/ ) so adding 'MJ' to the SensorDeviceClass.ENERGY would seem the in line with existing HA standards.

What version of Home Assistant Core has the issue?

2023.1.4

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

Gas Sensor (and Energy Sensor potentially)

Link to integration documentation on our website

No response

Diagnostics information

N/A

Example YAML snippet

ESPHome Gas Sensor Yaml


  #  Gas pulse meter on GPIO 5 & 0.01m3 (10L) increments
  - platform: pulse_meter
    name: '${friendly_name} - Flow Rate'
    id: "sensor_gas_flow_rate"
    unit_of_measurement: "m³/h"
    state_class: measurement
    device_class: gas
    icon: "mdi:pump"
    accuracy_decimals: 2
    pin:
      number: 5
      inverted: true
      mode: INPUT_PULLUP
    internal_filter_mode: PULSE
    internal_filter: 2s
    timeout: 5min
    filters:
      - multiply: 1.0
    #  Uses the above pulse_meter and adds sensor and calculations for tracking m3
    total:    
      name: '${friendly_name} - Reading'
      id: sensor_gas_reading
      unit_of_measurement: ""
      icon: "mdi:counter"
      state_class: "total_increasing"
      device_class: gas
      accuracy_decimals: 2
      filters:
        - multiply: 0.01

____________________________________________________________
HA - Gas YAML (sensors, tariffs and rates etc)



#
#  Based upon sensor in ESP device being configured as type PULSE meter.
#  Uses code from SgtBatten and also from https://community.home-assistant.io/t/using-home-assistant-to-calculate-my-energy-bill-using-data-from-my-solar-inverter/344913/1
#

template:
  - sensor:

# ---------------------------------------------------------------------------
#
#  Takes sensor called 'gas_meter_reading' from the ESPHome device. Based upon the meter recording in 0.01m³ increments (10L)
#  The correction factor is the factor the retailer applies to the meter reading, to allow for temperature affecting gas volume.
#
      - name: "Gas Meter Reading - m³"
        unique_id: gas_meter_reading_m3
        state: "{{ states('sensor.gas_meter_reading') | float(0) * 0.9775 }}"   # Change 0.9775 to your retailers CORRECTION FACTOR
        unit_of_measurement: ""
        icon: mdi:fire
        device_class: gas
        state_class: total_increasing

#
#  Takes the above sensor 'gas_meter_reading_m3' and applied the 'heating value' as determined by the retailer, to convert from m3 to MJ.
#
      - name: "Gas Meter Reading - MJ"
        unique_id: gas_meter_reading_mj
        state: "{{ states('sensor.gas_meter_reading_m3') | float(0) * 38.29 }}"   #Update 38.29 to your retailers HEATING VALUE
        unit_of_measurement: "MJ"
        icon: mdi:fire
        device_class: gas
        state_class: total_increasing

# ---------------------------------------------------------------------------
#
#  Gas retailer consumption and daily connection fee charges.
#
      - name: "Gas Tariff Rate - 1"               # 0-1905mj per quarter
        unique_id: gas_tariff_rate_1
        icon: mdi:cash-minus
        unit_of_measurement: "$/MJ"
        state: "0.03470"                          # update to reflect your retailers cost per MJ

      - name: "Gas Tariff Rate - 2"               # 1905-252558mj per quarter
        unique_id: gas_tariff_rate_2
        icon: mdi:cash-minus
        unit_of_measurement: "$/MJ"
        state: "0.02070"                          # update to reflect your retailers cost per MJ

      - name: "Gas Tariff Rate - 3"               # above 252,558mj per quarter
        unique_id: gas_tariff_rate_3
        icon: mdi:cash-minus
        unit_of_measurement: "$/MJ"
        state: "0.01800"                          # update to reflect your retailers cost per MJ

      - name: "Gas Supply Charge - Daily"
        unique_id: gas_supply_charge_daily
        icon: mdi:cash-minus
        unit_of_measurement: "$"
        state: "0.58500"

# ---------------------------------------------------------------------------
# 
#  Calculate daily, quarterly and yearly costs (consumption plus daily connection fee).
#
      - name: "Tariff - Gas Cost Daily"
        unique_id: tariff_gas_cost_daily
        icon: mdi:currency-usd
        state_class: total_increasing
        device_class: monetary
        unit_of_measurement: $
        state: >
          {% set supply = states('sensor.gas_supply_charge_daily') | float(0) %}
          {% set usage1 = states('sensor.gas_consumed_daily_mj_rate_1') | float(0) * states('sensor.gas_tariff_rate_1') | float(0) %}
          {% set usage2 = states('sensor.gas_consumed_daily_mj_rate_2') | float(0) * states('sensor.gas_tariff_rate_2') | float(0) %}
          {% set usage3 = states('sensor.gas_consumed_daily_mj_rate_3') | float(0) * states('sensor.gas_tariff_rate_3') | float(0) %}
          {{ (supply + usage1 + usage2 + usage3) | round(2) }}


      - name: "Tariff - Gas - Quarterly"
        unique_id: tariff_gas_cost_quarterly
        icon: mdi:currency-usd
        state_class: total_increasing
        device_class: monetary
        unit_of_measurement: $
        state: >
          {% set supply = states('sensor.gas_supply_charge_daily') | float(0) * now().day %}
          {% set usage1 = states('sensor.gas_consumed_quarterly_mj_rate_1') | float(0) * states('sensor.gas_tariff_rate_1') | float(0) %}
          {% set usage2 = states('sensor.gas_consumed_quarterly_mj_rate_2') | float(0) * states('sensor.gas_tariff_rate_2') | float(0) %}
          {% set usage3 = states('sensor.gas_consumed_quarterly_mj_rate_3') | float(0) * states('sensor.gas_tariff_rate_3') | float(0) %}
          {{ (supply + usage1 + usage2 + usage3) | round(2) }}


# ---------------------------------------------------------------------------
# 
# Utility meter consumption totals in cubic meters (m3), as the gas meter provides, with retailer correction factor applied.
# No tariffs are required here, as the retailers count the overall m3 for the quarter, but bill upon the MJ.
#

utility_meter:

#  Note this reading is in 'corrected' m3, after correction factor applied.
  gas_consumed_daily_m3:
    unique_id: gas_consumed_daily_m3
    source: sensor.gas_meter_reading_m3
    name: Gas Consumed Daily m³
    cycle: daily

#
#   Quarterly m3 total only included to allow validation against the retailers m3 reading on their quarterly invoice.
#
  gas_consumed_quarterly_m3:
    unique_id: gas_consumed_quarterly_m3
    source: sensor.gas_meter_reading_m3
    name: Gas Consumed Quarterly m³

#
#  The meter reading on the physical gas meter display window. m3 are raw, and not 'corrected'.
#
#  gas_meter_reading_lifetime_m3:
#    unique_id: gas_meter_reading_lifetime_m3
#    source: sensor.gas_meter_reading_raw
#    name: Gas Meter Reading Lifetime m³
# To Do - SET baseline and then add gas_meter_reading_raw to it.


# ---------------------------------------------------------------------------
# 
#   Utility meter consumption totals in megajoules (mj), as converted from gas meter m3 reading, with retailer correction factor applied.
#

  gas_consumed_daily_mj:
    unique_id: gas_consumed_daily_mj 
    source: sensor.gas_meter_reading_mj
    name: Gas Consumed Daily mj
    cycle: daily
    tariffs:
      - rate_1
      - rate_2
      - rate_3

  gas_consumed_quarterly_mj:
    unique_id: gas_consumed_quarterly_mj
    source: sensor.gas_meter_reading_mj
    name: Gas Consumed Quarterly mj
# To Do - Add cron job that calls substitution of days to offset
    tariffs:
      - rate_1
      - rate_2
      - rate_3

#
#  The Quarterly MJ Total reading is required to provide a reading against which the tariff rates are triggered, as 0-1905mj / 1905-252558mj etc are based on total for the quarter
#
  gas_consumed_quarterly_mj_total:
    unique_id: gas_consumed_quarterly_mj_total
    source: sensor.gas_meter_reading_mj
    name: Gas Consumed Quarterly mj Total
# To Do - Add cron job that calls substitution of days to offset

# ---------------------------------------------------------------------------
#
# Automation to monitor (quarterly mj reading) and switch tarrifs as they hit mj consumed thresholds for the quarter.
#

automation:

  #  This continually checks the quarterly mj used and then changes the tariff being used based upon mj used for the quarter
  - alias: Set Gas Tariff
    description: 'Set Gas Rate Tariff based upon the mj consumed during the quarter'
    trigger:
      - platform: state
        entity_id:
          - sensor.gas_meter_reading_mj
    condition: []
    action:
    - service: select.select_option
      data:
        option: >-
          {% set mj = states('sensor.gas_consumed_quarterly_mj_total') | float(0) %}
          {%- if mj >= 0 and mj < 1905  %}
            rate_1
          {%- elif mj >= 1905 and mj | float(0) < 252558 %}
            rate_2
          {%- else -%}
            rate_3
          {%- endif -%}
      target:
        entity_id:
          - select.gas_consumed_daily_mj
          - select.gas_consumed_quarterly_mj
    mode: single

  - alias: Gas Meter Quarterly Reset
    description: 'Reset the gas quarterly meter totals, at the end of each quarter. Remember to update these dates each year.'
    trigger:
      - platform: time
        at: input_datetime.gas_quarter_1
      - platform: time
        at: input_datetime.gas_quarter_2
      - platform: time
        at: input_datetime.gas_quarter_3
      - platform: time
        at: input_datetime.gas_quarter_4
    condition: []
    action:
      - service: utility_meter.reset
        data: {}
        target:
          entity_id:
            - select.tariff_gas_quarterly
            - select.gas_consumed_quarterly_m3
            - select.gas_consumed_quarterly_mj
            - select.gas_consumed_quarterly_mj_rate_1
            - select.gas_consumed_quarterly_mj_rate_2
            - select.gas_consumed_quarterly_mj_rate_3
    mode: single

# ---------------------------------------------------------------------------

Anything in the logs that might be useful for us?

Logger: homeassistant.components.sensor
Source: components/sensor/__init__.py:980
Integration: Sensor (documentation, issues)
First occurred: 1:23:15 am (2 occurrences)
Last logged: 1:23:19 am

Entity sensor.gas_meter_flow_rate (<class 'homeassistant.components.esphome.sensor.EsphomeSensor'>) is using native unit of measurement 'm³/h' which is not a valid unit for the device class ('gas') it is using; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+esphome%22


Entity sensor.gas_meter_reading_mj (<class 'homeassistant.components.template.sensor.SensorTemplate'>) is using native unit of measurement 'MJ' which is not a valid unit for the device class ('gas') it is using; Please update your configuration if your entity is manually configured, otherwise create a bug report at https://github.com/home-assistant/core/issues?q=is%3Aopen+is%3Aissue+label%3A%22integration%3A+template%22

Additional information

No response

@frenck
Copy link
Member

frenck commented Jan 16, 2023

    unit_of_measurement: "m³/h"
    state_class: measurement
    device_class: gas

The gas device class isn't used for flowrate but represents a volume.
MJ is not a supported unit for the gas device class.

Each device class, its purpose, and its accepted units have always been documented in our end-user and developer documentation. The checks have been recently added to warn in case device classes have been misused.

Both error messages are not a bug but correct warnings, closing the issue for that reason.

../Frenck

@frenck frenck closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2023
@Roving-Ronin
Copy link
Contributor Author

@frenck instead of hurry to close this, please take time to read what was actually lodged.

"Not sure if MJ is something that should be added to the SensorDeviceClass.GAS as it is technically a unit of energy ( https://www.elgas.com.au/blog/631-what-is-mj-mega-joule-megajoule-gas-heater/ ) so adding 'MJ' to the SensorDeviceClass.ENERGY would seem the in line with existing HA standards."

and:

"Integration causing the issue
Gas Sensor (and Energy Sensor potentially)"

and also that it was flagged that whilst this relates to gas as what it is monitoring, that SensorDeviceClass.ENERGY should also be assigned this. By closing this immediately and not assigning to the dev for SensorDeviceClass.GAS you kill the issue.

@frenck
Copy link
Member

frenck commented Jan 16, 2023

instead of hurry to close this, please take time to read what was actually lodged.

I'm sorry, but I did. You made an assumption there which is not correct.

"Not sure if MJ is something that should be added to the SensorDeviceClass.GAS as it is technically a unit of energy ( elgas.com.au/blog/631-what-is-mj-mega-joule-megajoule-gas-heater ) so adding 'MJ' to the SensorDeviceClass.ENERGY would seem the in line with existing HA standards."

That is a feature request and not a bug. Device classes are limited in the units they accept. That is currently by design. The allowed units for each device class are documented (as pointed out in my previous response as well).

and also that it was flagged that whilst this relates to gas as what it is monitoring, that SensorDeviceClass.ENERGY should also be assigned this.

Our current scope of device classes do not agree. This is not a bug.

By closing this immediately and not assigning to the dev for SensorDeviceClass.GAS you kill the issue.

It isn't an issue to start with. Hence it was closed.

../Frenck

@Roving-Ronin
Copy link
Contributor Author

@frenck . OK many thanks :-)

@github-actions github-actions bot locked and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants