Utility Meter - keep values after restart

Hi,

I’m using the newly introduced Utility Meter.
But as soon as I restart Hassio, the meter is reset to 0 for that day. Is there any way to not reset this meter upon restart?

Thanks
Cadsih

I’m using this component with Integration Sensor and the states don’t reset on restart.

I have also excluded the sensors and the Utility Meter sensors from recorder, but the values are conserved.

Maybe @dgomes knows why?

It uses the restore state functionality which is independent of the recorder (uses a file in .storage to save the last value only)

@Cadish can you share your configuration to try and trace why it resets ? (it should not)

1 Like

Thanks for this fast reply.
Is it possible to reset the integration sensors?

no such functionality for the integration sensor, sorry

the utility_meter sensors can be reset through a service call if you define tariff’s.

Thanks @dgomes for your reply.

Here’s an extract from my configuration. I didn’t post the full configuration as it’s pretty big… Just the parts I think matter.

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: XXXXXXXXXX
  longitude: XXXXXXXXXX
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: XXXXXXXXXX
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: 'Europe/Brussels'
  # Customization file
  customize: !include customize.yaml

# Enables the frontend
frontend:

# Enables configuration UI
config:

# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
#conversation:

# Enables support for tracking state changes over time
history:

# View all events in a logbook
logbook:

# Enables a map showing the location of tracked devices
#map:

# Track the sun
#sun:

utility_meter:
  solar_energy_daily:
    source: sensor.total_yield
    cycle: daily

sensor:
# Zonnepanelen
  - platform: sma
    host: '192.168.86.30'
    password: !secret pass_zonnepanelen
    ssl: true
    verify_ssl: false
    group: user
    scan_interval: 120
    sensors:
      grid_power:
      total_yield:

# Kamerdefinities
group: !include groups.yaml

scene: !include scenes.yaml

automation: !include automations.yaml

script: !include scripts.yaml

recorder: 
  purge_keep_days: 730

BTW, this is what I see in the file core.restore_state in the .storage folder:

{
    "last_seen": "2019-02-08T18:06:45.084005+00:00",
    "state": {
        "attributes": {
            "friendly_name": "solar_energy_daily",
            "icon": "mdi:counter",
            "last_period": 0,
            "last_reset": "2019-02-07T20:37:22.918326+01:00",
            "meter_period": "daily",
            "source": "sensor.total_yield",
            "status": "collecting"
        },
        "context": {
            "id": "e134b59bee404e36af119e20b4f65771",
            "user_id": null
        },
        "entity_id": "sensor.solar_energy_daily",
        "last_changed": "2019-02-08T18:06:39.252134+00:00",
        "last_updated": "2019-02-08T18:06:39.253943+00:00",
        "state": "0"
    }
},

OK clearly the reason why it resets is that core.restore_state is storing "state": "0"

Can you during the day check if that value is updated ? and if it is, reset hassio to check if it is restored properly (to a non 0 state)

Thanks. Is it supposed to update constantly during the day, without me doing anything? If that’s the case: it stays 0… This file hasn’t updated since yesterday…

Yes it is supposed to update every 15min

what about the dates ? Can you share the current core.restore_state ?

It just updated yesterday evening at 19:06 for the last time…

{
"data": [
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Middernacht",
                "initial": null,
                "max": 999999999.0,
                "min": 0.0,
                "mode": "slider",
                "step": 1.0
            },
            "context": {
                "id": "4f8aa18579004fb6b65bd9c28b22e5f5",
                "user_id": null
            },
            "entity_id": "input_number.solar_kwh_middernacht",
            "last_changed": "2019-02-08T18:06:39.184500+00:00",
            "last_updated": "2019-02-08T18:06:39.184500+00:00",
            "state": "112.573"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "solar_energy_daily",
                "icon": "mdi:counter",
                "last_period": 0,
                "last_reset": "2019-02-07T20:37:22.918326+01:00",
                "meter_period": "daily",
                "source": "sensor.total_yield",
                "status": "collecting"
            },
            "context": {
                "id": "e134b59bee404e36af119e20b4f65771",
                "user_id": null
            },
            "entity_id": "sensor.solar_energy_daily",
            "last_changed": "2019-02-08T18:06:39.252134+00:00",
            "last_updated": "2019-02-08T18:06:39.253943+00:00",
            "state": "0"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Beneden uit via knop overloop",
                "last_triggered": null
            },
            "context": {
                "id": "b45aa26dae6a43ffad06cbe933eb8a33",
                "user_id": null
            },
            "entity_id": "automation.beneden_uit_via_knop_overloop",
            "last_changed": "2019-02-08T18:06:39.776640+00:00",
            "last_updated": "2019-02-08T18:06:39.776640+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Goedemorgen aan via knop overloop",
                "last_triggered": null
            },
            "context": {
                "id": "edb1eb8be71e4e6c95c8a5d103b84a73",
                "user_id": null
            },
            "entity_id": "automation.goedemorgen_aan_via_knop_overloop",
            "last_changed": "2019-02-08T18:06:39.779661+00:00",
            "last_updated": "2019-02-08T18:06:39.779661+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Goedemorgen aan via knop keuken",
                "last_triggered": null
            },
            "context": {
                "id": "2c80d77d75ec4084b5ef47d823356328",
                "user_id": null
            },
            "entity_id": "automation.goedemorgen_aan_via_knop_keuken",
            "last_changed": "2019-02-08T18:06:39.782658+00:00",
            "last_updated": "2019-02-08T18:06:39.782658+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Open rooftop window in the bathroom when moisture is detected",
                "last_triggered": null
            },
            "context": {
                "id": "1ba25539dbdb462e99a10e46879826c2",
                "user_id": null
            },
            "entity_id": "automation.open_rooftop_window_in_the_bathroom_when_moisture_is_detected",
            "last_changed": "2019-02-08T18:06:39.785817+00:00",
            "last_updated": "2019-02-08T18:06:39.785817+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Notify when leaving and the front door is still open",
                "last_triggered": null
            },
            "context": {
                "id": "354e1d099ed945fb9c463df5b804eec4",
                "user_id": null
            },
            "entity_id": "automation.notify_when_leaving_and_the_front_door_is_still_open",
            "last_changed": "2019-02-08T18:06:39.788819+00:00",
            "last_updated": "2019-02-08T18:06:39.788819+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Turn on light in wc upon motion detected",
                "last_triggered": null
            },
            "context": {
                "id": "f54ee132b0f0460c97d7f6f83538b802",
                "user_id": null
            },
            "entity_id": "automation.turn_on_light_in_wc_upon_motion_detected",
            "last_changed": "2019-02-08T18:06:39.791786+00:00",
            "last_updated": "2019-02-08T18:06:39.791786+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Turn off light in wc after 3 minutes no motion detected",
                "last_triggered": null
            },
            "context": {
                "id": "39d400dd9e6d4c95abf6394fecd8043a",
                "user_id": null
            },
            "entity_id": "automation.turn_off_light_in_wc_after_3_minutes_no_motion_detected",
            "last_changed": "2019-02-08T18:06:39.794739+00:00",
            "last_updated": "2019-02-08T18:06:39.794739+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Turn on light in dressing upon motion detected",
                "last_triggered": null
            },
            "context": {
                "id": "439d9fb9943c48a58dd405f9b88314fc",
                "user_id": null
            },
            "entity_id": "automation.turn_on_light_in_dressing_upon_motion_detected",
            "last_changed": "2019-02-08T18:06:39.797609+00:00",
            "last_updated": "2019-02-08T18:06:39.797609+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Turn off light in dressing after 3 minutes no motion detected",
                "last_triggered": null
            },
            "context": {
                "id": "95ba364f69bc47f3b98cad8d039887be",
                "user_id": null
            },
            "entity_id": "automation.turn_off_light_in_dressing_after_3_minutes_no_motion_detected",
            "last_changed": "2019-02-08T18:06:39.800473+00:00",
            "last_updated": "2019-02-08T18:06:39.800473+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Turn on light in berging upon motion detected",
                "last_triggered": null
            },
            "context": {
                "id": "50390d3dd3094d95a4d4ee3ec1ef9b45",
                "user_id": null
            },
            "entity_id": "automation.turn_on_light_in_berging_upon_motion_detected",
            "last_changed": "2019-02-08T18:06:39.803461+00:00",
            "last_updated": "2019-02-08T18:06:39.803461+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Turn off light in berging after 3 minutes no motion detected",
                "last_triggered": null
            },
            "context": {
                "id": "ef49fc4c798f40849fd158b3cc7cbd0e",
                "user_id": null
            },
            "entity_id": "automation.turn_off_light_in_berging_after_3_minutes_no_motion_detected",
            "last_changed": "2019-02-08T18:06:39.806341+00:00",
            "last_updated": "2019-02-08T18:06:39.806341+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Sla kWh stand zonnepanelen op om middernacht",
                "last_triggered": null
            },
            "context": {
                "id": "5848633860ed4518997f58a669920368",
                "user_id": null
            },
            "entity_id": "automation.sla_kwh_stand_zonnepanelen_op_om_middernacht",
            "last_changed": "2019-02-08T18:06:39.809200+00:00",
            "last_updated": "2019-02-08T18:06:39.809200+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Notify when door opens and no one is home",
                "last_triggered": null
            },
            "context": {
                "id": "3775368ce1714525836716a4fff434f4",
                "user_id": null
            },
            "entity_id": "automation.notify_when_door_opens_and_no_one_is_home",
            "last_changed": "2019-02-08T18:06:39.812072+00:00",
            "last_updated": "2019-02-08T18:06:39.812072+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Warm auto op via Google Calendar event",
                "last_triggered": null
            },
            "context": {
                "id": "f77f80e3e1f1487abb81545307fcb97a",
                "user_id": null
            },
            "entity_id": "automation.warm_auto_op_via_google_calendar_event",
            "last_changed": "2019-02-08T18:06:39.814929+00:00",
            "last_updated": "2019-02-08T18:06:39.814929+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Lights on when someone comes home",
                "last_triggered": null
            },
            "context": {
                "id": "37ab8d902bec48398aa8b7b3435a827e",
                "user_id": null
            },
            "entity_id": "automation.lights_on_when_someone_comes_home",
            "last_changed": "2019-02-08T18:06:39.817902+00:00",
            "last_updated": "2019-02-08T18:06:39.817902+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Warm de kamers op in de ochtend",
                "last_triggered": null
            },
            "context": {
                "id": "f9d5457ce2e142219fc4ab347e1d54a3",
                "user_id": null
            },
            "entity_id": "automation.warm_de_kamers_op_in_de_ochtend",
            "last_changed": "2019-02-08T18:06:39.820750+00:00",
            "last_updated": "2019-02-08T18:06:39.820750+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Koel de kamers af in de avond",
                "last_triggered": null
            },
            "context": {
                "id": "df0eed2b29f6454088105bfc49ede45c",
                "user_id": null
            },
            "entity_id": "automation.koel_de_kamers_af_in_de_avond",
            "last_changed": "2019-02-08T18:06:39.823621+00:00",
            "last_updated": "2019-02-08T18:06:39.823621+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Open de gordijnen door knop keuken",
                "last_triggered": null
            },
            "context": {
                "id": "98d87b865be74adda70288f6bc6c6e02",
                "user_id": null
            },
            "entity_id": "automation.open_de_gordijnen_door_knop_keuken",
            "last_changed": "2019-02-08T18:06:39.826545+00:00",
            "last_updated": "2019-02-08T18:06:39.826545+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Send notification if a person is detected on TV",
                "last_triggered": null
            },
            "context": {
                "id": "adb72f1bda544ebba255ca24fe4d567c",
                "user_id": null
            },
            "entity_id": "automation.send_notification_if_a_person_is_detected_on_tv",
            "last_changed": "2019-02-08T18:06:39.829392+00:00",
            "last_updated": "2019-02-08T18:06:39.829392+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Sluit de gordijnen door knop keuken",
                "last_triggered": null
            },
            "context": {
                "id": "10b250b24541462ca6ec44d23632e6a8",
                "user_id": null
            },
            "entity_id": "automation.sluit_de_gordijnen_door_knop_keuken",
            "last_changed": "2019-02-08T18:06:39.832353+00:00",
            "last_updated": "2019-02-08T18:06:39.832353+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Reboot Nest Hello when it goes offline",
                "last_triggered": null
            },
            "context": {
                "id": "c8d326961100488f8e1268f5ea6192dc",
                "user_id": null
            },
            "entity_id": "automation.reboot_nest_hello_when_it_goes_offline",
            "last_changed": "2019-02-08T18:06:39.835209+00:00",
            "last_updated": "2019-02-08T18:06:39.835209+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Alles uit via voor- en achterdeur",
                "last_triggered": null
            },
            "context": {
                "id": "20c40a2a00a04a3fbc94d231fc54a0c9",
                "user_id": null
            },
            "entity_id": "automation.alles_uit_via_voor_en_achterdeur",
            "last_changed": "2019-02-08T18:06:39.838073+00:00",
            "last_updated": "2019-02-08T18:06:39.838073+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Set scene TV kijken indien TV speelt na 20u30",
                "last_triggered": null
            },
            "context": {
                "id": "8f84ce20991c47a483ed8e585b58a87b",
                "user_id": null
            },
            "entity_id": "automation.set_scene_tv_kijken_indien_tv_speelt_na_20u30",
            "last_changed": "2019-02-08T18:06:39.840954+00:00",
            "last_updated": "2019-02-08T18:06:39.840954+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Reset volume at 4AM",
                "last_triggered": null
            },
            "context": {
                "id": "17cca4eddd1a4f4587dff7663204a4ea",
                "user_id": null
            },
            "entity_id": "automation.reset_volume_at_4am",
            "last_changed": "2019-02-08T18:06:39.843792+00:00",
            "last_updated": "2019-02-08T18:06:39.843792+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Tesla Model S location tracker",
                "gps_accuracy": 0,
                "id": "XXXXXXXX",
                "latitude": XXXXX,
                "longitude": XXXXXXX,
                "name": "Tesla Model S location tracker",
                "source_type": "gps",
                "trackr_id": "XXXXXX"
            },
            "context": {
                "id": "XXXXXX",
                "user_id": null
            },
            "entity_id": "device_tracker.tesla_model_s_XXXXXXX_location_tracker",
            "last_changed": "2019-02-08T18:06:39.959446+00:00",
            "last_updated": "2019-02-08T18:06:44.932824+00:00",
            "state": "home"
        }
    },
    {
        "last_seen": "2019-02-08T18:06:45.084005+00:00",
        "state": {
            "attributes": {
                "battery": 30,
                "friendly_name": "My iPhone",
                "gps_accuracy": 65,
                "latitude": XXXXX,
                "longitude": XXXXXXXX,
                "source_type": "gps"
            },
            "context": {
                "id": "XXXXX",
                "user_id": null
            },
            "entity_id": "device_tracker.my_iphone",
            "last_changed": "2019-02-08T18:06:39.962726+00:00",
            "last_updated": "2019-02-08T18:06:39.962726+00:00",
            "state": "home"
        }
    },
    {
        "last_seen": "2019-02-05T17:11:16.797593+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Turn off light in dressing after 2 minutes no motion detected",
                "last_triggered": null
            },
            "context": {
                "id": "b64c8050fd3b4e8688d2f363d563b514",
                "user_id": null
            },
            "entity_id": "automation.turn_off_light_in_dressing_after_2_minutes_no_motion_detected",
            "last_changed": "2019-02-05T17:11:06.815959+00:00",
            "last_updated": "2019-02-05T17:11:06.815959+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-05T17:11:16.797593+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Turn off light in berging after 2 minutes no motion detected",
                "last_triggered": null
            },
            "context": {
                "id": "f0e6add459e84c2aa1b79e3c4dfe73cc",
                "user_id": null
            },
            "entity_id": "automation.turn_off_light_in_berging_after_2_minutes_no_motion_detected",
            "last_changed": "2019-02-05T17:11:06.818845+00:00",
            "last_updated": "2019-02-05T17:11:06.818845+00:00",
            "state": "off"
        }
    },
    {
        "last_seen": "2019-02-05T17:11:16.797593+00:00",
        "state": {
            "attributes": {
                "friendly_name": "Turn off light in wc after 2 minutes no motion detected",
                "last_triggered": null
            },
            "context": {
                "id": "97fa2a99cd904c91b79467399dbd3f6a",
                "user_id": null
            },
            "entity_id": "automation.turn_off_light_in_wc_after_2_minutes_no_motion_detected",
            "last_changed": "2019-02-05T17:11:06.862092+00:00",
            "last_updated": "2019-02-05T17:11:06.862092+00:00",
            "state": "off"
        }
    }
],
"key": "core.restore_state",
"version": 1

}

All your entries are from yesterday! I would say your problem is larger then utility_meter :frowning:

Did you do any more changes to your configuration ?

No other changes except for sensors, lights and switches…

  • do a backup of the file.
  • stop HA
  • delete the file
  • start HA

Nope :disappointed_relieved:

It recreates the file upon start of hassio, but doesn’t get updated…

I’ve run out of ideas :cry:

The sensors work, it is the restore-state functionality that is broken. I can’t reproduce the behaviour :frowning: don’t know how to help you :frowning:

:pensive: thanks a lot for your help! I’ll try to reinstall everything and hopefully that works.

Thanks!

I’m testing the Utility Meter too.
I’m very happy to see that someone has made the effort to create this sensor. I think it is mostly working.

My feedback after testing it for some days is: I think it misses some functionality:

  • It should be accurate: when I look at the history of a daily sensor, I see that the last measurement of the day is at 11:49PM. Why not at 11:59(:59)AM? I would think that the sensor first measures the end-of-day value and then resets itself to zero. Maybe it does this, can someone confirm this?
  • It should make available the value measured at 11:59:59AM as I am mostly interested in that value. Next to the “running”-value of the ongoing day. This can probably be obtained via an automation, but this has the disadvantage that then everything must be timed perfectly: for instance, measure at 11:59:59.0, pick up the value by automation at 11:59:59.5 and reset the value to 0 at 12:00:00.0. It is better when the Utility Meter does that, less chance of errors.
1 Like

Just found the issue. Apparently if I remove my Heos media_player config, it’s working as it should be. Guess there’s something wrong with that custom component…

1 Like

Hi!

The utility_meter timings depend of the source. All calculations are event driven and triggered by the source, if the last value is sent by the source sensor at 11h59 then its at that time the utility_meter update. Resets are done at 00h00m00s but depend on the HA scheduler which is not realtime.

I don’t get your second bullet, can you explain in other terms ?