Energy, help with water and gas management

Yes, you are right. The 2 sensors are providing a net increase value.
Another scenario is without the integration sensors and use utility meters (these are helpers)

Create for water and gas each an utility sensor.
Set the Meter cycly period to ‘none’ and switch on the ‘Delta values’.

You need to calibrate the sensors with the current value (in m3). This can be done via ‘developer tool’-> services → utility_meter.calibrate.
After the calibration you can add the utility meters sensors to the Energy dashboard.

Ok, gonna try that, indeed integration sensor is now lower then the template sensor, that isn’t right…

When using utility instead of integration, isn’t it better to make my sensor getting back daily values that are increasing based on scan interval?

And then setup in utility meter , the cycle on daily?

For the Energy dashboard a sensor that is updating at least every hour is more insightfull.
The utility meters cycle must be set to: No cycle. Because you creating a utility meter with absolut meter values (= total_increasing)
Also you must switch the ‘Delta values’ on, in the ultility meter initial config.

Yeah, but the daily sensor is also increasing, my scan interval is set to 60 seconds, on the rest API command, so when I use water, the template sensor is getting updated every 60 sec. Next day it’s just back to 0…

I understood that you query the usage for the last ‘hour’. Why would you set the scan interval to 60 seconds. It’s seems logical to set it also to 1 hour. If you what faster updates for example every 5 minutes then the api query should ask for the last 5 minutes and the scan interval should also be 5 minutes.
Its important that the values your getting are the increase(usage) between the last and the current request.

Yeah, if I do 60 seconds or 1 hour as interval, it doesn’t mather, in the API call I specify a time from … to …

But gonna try some stuff :slight_smile:

Ok, then it should going to work. ‘Just’ aligning the period and query.

Hey, i had to change my rest sensor to poll daily values instead of hourly, so the value1 and value2 in below screenshot is updating every 60 seconds, and goes back to 0 next day …

Next, created template sensors, als had to divide extra /100 for the gas, to give me m3 results , and used total increasing, since they are every 60 seconds based on scan interval i can define…

  - name: Smappee Water Consumption
    unit_of_measurement: "m³"
    state_class: total_increasing
    state: >-
      {% if state_attr('sensor.smappee_water_gas', 'records') %}
      {{ state_attr('sensor.smappee_water_gas', 'records')[0]["value1"]|float(0)/1000 }}
      {% endif %}   

  - name: Smappee Gas Consumption
    unit_of_measurement: "m³"
    state_class: total_increasing
    state: >-
      {% if state_attr('sensor.smappee_water_gas', 'records') %} 
      {{ state_attr('sensor.smappee_water_gas', 'records')[0]["value2"] | float(0)/100 }}
      {% endif %}

Gives me:


So far so good … i believe…
now for the utility … i dont think i need delta values? since they increase now? and you told me i dont need to cycle?

is this correct then?

smappee_water_consumption_m3:
    source: sensor.smappee_water_consumption
    name: Smappee Water Consumption m3
    unique_id: smappee_water_consumption_m3


smappee_gas_consumption_m3:
    source: sensor.smappee_gas_consumption
    name: Smappee Gas Consumption m3
    unique_id: smappee_gas_consumption_m3

i now see unavaible…

and this in log:

2023-01-11 21:26:58.565 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform utility_meter
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 438, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 709, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 803, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/utility_meter/sensor.py", line 511, in async_added_to_hass
    dt_util.parse_datetime(state.attributes.get(ATTR_LAST_RESET))
  File "/usr/src/homeassistant/homeassistant/util/dt.py", line 188, in parse_datetime
    return ciso8601.parse_datetime(dt_str)
TypeError: argument must be str
2023-01-11 21:26:58.567 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform utility_meter
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 438, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 709, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 803, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/utility_meter/sensor.py", line 511, in async_added_to_hass
    dt_util.parse_datetime(state.attributes.get(ATTR_LAST_RESET))
  File "/usr/src/homeassistant/homeassistant/util/dt.py", line 188, in parse_datetime
    return ciso8601.parse_datetime(dt_str)
TypeError: argument must be str
2023-01-11 21:26:58.749 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up utility_meter platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 297, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 438, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 709, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 803, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/utility_meter/sensor.py", line 511, in async_added_to_hass
    dt_util.parse_datetime(state.attributes.get(ATTR_LAST_RESET))
  File "/usr/src/homeassistant/homeassistant/util/dt.py", line 188, in parse_datetime
    return ciso8601.parse_datetime(dt_str)
TypeError: argument must be str

Looks like there’s a problem with the yaml config of the utility meters. You didn’t add a cron value.
Its easier to add the utility meters via the gui.
Go to settings → devices & services → Helpers
Click ‘Create helper’ and chose utility_meter. Use the config option as described earlier

The values are not absolut values and increasing. As i understood the values are the usage in a period.

Yes and no, if I use water / gas , every 60 seconds when I do the poll, the sensor is also updated…

Maybe the error in log is coming from the fact, the first 60 seconds after restart HA the value is unknown, it only gets updated after the next scan interval… After 60 sec after restart HA

Do you poll every 60 seconds with the same from … to period?
If that period is the same and in the past, its not possible that the sensor value changes.
The water or gas is already consumed, so the values can’t change anymore.

No ,the from/to is also changed and in the API itself , it’s set to daily… so what I retrieve is always the current day… Updated every 60 sec and increasing untill 00.00 , then values are 0 again… Need to double check this tomorrow…

The from … To is based on timestamp now() - 86400 … In epoch seconds … So it’s Dynamic

Ok, thats back to the beginning. During the day increasing and resetting at midnight will not work with the utility_meter.

For tomorrow i propose to try another approach (example below for water):

  1. create a statistics sensor
- platform: statistics
  name: water delta raw
  entity_id: sensor.the_water_sensor
  state_characteristic: change
  sampling_size: 2
  1. Create a template sensor to filter negatieve values
- sensor:
  - name: water delta
    unit_of_measurement: "m³"
    icon: mdi:water
    device_class: water
    state: >
      {% set v = states('sensor.water_delta_raw')|float(0)/1000 %}
      {% if v >= 0 %}
        {{ v }} 
      {% else %}
        0
      {% endif %} 
  1. Create utility_meter with source sensor.water_delta in helper (switch delta values on and no reset cycle)
  2. Calibrate the water utility_meter to the actual value

Looks like utility_meters can’t be used as source in the dashboard.
To use the ultility_meter of step 3, create a template sensor with your utility_meter as source in the state template.

- sensor:
  - name: water sensor total increasing
    unit_of_measurement: "m³"
    icon: mdi:water
    device_class: water
    state_class: total_increasing
    state: >
      {{ states('sensor.ultility_meter') }} 

Ok, I try tomorrow, appreciated for all the help!!!

I checked and the statistic sensor is not handling well the daily reset. I will make an alternative.

1 Like

was playing with the utiliy meter, they are collecting, but for some reason i’m not able to add the gas and water sensors to energy dashboard, the 2 ones with _hourly are the utility meter … i believe its because they have the energy class missing ? how can i add it ?

You need to create 2 sensors. One for water and one for gas. The water example:

- sensor:
  - name: water sensor for energy dashboard
    unit_of_measurement: "m³"
    icon: mdi:water
    device_class: water
    state_class: total_increasing
    state: >
      {{ states('utility_meter.water') }} 

These sensors can be added to the energy dashboard