question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Utility meter is having a bad time

See original GitHub issue

Figured I had enough time to mess around with finally configuring this today but seem to have hit a wall with the utility meters

The power and energy sensors are both working great but it has only generated some of the utility meter entities, all of which are forever stuck with a value of “unknown” and my logs get updated every few seconds with:

Logger: homeassistant.helpers.event
Source: components/utility_meter/sensor.py:176
First occurred: 7:40:51 PM (327 occurrences)
Last logged: 7:56:03 PM

Error while processing state change for sensor.electricity_used_server_rack_light_2_virtual
Error while processing state change for sensor.electricity_used_front_porch_light_1_virtual
Error while processing state change for sensor.electricity_used_back_patio_light_1_virtual
Error while processing state change for sensor.electricity_used_server_rack_light_1_virtual
Error while processing state change for sensor.electricity_used_kitchen_ceiling_light_2_virtual
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/event.py", line 269, in _async_state_change_dispatcher
    hass.async_run_hass_job(job, event)
  File "/usr/src/homeassistant/homeassistant/core.py", line 433, in async_run_hass_job
    hassjob.target(*args)
  File "/usr/src/homeassistant/homeassistant/components/utility_meter/sensor.py", line 176, in async_reading
    for sensor in self.hass.data[DATA_UTILITY][self._parent_meter][
KeyError: 'sensor.electricity_used_kitchen_ceiling_light_2_virtual_daily'

Running the current power calc master branch / home assistant core-2021.10.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
Nozza-VScommented, Oct 9, 2021

Looks like utility meter expects ATTR_LAST_PERIOD to be a float (numeric value), but it is actually None, which causes this error. I would suggest to delete all state entries for this utility meter from the database. DELETE FROM states WHERE entity_id=“sensor.utility_meter_id”;.

I decided to go a bit further and give home assistant a fresh database, unfortunately this error still persists (no more restore state messages though so that’s nice). I’ve let it run for a couple hours now and nothing appears broken so I’ll just let it run for a week or so and see if it occurs on the next restart again

1reaction
Nozza-VScommented, Oct 9, 2021

I’ve updated to 0.10.1 and enabled about 3/4 of the devices I plan to use So far everything appears to have created the correct entities and it’s all working great

I was getting this error yesterday which I couldn’t work out and am still getting after I updated

Logger: homeassistant.components.sensor
Source: components/utility_meter/sensor.py:340
Integration: Sensor (documentation, issues)
First occurred: 6:15:42 PM (3 occurrences)
Last logged: 6:15:43 PM

Error adding entities for domain sensor with platform powercalc
Error while setting up powercalc platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 587, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 681, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/usr/src/homeassistant/homeassistant/components/utility_meter/sensor.py", line 340, in async_added_to_hass
    float(state.attributes.get(ATTR_LAST_PERIOD))
ValueError: could not convert string to float: 'None'

Functionally everything seems fine though

The only other error related to utility meters that I seem to be getting a lot since updating home assistant (this isn’t specific to powercalc as it happens to essentially any new meter or anything that hasn’t received any data and for low power usage devices such as a virtual item using only 0.5W, it can sometimes take forever to update with a value)

Logger: homeassistant.components.utility_meter.sensor
Source: components/utility_meter/sensor.py:330
Integration: Utility Meter (documentation, issues)
First occurred: 6:15:40 PM (62 occurrences)
Last logged: 6:15:40 PM

Could not restore state <unknown>. Resetting utility_meter.Electricity Used Plug 14 Virtual monthly
Could not restore state <unknown>. Resetting utility_meter.Electricity Used Plug 14 Virtual yearly
Could not restore state <unknown>. Resetting utility_meter.Electricity Used Plug 15 Virtual daily
Could not restore state <unknown>. Resetting utility_meter.Electricity Used Plug 15 Virtual monthly
Could not restore state <unknown>. Resetting utility_meter.Electricity Used Plug 15 Virtual yearly

~I’ve created 2 group (1 for lights, 1 for plugs) to test that out and the entities were created correctly but they don’t seem to be adding the values of every virtual device together. Rather it just uses a flat value of one of the devices. This could be user error though and me not understanding the configuration properly just yet so I’ll play with the groups a bit more tonight~ Groupings not working were 100% user error, works as expected (when configured correctly lol)

I’ve dumped my current powercalc config / some debug logs over on pastebin

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 Reasons Your Utility Bills Are Inaccurate - Aquicore
1. There Are Problems with Your Utility Meters. Issues you could have with your meters themselves range from installation errors to communication failures....
Read more >
How Often Should Electricity Meters Be Changed?
If your electricity meter is either moving too fast or too slow or telling the wrong time, it is probably not functioning correctly....
Read more >
Faulty meter? Here are the warning signs | Energyprice.be
But if prices have remained stable, it's time to have a look at your gas or electricity meter as it may be turning...
Read more >
Is My Electric Meter Faulty?
Are your high electrical bills caused by a faulty electrical meter? Probably not, but it's worth it to check. Read our post to...
Read more >
Check if your energy meter is faulty - Citizens Advice
If the meter is still moving, it's probably faulty. If it's a gas meter, you might have a gas leak - report it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found