Energy, help with water and gas management

Guys , i have a sensor with scan interval every 60 seconds

The value1 is the water used for today in L , and the value2 is the gas used today in m3 , need divided to /100 … The values are resetted to 0 each day

How can i make sensors from it , so they can be used in energy management? Will it give problems that they are resetted to 0 each time? I have it now configured as below…

sensor:

  - name: Smappee Water Consumption
    unit_of_measurement: "L"
    state_class: total_increasing
    device_class: water
    state: >-
      {{ state_attr('sensor.smappee_water_gas', 'records')[0]["value1"] }}

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

is that enough?

thnx

If you want to add gas and water to the energy dashboard, the values needs to be of the state_class total_increasing (= increasing total sum of usage in kWh or m3).
Resetting every day is not total_increasing, so that will not work for the dashboard.
Can’t you get the real meter readings from the smappee device/integration?
Those values are total_increasing and can be using in the energy dashboard.

hi, no thats the problem, the smappee integration doesnt provide gas/water, those values are only online, i created a rest sensor to retrieve them with the API they supply…
How can i proceed now then?

Just my first idea.
First you need a dirivate sensor with the current sensor as input and filter out negative values. The result is that you only get changes. This way the daily reset is filtered out.
The second step is a integration sensor that adds up al the values from the derivate sensor.
The result is a sensor of which the value is total_increasing.
Can you try this approach?

this is all new to me, need to google a lot now :slight_smile:

I think the API from smappee also allow to retrieve the water/gas values from last hour only, and not the total from the day , then i can make an integration sensor that just sums up ? isnt that easier maybe?

Yes, if the consumption per hour is available, thats better to use.
Is the last_hour value resetting every hour or constantly updating?
You need to understand when you need to poll (via the rest sensor).

Leys say i have hourly status:

should this do it?

  - name: Smappee Water Consumption
    unit_of_measurement: "L"
    state_class: total
    device_class: water
    state: >-
      {{ state_attr('sensor.smappee_water_gas', 'records')[0]["value1"] }}
  - platform: integration
    source: sensor.smappee_water_consumption
    name: water_consumption

no, if there is no water used, there is no json record to retrieve

Yes, with 3 changes

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

ok, i have it now like below, for template sensor:

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

and sensor:

  - platform: integration
    source: sensor.smappee_water_consumption
    name: water_consumption_l
    
  - platform: integration
    source: sensor.smappee_gas_consumption
    name: gas_consumption_m3

is that ok? dont i need to define gas/water device class somewhere? you removed it?

A few changes

  • water has also m3 as unit
  • removed /1000 in gas and added /1000 in water
  • use float(0) for both sensors
  • to used the same value1, i changed that

That results in:

- 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"]/1000 | float(0) }}
      {% 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) }}
      {% endif %}

And indeed you need the rest sensor to get the hourly values (sensor.smappee_water_gas)

ok, thnx gonna try!! But why cant i use L as unit? isnt that working?

The integration sensors, those i can use to add to energy dashboard?
and indeed, its now hourly

To add water to the energy dashboard you need to use m³ or gl (gallon).
And the dashboard makes in UI, L or gl of it

1 Like

cool, lets try!

This line

      {{ state_attr('sensor.smappee_water_gas', 'records')[0]["value1"]/1000 | float(0) }}

needs to be

      {{ state_attr('sensor.smappee_water_gas', 'records')[0]["value1"]|float(0)/1000 }}

Ah, what’s the difference? I putted them both in template editor and they provide same result?

That’s only to make sure that state_attr(‘sensor.smappee_water_gas’, ‘records’)[0][“value1”] is a number when deviding by 1000. But when it’s already a number, is makes no difference

1 Like

Ok…
The integration sensor, is that a sensor that’s counted up? Or is the value also resetted every hour?

Also the total_increasing, is that correct? Since it doesn’t actually increase, it’s always a static value from past hour…