Manual input for electricity, gas and water consumption

A manual entry for electricity, gas and water consumption would be useful. in many cases you cannot create a smart solution with automatic collection of this data.
A field for the starting value and a field in which you can regularly enter the electricity, gas and water consumption in order to get a logging of the data.

I think you can do it with an Input Number - Home Assistant (described as total increasing as described on Benefit from long term statistics for any sensor and set with proper units).

Have you tested this kind of solution?

Hello, thanks for the reply.
No, unfortunately I don’t know how to implement this.
A starting value would also be important

There seems to be a soltuion: Utility Meter - take manual readings


Edit: However, when I tried to this, I got an error. Does not seem possible to use input_number as an input for a utility meter:
grafik

I got a bit further by defining a template sensor in configuration.yaml:

(First I created an “input_number” [stromablesen] helper to input the actual values)

input_number:
  stromablesen:
    initial: null
    editable: true
    min: 0
    max: 100000
    step: 1
    mode: box
    unit_of_measurement: kWh
    icon: mdi:meter-electric
    friendly_name: StromAblesen

Then I created a template sensor in Configuration.yaml:

template:
 sensor:
   name: "stromverbrauch"
   unit_of_measurement: kWh
   state_class: total_increasing
   device_class: energy
   state: "{{ states('input_number.stromablesen') }}"

I am now able to create the “Utility Meter”.

sensor:
  strom:
    state_class: total_increasing
    source: sensor.stromverbrauch
    status: collecting
    last_period: 0
    last_reset: 2022-11-04T00:33:23.138130+00:00
    unit_of_measurement: kWh
    device_class: energy
    icon: mdi:counter
    friendly_name: Strom

But still no luck in using the final “strom” Utility Meter sensor on the Energy Dashboard. I am not able to select it as a energy source.

What am I doing wrong?

Edit:
I checked the definition of the metadata on the database. The unit of measure was recorded as “KW” even though I specified “kWh” when creating the sensors. After manually modifying the database records, I was able to add the “Utility Meter” to the Energy Dashboard.

SELECT * FROM `statistics_meta` WHERE statistic_id = "sensor.strom";
40	sensor.strom	recorder	kW	0	1	NULL	

After changing the unit from “kW” to “kWh” I was able add the sensor “strom” to the energy Dashboard.

2 Likes

Hello,

so you made it Congratulation.
I want to try it too and hope you can help me.
I didn’t understand that with the database processing. am a beginner
My questions:

  1. Can I bypass the problem beforehand? Without editing a database. As ?

  2. Can I also enter meter readings from the past?

  3. Can I enter an initial meter reading? Where?

Would be nice if you can help me.

Greetings Werner

1 Like

So anyone made it to enter manual and historical data?

I found this, maybe it helps? It added a timestamp to a value, would be nice to enter older values.

1 Like

Hello,

Thanks for the answer.
Unfortunately I don’t know where to paste the code mentioned there. I would like to have an input option. The date and meter reading should then be entered there.

Greeting Werner

Hello. I’m currently setting up manual tracking of my gas / water / power consumption. I want to share my findings with you, maybe some of this is helpful.

First I have created three input_number helpers via the UI, namely input_number.gas, input_number.power and input_number.water. Yeah, I’m not very good at naming things. :smiley:

Then I have created three template sensors from these inputs:

- sensor:
  - name: "Gas"
    device_class: gas
    unique_id: "current_gas"
    unit_of_measurement: "m³"
    state: "{{ states('input_number.gas') }}"
    state_class: total_increasing
  - name: "Wasser"
    device_class: water
    unique_id: "current_water"
    unit_of_measurement: "m³"
    state: "{{ states('input_number.water') }}"
    state_class: total_increasing
  - name: "Strom"
    device_class: energy
    unique_id: "current_power"
    unit_of_measurement: "kWh"
    state: "{{ states('input_number.power') }}"
    state_class: total_increasing

Then I was able to use these sensors in my Energy Dashboard configuration:

I tried creating Utility Meter sensors before in UI and I could select them when setting up my energy dashboard but due to some misconfiguration (I assume) the consumption of the gas utility meter was not displayed. I then tried selecting the sensor directly and it looks like it is working now:

It looks like maybe there was some change in HA to the way that the energy dashboard has to be setup that I missed? But for me having input_number together with template.sensor seems to do the trick. I will report back here if something seems not right to me.


Now I’m left with the task to regularly collect my sensor data manually and I’m looking for a way to spread the difference of the value over the time since the last measurement taken. Because I will probably not take values every single day. :sweat_smile:

[EDIT]
Ist’s looking good so far. I’m currently taking readings every other or every third day. So rather infrequently. This doesn’t help me tracking my usage throughout the day, but at least with monthly to quartely accuracy.

10 Likes

That’s an awesome guide, and I guess it could be marked as solution (if the Feature Requests forum allows that lol)

I even tried adding all the properties mentioned by @yonz2, but a couple of those don’t work at utility_meter: (such as state_class and status, maybe more, I stopped trying lol)

Lastly, nowadays it’s possible to set a Utility Meter directly in the Helpers panel… but it doesn’t seem to like reading from input_number :frowning: It would be handy, so everything would be in the UI and we wouldn’t need to set a friendly name elsewhere (I’m looking at you, customize.yaml!!!)


EDIT: actually, for some odd reason (HA being HA), it’s not being able to calculate properly the cost of those manual entries, even though it can calculate just fine if I add a device’s consumption directly to that same section :thinking:
That, together with the fact the graph for individual devices is sooo poor, kinda defeats all the time I’ve lost trying to make manual energy input to work :angry:

HA is completely lost with that issue, as there are not “complaints” about some of the entities without cost, and complaints about some of the calculated ones (all of them using the same tariff entity):

image
image

1 Like

Awesome and thanks for your guide!

Did you manage to find a way to add manual inputs “backdated”?
I would like to record them every two weeks or so but inform the system on which day the data refers to.

No, I’m sorry. I haven’t found an easy solution and have given up on that task. Would still be nice to get some sort of CSV import feature.

Would this custom integration by @klaj be a possibility? It imports historic statistics (like energy data) from a CSV.

1 Like

Interesting, thanks for the link @StephenH… I didn’t try yet but have the feeling it won’t be sufficient for Energy. i.e. statistics will update but real energy consumption, counters, etc. will not
May give it a go on a test sensor and see how it works.

If anyone is interested, I posted some reasonably robust Python code to insert backdated state data into the states table. The source can be either a CSV file or a SQLite db – with 2 columns (one for timestamp in UTC, other for data to be entered)

https://community.home-assistant.io/t/enter-delayed-aka-backdated-mqtt-data-asynchronously-based-on-attached-timestamp /750485/7?u=puterboy

Please see the following link for updated version that also adds the corresponding statistics to the statistics and short_term_statistics tables.