Integrate water consumption in energy panel

Based on a counter sensor that counts pulses of a Shelly Uni input, a template sensor has been defined:

template:
  - sensor: 
    - name: Consommation eau
      unit_of_measurement: L
      device_class: water
      state_class: total_increasing
      state: "{{states('counter.eau') }}"

However nothing is showing up in the energy panel. “Consommation eau” is indeed created and it states reflects the counter.eau value

What could be wrong?
Thank you

Have you set the sensor in the Energy dashboard config, or are you not able to choose it there?

Are you sure the value is in Liter and not m³? There’s a x1000 difference, and your sensor value seems very low for L.

ps. Unless the counter is actually reset every xxx period I would use state class total instead of total increasing. if for some reason the value decreases you’ll get weird results.

Thanks.
The counter is never reset and there is no chance it will go the other way
I’m sure the value is L. The screenshot in the OP displays 6041L. It has been set-up a few month ago, hence the low value.

Have you set the sensor in the Energy dashboard config, or are you not able to choose it there?

I see no evidence where I could set it up. Where is that?

since then I read in a post that only m3 and ft3 “seems” to be supported. So I change the unit to m3 and added multiply (0.0001). Nothing showing up either.

it should be in Settings, Dashboard, Energy but when I went there to take a screenshot of how I set it up it has mysteriously disappeared. Bug in 2022.11.1?

Edit: a refresh brought it back:

Liters is supported afaik, but my water meter is running so long and calibrated to rum the same value as the meter itself: 1,153.763 m³ for me. So 6000L is very low in my book :slight_smile:

Oh I see! I never had the idea to go in this panel since I use an integration that set things automatically… However now that I have added the template sensor it reports an error related to unit:

Bummer.
So I had the idea to set it to: m³ (power of 3) and then everything it set up now. By the way I think that both notations should be valid.
Thank you so much, I was really going around in circles.

1 Like

I have a similar problem with a KNX water meter and the Energy panel
In the knx-sensor.yaml

 #Compteur eau 
  - name: compteur_eau
    state_address: "9/7/12"
    type: "volume_liquid_litre"
    sync_state: every 30

I created an entry “utility meter water, gas, electricity” (sensor.compteur_eau_2)
In settings / dashboards / Energy: “Add a water source”, sensor.compteur_eau_2 is not displayed ?

You have to create a template sensor like this:

template:
  - sensor: 
    - name: whatever name
      unit_of_measurement: m³
      device_class: water
      state_class: total_increasing
      state: "{{states('compteur_eau') }}"

Then it will show up in the panel. Watch out the power of 3

thank you for the answer
In knx_sensor.yaml, i have this Code

sensor:
  - name: compteur_eau_4
    state_address: "9/7/3"
    type: "volume_m³"
    device_class: water
    state_class: total_increasing
    state: "{{states('compteur_eau_4')}}"

with this error message

Invalid config for [knx]: extra keys not allowed @ data[‘knx’][‘sensor’][46][‘device_class’]. Got ‘water’
extra keys not allowed @ data[‘knx’][‘sensor’][46][‘state’]. Got “{{states(‘compteur_eau_4’)}}”
type ‘volume_m³’ is not a valid DPT identifier for DPTBase. for dictionary value @ data[‘knx’][‘sensor’][46][‘type’]. Got ‘volume_m³’. (See /config/configuration.yaml, line 7).

lines 7 to 14 of configuration.yaml

# KNX
knx: !include_dir_merge_named knx/
cover: !include cover.yaml
group: !include group.yaml
sensor: !include sensors.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

So if I understand well the counter that receives the increment is compteur_eau_4?
In that case create a template sensor as explained above and replace

state: "{{states('compteur_eau') }}"

by

state: "{{states('compteur_eau_4') }}"

You’ve got to have all the attributes defined as explained in order to make it recognized by Energy panel

The counter that receives the increment is indeed in “compteur_eau_4”

#Compteur eau 4 
  - name: compteur_eau_4
    state_address: "9/7/3"
    unit_of_measurement: m³
    device_class: water
    state_class: total_increasing
    state: "{{states('compteur_eau_4')}}"

(I did not indicate “template” in my code)

I have this error message
Invalid config for [knx]: [template] is an invalid option for [knx]. Check: knx->knx->template. (See /config/configuration.yaml, line 7).

You don’t have yet defined a template sensor, this is key. And you can’t have a template sensor having the same same as the sensor that receives the increments. So “whatever name” can be anything but compteur_eau_4. For reference: Template
If you don’t have a template file, put the code I gave you (with some modification), directly in configuration.yaml
Remember to reload template entities; As soon it is done in developer tools/states, you’ll see your new sensor. Then you’ll be able to add it to energy panel

configuration.yaml

template:
  - sensor:
      - name: compteur_eau
        unit_of_measurement: m³
        device_class: water
        state_class: total_increasing
        state: "{{states('compteur_eau_4')}}

(the name “compteur_eau” is the name of the meter which receives the increment and which is in the knx_sensor.yaml file)

error message
Value is not accepted. Valid values: “apparent_power”, “aqi”, “battery”, “carbon_dioxide”, “carbon_monoxide”, “current”, “date”, “duration”, “energy”, “frequency”, “gas”, “humidity”, “illuminance”, “monetary”, “nitrogen_dioxide”, “nitrogen_monoxide”, “nitrous_oxide”, “ozone”, “pm1”, “pm10”, “pm25”, “power”, “power_factor”, “pressure”, “signal_strength”, “sulphur_dioxide”, “temperature”, “timestamp”, “volatile_organic_compounds”, “voltage”

Double quote is missing at the end of the state statement.
I’m a bit puzzled. In a previous post it is written:

Then here in the last post it is written:

(the name “compteur_eau” is the name of the meter which receives the increment and which is in the knx_sensor.yaml file).

So if “compteur_eau” is the name of the counter (or the meter) that
receives the increments, then it should be:

template:
  - sensor: 
    - name: eau
      unit_of_measurement: m³
      device_class: water
      state_class: total_increasing
      state: "{{states('compteur_eau') }}"

“eau” entity (you may name it as you wish, but compteur_eau) will be created taking it’s value from the state of “compteur_eau”. It the meter reports liters, and since unit of measurement is m3 you have to divide the value by 1000. So it shall be:

      state: "{{states('compteur_eau') | multiply(0.001) }}"

The quotation mark is in the code but forgotten in the copy/paste.
I have two knx addresses with a meter value in liters and a value in m3
knx_sensor.yam

#Compteur eau (litres)
  - name: compteur_eau
    state_address: "9/7/12"
    type: "volume_liquid_litre"
    sync_state: every 30
 
#Compteur eau (m3)
  - name: eau_m3
    state_address: "9/7/3"
    type: "volume_m3"
    sync_state: every 30

I just noticed that the m3 value goes up incorrectly in an HA entity. So I modified the code to use the value in liters

configuration.yaml

template:
  - sensor:
      - name: eau
        unit_of_measurement: L
        device_class: water
        state_class: total_increasing
        state: "{{states('compteur_eau')}}"

I always have an error message for the device class

Value is not accepted. Valid values: “apparent_power”, “aqi”, “battery”, “carbon_dioxide”, “carbon_monoxide”, “current”, “date”, “duration”, “energy”, “frequency”, “gas”, “humidity”, “illuminance”, “monetary”, “nitrogen_dioxide”, “nitrogen_monoxide”, “nitrous_oxide”, “ozone”, “pm1”, “pm10”, “pm25”, “power”, “power_factor”, “pressure”, “signal_strength”, “sulphur_dioxide”, “temperature”, “timestamp”, “volatile_organic_compounds”, “voltage”

In the sensor device class documentation, the water class exists

volume: Generic volume in L, mL, gal, fl. oz., m³, or ft³
water: Water consumption in L, gal, m³, or ft³

Are you using an older version than 2022.11 ?

Home Assistant 2022.11.4
Supervisor 2022.11.2
Operating System 9.3
Interface utilisateur : 20221108.0 - latest

I removed this part in configuration.yaml

#template:
 # - sensor:
     #- name: eau
       # unit_of_measurement: L
       # device_class: water
       # state_class: total_increasing
       # state: "{{states('compteur_eau')}}"

I modified in knx_sensor.yaml

#Compteur eau (litres)
  - name: compteur_eau
    state_address: "9/7/12"
    type: "volume_liquid_litre"
    state_class: total_increasing
    sync_state: every 30

I created a “utility meter” helper with the “compteur_eau” input sensor and HA created the following entities

I still cannot add a water source in the Energy dashboard

Let’s try to clarify some stuff. But before may I kindly ask whether you are familiar with templates?

The Energy panel requires a sensor with all attributes as specified in a previous post (please refer to it). Anything you do that is not following these rules including the unit in m³ will go nowhere.

This is why it is needed to derive a new sensor based on the water meter.

So I defined a meter (counter.eau) that is incremented by an automation whenever a on to off condition is detected that is every new liter. Please adapt the code depending on the hardware.

- id: 532445d2-a9a1-4a1d-9b6d-e7c14b82a666
  alias: Shelly Uni IN2
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.shelly_uni_channel_2_input
    from: "on"
    to : "off"
  condition: []
  action:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.eau
  mode: single

and a template sensor is defined in order to feed Energy panel

  - name: Consommation eau
    unit_of_measurement: m³
    device_class: water
    state_class: total_increasing
    state: "{{states('counter.eau') | multiply(0.001) }}"

Most probably your meter reports liters however the template sensor has to be set in m³ because Energy panel is waiting for this unit (or ft³) hence the multiply (0.001). Please note that Energy panel will report liters.

I progressed with the gas consumption which now worksand ; I tried to reproduce the same for the water consumption but I encounter a problem.

knx_sensor.yaml

#Compteur gaz 
  - name: compteur_gaz
    state_address: "9/7/1"
    type: "volume"
    sync_state: every 30
    state_class: total_increasing

#Compteur eau (litres)
  - name: compteur_eau
    state_address: "9/7/12"
    type: "volume_liquid_litre"
    sync_state: every 30
    state_class: total_increasing

customize.yaml

sensor.compteur_gaz:
  device_class: gas
  unit_of_measurement: "m³"

sensor.compteur_eau:
   unit_of_measurement: "m³"
   device_class: water
   state: "{{states('compteur_eau') | multiply(0.001) }}"

the device class “water” is not accepted and I have this error message

Value is not accepted. Valid values: “apparent_power”, “aqi”, “awning”, “battery”, “battery_charging”, “blind”, “carbon_dioxide”, “carbon_monoxide”, “cold”, “connectivity”, “current”, “curtain”, “damper”, “date”, “door”, “duration”, “energy”, “frequency”, “garage”, “garage_door”, “gas”, “gate”, “heat”, “humidity”, “illuminance”, “light”, “lock”, “moisture”, “monetary”, “motion”, “moving”, “nitrogen_dioxide”, “nitrogen_monoxide”, “nitrous_oxide”, “occupancy”, “opening”, “outlet”, “ozone”, “plug”, “pm1”, “pm10”, “pm25”, “power”, “power_factor”, “presence”, “pressure”, “problem”, “receiver”, “running”, “safety”, “shade”, “shutter”, “signal_strength”, “smoke”, “sound”, “speaker”, “sulphur_dioxide”, “switch”, “tamper”, “temperature”, “timestamp”, “tv”, “update”, “vibration”, “volatile_organic_compounds”, “voltage”, “window”.

The device class “water” is well mentioned in the documentation sensor (devices)
The problem is the same with the device class “volume”

why don’t you use a template sensor as advised (code directly in configuration.yaml?

template:
  - sensor:
      - name: eau
        unit_of_measurement: m³
        device_class: water
        state_class: total_increasing
        state: "{{states('compteur_eau') | multiply(0.001) }}