Is there a way to clear the numeric value that powercalc is using for computing grouped and nested grouped power entities? I’m seeing a lot of debug messages about old_value being higher than the new_value for some of my nested groups. I believe this may have happened when I added an additional entity into an existing powercalc group after I had setup powercalc originally, but I’m not sure. I have already deleted all of the _power and _states entities from the states, statistics, statistics_meta, and statistics_short_term tables and the old_value still never reset. Below is just a snippet of the warning messages. The new_value is moving slightly, but until it surpasses the old_value it won’t start showing data.
2022-06-21 08:39:03 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4696
2022-06-21 08:39:03 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4696
2022-06-21 08:39:03 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4696
2022-06-21 08:39:03 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4696
2022-06-21 08:39:03 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4696
2022-06-21 08:39:03 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4696
2022-06-21 08:39:03 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4696
2022-06-21 08:39:03 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4696
2022-06-21 08:39:03 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4696
2022-06-21 08:39:12 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4706
2022-06-21 08:39:32 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4716
2022-06-21 08:39:33 WARNING (MainThread) [custom_components.powercalc.sensors.group] sensor.all_estimated_usage_energy: State value of grouped energy sensor may never be lower than last value, skipping. old_value=518.9630. new_value=510.4750
@bramski is there a way to wipe out all the Powercalc data to start from zero on everything? I removed the integration and deleted every entity that Powercalc created, rebooted and then re-enabled Powercalc again and everything picked up right where it left off. I’m not logging anything as of yet, so there are no entries in the database for the recorded kWh, but they still came back.
Have a look at config/.storage/core.restore_state. Powercalc uses information from there to restore entity to latest known state. That’s the same as many other HA entities do it to restore the state after HA is restarted.
I would say HA should take care of cleaning these entries up if you remove the entity from HA, but apparantly it is not. So I would stop HA first than clean up the entries from this JSON file and then restart again. You could also remove all relevant entries from states table if there are any and you are using MariaDB. Hope this helps.
Thank you, I’ll take a look once I get it working again. I just restarted after adding one entry (which was a copy-paste of another entry but with a different entity_id) and suddenly I cannot even get it to start anymore, I get the following:
2022-06-21 12:38:39 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up powercalc platform for sensor
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/powercalc/sensor.py", line 238, in async_setup_platform
entities = await create_sensors(hass, config, discovery_info)
File "/config/custom_components/powercalc/sensor.py", line 321, in create_sensors
(child_new_sensors, child_existing_sensors) = await create_sensors(
File "/config/custom_components/powercalc/sensor.py", line 347, in create_sensors
await create_individual_sensors(hass, merged_sensor_config)
File "/config/custom_components/powercalc/sensor.py", line 417, in create_individual_sensors
power_sensor = await create_power_sensor(
File "/config/custom_components/powercalc/sensors/power.py", line 91, in create_power_sensor
return await create_virtual_power_sensor(
File "/config/custom_components/powercalc/sensors/power.py", line 151, in create_virtual_power_sensor
calculation_strategy = calculation_strategy_factory.create(
File "/config/custom_components/powercalc/strategy/factory.py", line 47, in create
return self._create_linear(config, light_model, source_entity)
File "/config/custom_components/powercalc/strategy/factory.py", line 69, in _create_linear
return LinearStrategy(
File "/config/custom_components/powercalc/strategy/linear.py", line 53, in __init__
self._calibration = self.create_calibrate_list()
File "/config/custom_components/powercalc/strategy/linear.py", line 102, in create_calibrate_list
min = full_range[0]
TypeError: 'NoneType' object is not subscriptable
I’m going to go through my latest entries to make sure the entity_id is correct, but I figure I would report this so you could look if there is any additional error trapping you can do.
UPDATE: I’ve wiped out all my new entries and this still happens, I can’t seem to find a culprit causing this.
Could you please create a report on github (also include the yaml configuration for the relevant sensor). Than we can have a look and not pollute the forum. Definitely the error handling must be improved for this case. The problem is probably somewhere in the linear calibration configuration syntax being incorrect.
I meant to ask on that thread if you wanted me to post on Git instead, I have my answer . I have a pretty massive config at this point, it’ll be challenging to pull it all together, but if you think it’s a linear config issue then I can post the last handful of those (although I removed them all and rebooted and no joy).
It’s 100% an issue with linear configuration, I can work that out by looking at the stacktrace. When you make an issue on github that’s also my backlog to improve upon the error handling, also I can put the relevant entity_id in the error message, which will make it more clear what goes wrong.
Complete config dumps and further support here on the forum will really pollute things, all there answers are shown under eachother, even though they are part of some sub thread.
Yes this behaviour can potentially happen in one of these cases:
Removing an energy sensor from the group
Removing an energy sensor completely from HA
One of the groups energy sensor becoming unavailable (maybe temporarily).
Because the energy sensor has the state_class total_increasing (which indicates the value must only go up) I have added some additional check to not record any new state values when it becomes lower. As this would probably mess HA statistics.
However I did some more investigation how to solve this issue and HA has introduced another state_class total (see Sensor Entity | Home Assistant Developer Docs), which would remove the need for the sensor to only ever increase in value. That was not available at the time I implemented the grouped energy sensor.
It seems this is the way to go, will have a look soon to implement this.
I just did a full reset of all my energy data in HA. The first was to clear out the entities in the statistics_meta database (I use MariaDB so it was quite easy, your mileage may vary) - you might not need this unless you are using recorder to keep track of your energy readings, then came the tougher part, to remove the data from .storage/core.restore_state file. That one has a LOT of lines of data, and for me having hundreds of Powercalc entries I just wrote a PHP script to re-render the JSON data without the Powercalc entities and it worked wonderfully - I was able to reset everything back to zero again so I could start fresh because, like you, I had a few rogue devices that would report huge negative numbers.
My new system, which is proving to be quite accurate using Powercalc when compared to my minute-by-minute data from the meter is pretty close, is to put everything into a group of “Whole House” and then subgroups of each area, which then contains all the Powercalc configs I want to use. Part of this is I went through and disabled every device kWh entity, as these were often problematic, and just let Powercalc do it all for me. In the end I have a Whole House meter for the “grid” in the Energy dashboard, whole area reporting for the entity details in the dashboard and can report on every single device in current watts, total kWh (that doesn’t go deep negative ever), daily kWh, monthly kWh and yearly kWh.
I love Powercalc, it is really helping me see huge power drains in my system that are easily controllable, and in doing this I’m able to recoup 500 kWh per month, which is a nice savings and just better all around.
Hi, is it possible to go more detailed in the climate integration taking under consideration the external and internal temperature?
The supplier usually provides a table the states the consumption in relation to the external and internal temperature.
So there should be a relation like that
if states(‘sensor.outside_temp’) <= 32, states(‘sensor.inside_temp’)<=25 Then power = 1042
and this should be repeated for let’s say 20 combination for both heating and cooling.
an easier way would be to include some sort of a table or csv reference in the configuraiton.yaml with this values and include in powercald the 2 sensors that should be considered.
I would give it a try if I only knew how to code properly …
Has anyone successfully run the collector from within HASS OS? I don’t have anything else capable of running docker and am drawing a blank on how I can run it.
No the measure tool won’t run on HASS OS. I did have a look into making it available as an addon, but it was too complicated and had some drawbacks.
Docker runs on almost any OS and architecture. I have it running on my Macbook, windows desktop and on a linux server. So I think you should be able to run it on the same device as you are browsing the forum on (unless this is a mobile phone of course).
Hmm, ok. I would prefer not to install docker on my MacBook.
I do have a pi3b+ on another network that should run the python env. Is it just access to hass api on 8123 and http 80 on the Shelly plug that would be needed?
Yes, access to that ports is all that’s needed.
Alternatively to docker you can run the python env and install dependencies yourself in a virtualenv if you want.
Could you set LOG_LEVEL=DEBUG in .env. This should give you following log line, with the exact URL that is being requested. Checking API connection: ...
Ah I see. Did have another look into the code, and it should not log errors in the API version detection method. It should only raise an error when non of the API version V1,V2 can be detected. Now the user will get notified of an error when there is no actual error.
I will change these logs from error → debug level.
I seem to be getting a certificate verification error from the hass api that curl doesn’t return when accessing the /api/ endpoint.
Any ideas where this might be coming from?
[ERROR] Aborting: Failed to connect to HA API: HTTPSConnectionPool(host='hass.local', port=8123): Max retries exceeded with url: /api/ (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
Where as curl with the same configured settings will return