Simple electricity meter manual input

Hi,

I am a developer and new to Home Assistant. I got very excited when I stumbled upon it.
After a few hours of sorting unix, docker, docker desktop issues, I finally got Home Assistant up and running locally on my PC.

I thought I would start with a simple electricity consumption display, with a basic input_number to enter meter readings manually, either daily or monthly.

But sadly… this… is… insanely… complicated :frowning:

There are sensors, input numbers, sensor templates, utility meters… all either in configuration.yaml or in input_nubers.yaml or other files.
I managed to create the input field to manually enter the meter reading from the Overview page of Home Assistant, but nothing happens. I have 2 sensors showing in the Sensor box: “Daily Energy” and “Monthly Energy”, but when I click on them there is no history.

And this is my configuration.yaml file.

# Loads default set of integrations. Do not remove.                                                                     default_config:                                                                                                                                                                                                                                 # Text to speech                                                                                                        
tts:                                                                                                                      
   - platform: google_translate                                                                                                                                                                                                                  automation: !include automations.yaml                                                                                   
script: !include scripts.yaml                                                                                           
scene: !include scenes.yaml                                                                                             
utility_meter:                                                                                                             
   monthly_energy:                                                                                                           
      source: sensor.energy_reading                                                                                           
      name: Monthly Energy                                                                                                    
      cycle: monthly                                                                                                       
   daily_energy:                                                                                                              
      source: sensor.energy_reading                                                                                           
      name: Daily Energy                                                                                                      
      cycle: daily                                                                                                                                                                                                                              
      
input_number:                                                                                                              
   electricity_meter_reading:                                                                                                 
      name: Electricity Meter Reading                                                                                        
      initial: 66130                                                                                                          
      min: 0                                                                                                                  
      max: 999999                                                                                                             
      step: 1                                                                                                                 
      mode: box                                                                                                               
      unit_of_measurement: kWh
template:
   - sensor:                                                                                                                  
      - name: energy_reading                                                                                                    
        unit_of_measurement: kWh                                                                                                
        device_class: energy 

I am getting this error in the logs
Invalid config for [template]: required key not provided @ data['sensor'][0]['state']. Got None. (See /config/configuration.yaml, line 32).

When I click on Energy I get “No matching statistics found” and cannot go any further.

Also no idea how and where to setup a consumption graph (monthly or daily).

Grateful for any pointers on how to do this. I searched the docs and googled but all I found were partial answers that were difficult to piece together to understand the key steps.

1 Like

You need to tell to your template sensor where it will read it’s value.
This is the state: part of the configuration, wich obviously is NOT in your configuration.

I would recommend to read : Template - Home Assistant

Then here is what’s missing from what I’ve understood of your setup :

template:
   - sensor:                                                                                                                  
      - name: energy_reading                                                                                                    
        unit_of_measurement: kWh                                                                                                
        device_class: energy 
        state: >-
          {{ states('sensor.energy_reading') | int(default=0) }}

But, if you set an initial value to your input_number it will go back to this value after every HA restart. You should not set the initial value, wich will lead to the input_number to get back the last value it has before HA restart.

2 Likes