I’m pretty sure that the statistics required states need to go in your home assistant config, not the esphome one.
It looks correct. Maybe use only single quotes not double. I do not use any quotes and it works. You may need a statistics sensor, but it should at least show up in the dropdown.
sensor:
- platform: statistics
entity_id: sensor.water_consumption
state_characteristic: mean
sampling_size: 20
Not sure why the devs made it so darn complicated!
I managed to get data for water consumption but somehow very strange
Based on following incomplete ESPHome device config
sensor:
- platform: pulse_counter
pin:
number: D4
mode: INPUT_PULLUP
count_mode:
rising_edge: DISABLE
falling_edge: INCREMENT
name: 'Conso Eau Potable'
id: 'h2oPotable'
unit_of_measurement: 'L'
icon: 'mdi:water'
internal_filter: 10ms
state_class: measurement
filters:
- lambda: |-
if(x==0){
return {};
} else {
return x;
}
total:
name: 'Eau Potable : volume total'
device_class: water
state_class: total_increasing
unit_of_measurement : m³
filters:
- multiply: 0.001
- platform : integration
name : testintegration
sensor: h2oPotable
time_unit: min
device_class: water
state_class: total
unit_of_measurement : m³
I got the following results in the dashboard
The sensor used is “testintegration” , what’s the prb (except negative value & very high values)
Thx
I created statistics and it indeed shows up. Strange however that this wasn’t needed for my gas consumption.
Also the configuration for water in the energy dashboard it gives the warning:
Last reset missing. The following entities have state class ‘measurement’ but ‘last_reset’ is missing:…
I’m not sure if that is a problem?
FYI, I added the new water device class and converted to m3, below works for gas and water:
sensor:
# Device class, icon, and accuracy are not inherited from main sensor, manually repeat
- platform: pulse_meter
pin:
number: GPIO32
mode: INPUT_PULLUP
internal_filter_mode: PULSE
internal_filter: 100ms
timeout: 60s
unit_of_measurement: 'gal/min'
accuracy_decimals: 3
name: ${device_name}_water_meter
icon: 'mdi:water'
filters:
- multiply: 10
total:
name: ${device_name}_water_meter_total
icon: 'mdi:water'
device_class: 'water'
id: water_total
unit_of_measurement: 'gal'
accuracy_decimals: 3
filters:
- multiply: 10
- platform: pulse_meter
pin:
number: GPIO33
mode: INPUT_PULLUP
internal_filter_mode: PULSE
internal_filter: 100ms
timeout: 60s
unit_of_measurement: 'ft³/min'
accuracy_decimals: 3
name: ${device_name}_gas_meter
icon: 'mdi:fire'
filters:
- multiply: 10
total:
name: ${device_name}_gas_meter_total
icon: 'mdi:fire'
device_class: 'gas'
id: gas_total
unit_of_measurement: 'ft³'
accuracy_decimals: 3
filters:
- multiply: 10
# https://esphome.io/components/sensor/template.html
# TODO: l unit for water is not used, m³ is used, remove l when no longer needed
- platform: template
name: ${device_name}_water_meter_total_l
icon: 'mdi:water'
device_class: 'water'
state_class: 'total_increasing'
accuracy_decimals: 3
unit_of_measurement: 'l'
# Convert gal to l
lambda: |-
return id(water_total).state / 3.785;
- platform: template
name: ${device_name}_water_meter_total_m3
icon: 'mdi:water'
device_class: 'water'
state_class: 'total_increasing'
accuracy_decimals: 3
unit_of_measurement: 'm³'
# Convert gal to m³
lambda: |-
return id(water_total).state / 0.003785;
- platform: template
name: ${device_name}_gas_meter_total_m3
icon: 'mdi:fire'
device_class: 'gas'
state_class: 'total_increasing'
accuracy_decimals: 3
unit_of_measurement: 'm³'
# Convert ft³ to m³
lambda: |-
return id(gas_total).state / 35.315;
I think there are a few issues in this thread, but for me, I was not able to add my ESPHome water sensor with the “gl” unit_of_measurement
when I changed it according to the dropdown hint. (I read ‘gl’ as an abbreviation for gallons, even though I’ve never seen that either).
I changed the unit_of_measurement
in my ESPHome yaml to m³
and It was found. I tried changing it back to ‘gl’ to see what would happen, and I got this warning
So even though the dropdown “hint” asks for ‘gl’ or ‘m³’, the warning says it wants ‘m³ or ’ ft³’. If I change the unit_of_measurement
in ESPHome to ‘gal’ it also works.
Here’s my working ESPHome water configuration:
- platform: pulse_counter
pin: D1
accuracy_decimals: 2
unit_of_measurement: 'GPH'
update_interval: 1s
name: "Main Water"
id: main_water
icon: mdi:water
filters:
# 330 pulses/L .00303 L/m * 15.8503 to get GPH
- multiply: 0.048031212
total:
unit_of_measurement: 'gal'
name: 'Total Main Water'
id: total_main_water
icon: mdi:water
device_class: water
filters:
# 330 pulses/L 3.78541 L/G
- multiply: 0.0008005217
So my problem was just confusion between what the dropdown says vs the warning vs what it really wants in addition to a lack of documentation here Integrating your water usage - Home Assistant (or maybe I just completely missed the relevant documentation). Hope it helps someone.
I’ve tried various things based on information in this thread, but still have no relevant data in my Energy Dashboard for water section. Could someone help with a full example ESPHome yaml and Configuration.yaml or help me correcting my mistakes.
relevant part of my ESPHome yaml (for ESP8266 with NPN sensor):
relevant part of configuration.yaml:
Exact same issue here too, nothing comes in. Made sure i had some usage but no luck so far. Dashboard does say it can take up to 2 hours but since this data is coming in i assume that doesn’t matter. I left it on for a day too, no change.
Can anyone that has the dropdown list filled, show the content of the entiity? In what format it comes in, so we can compare?
Apparently, it is a problem indeed. After almost a day water consumption in the energy panel is still at 0 while the sensor (and statistics) reports more than 0 usage.
I’ve been tracking water data for some time, and had an existing sensor with gallons
as my unit. When switching to this energy dashboard method, I changed the units to gal
, and set the appropriate device_class
and state_class
, but the sensor still wasn’t showing in the dropdown.
It looks like I also had to update the units for previously stored datapoints. In Developer
→ Statistics
I performed the following, and was able to select my sensor:
Waw, I just found that panel and wanted to share it here! But you beat me to it.
This fixed it for me.
Hi everybody,
same problem, no water consumption showing in energy panel.
6 times checked configuration.yaml. Finally, I check the stats in the developer tools. There was some problem with my water entity and I fixed it.
Since then, my water and energy consumption have appeared immediately.
He He Erik-Jan, how are things?
I have used @PatBat it’s proposal, the 5th in this thread.
Added into the configuration yaml file. The water meter came up.
The issue with the m³ instead of L is not solved yet.
I do agree with others, why is it so hard to add this energy sensor. All the others came up, no issue!
I also want to know about @Duky his solutions and more guideline to understand what needs to be fixed?!
I tried several suggestions in this thread, only @PatBat solution with the template sensor seems to work. I have an MQTT sensor having the water usage data:
- name: Water Total
state_topic: iobroker/gruenbeck/0/calculated/Wasserzaehler
unique_id: "gruenbeck-wasserverbrauch"
icon: "mdi:water-pump"
unit_of_measurement: m³
device_class: volume
state_class: total_increasing
for which I need to create the same template sensor to have the entity in the energy dashboard shown up:
template:
- sensor:
- name: "water counter"
state: "{{ states('sensor.water_total') }}"
unit_of_measurement: m³
device_class: water
state_class: total_increasing
This does not seem right, I probably miss here something obvious. My MQTT sensor shows up properly in the Developer Tools/Statistics tab without any problems to be fixed. I also tried different device_class values.
Can someone point me to the source code which suppose to handle this case?
Can’t you change your MQTT sensor’s device_class to water?
- name: Water Total
state_topic: iobroker/gruenbeck/0/calculated/Wasserzaehler
unique_id: "gruenbeck-wasserverbrauch"
icon: "mdi:water-pump"
unit_of_measurement: m³
device_class: water
state_class: total_increasing
I tried that too.
Edit: funnily it now shows up after I changed it to water. I had water there initially without success and after that I tried different device_class values. Whatever, it seems to work now, black magic
Edit2: I have removed the Template sensor rebooted and now the MQTT is gone again. This really drives me crazy.
Looks like water usage data is now showing up in my Energy Dashboard… Hopefully it sticks and will be accurate… I’ll update this message when not…
I started all over in ESPHome (ESP8266 Wemos D1 Mini with a simple NPN sensor) based on parts in this thread. I used all new names / IDs. I removed everything from configuration.yaml. The following is what I now have in ESPHome:
The Water Consumption ‘metric’ was immediately visible in the drop down list. No error messages appeared in the following hours. Data started to flow in in next hours.
I’ve manually added the water usage earlier today (by changing 1 value from 0.0 to 0.17m3 in the statistics via Developer → Statistics)