homeassistant-powercalc icon indicating copy to clipboard operation
homeassistant-powercalc copied to clipboard

Group missing energy sensor

Open Largelos opened this issue 6 months ago • 13 comments

System Health details

System Information

version core-2025.5.0
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.13.3
os_name Linux
os_version 6.12.23-haos
arch x86_64
timezone Europe/Berlin
config_dir /config
Home Assistant Community Store
GitHub API ok
GitHub Content ok
GitHub Web ok
HACS Data ok
GitHub API Calls Remaining 4966
Installed Version 2.0.5
Stage running
Available Repositories 1720
Downloaded Repositories 10
Home Assistant Cloud
logged_in false
can_reach_cert_server ok
can_reach_cloud_auth ok
can_reach_cloud ok
Home Assistant Supervisor
host_os Home Assistant OS 15.2
update_channel stable
supervisor_version supervisor-2025.04.1
agent_version 1.7.2
docker_version 28.0.4
disk_total 62.3 GB
disk_used 32.1 GB
healthy true
supported true
host_connectivity true
supervisor_connectivity true
ntp_synchronized true
virtualization microsoft
board ova
supervisor_api ok
version_api ok
installed_addons Terminal & SSH (9.17.0), Mosquitto broker (6.5.0), File editor (5.8.0), Studio Code Server (5.19.2), Zigbee2MQTT (2.3.0-1), Frigate (0.15.1), Tesla HTTP Proxy (2.2.8)
Dashboards
dashboards 5
resources 2
views 6
mode storage
Network Configuration
adapters lo (disabled), eth0 (enabled, default, auto), hassio (disabled), docker0 (disabled), veth6e21d64 (disabled), veth7da5a98 (disabled), veth30ca7de (disabled), veth305d463 (disabled), vethe9cdc9b (disabled), vethb833a6a (disabled), veth80872b8 (disabled), vethcfc5287 (disabled)
ipv4_addresses lo (127.0.0.1/8), eth0 (172.16.1.228/24), hassio (172.30.32.1/23), docker0 (172.30.232.1/23), veth6e21d64 (), veth7da5a98 (), veth30ca7de (), veth305d463 (), vethe9cdc9b (), vethb833a6a (), veth80872b8 (), vethcfc5287 ()
ipv6_addresses lo (::1/128), eth0 (fe80::28:860:442a:b1cf/64), hassio (fe80::d054:eeff:fe1f:d749/64), docker0 (fe80::a87f:6cff:febf:36ec/64), veth6e21d64 (fe80::8c86:9dff:fe97:ffbd/64), veth7da5a98 (fe80::b04c:8fff:fee8:c1df/64), veth30ca7de (fe80::ec9f:f6ff:fe86:dd05/64), veth305d463 (fe80::bc4d:5dff:feae:e6af/64), vethe9cdc9b (fe80::6029:3cff:febd:2db8/64), vethb833a6a (fe80::f022:68ff:fe52:2864/64), veth80872b8 (fe80::389f:3eff:fe7d:a84d/64), vethcfc5287 (fe80::3cc8:8fff:fe84:900d/64)
announce_addresses 172.16.1.228, fe80::28:860:442a:b1cf
Recorder
oldest_recorder_run April 7, 2025 at 9:29 PM
current_recorder_run May 8, 2025 at 9:04 PM
estimated_db_size 3069.36 MiB
database_engine sqlite
database_version 3.48.0

Checklist

  • [x] I have read the FAQ to see if there is a known solution to my problem.
  • [x] I have enabled debug logging for my installation.
  • [x] I have filled out the issue template to the best of my ability.
  • [x] This issue only contains 1 issue (if you have multiple issues, open one issue for each issue).
  • [x] This issue is not a duplicate issue of currently previous issues..

Describe the issue

Sensor "Roborock energy" created by powercalc group missing "Saros 10R energy" member for unknown reason, but members power calculation is fine. Now I'm not sure if all other groups from integration also calculate values correctly.

Image

Image

Image

Reproduction steps

  1. I created 3 devices and group by GUI
  2. Now discovered energy calculated incorrect

Debug logs

Field can not be longer than 65536 characters, debug log attached as file below.

Diagnostics dump or YAML config

config_entry-powercalc-01JTH9MK0VCJA5J4SHBMCGEPMW.json

config_entry-powercalc-01JTHBGV5PKEN6J6GWQ4ZY6B9K.json

config_entry-powercalc-01JTH7VZB5W9BX9SVMT1Q9B2MY.json

home-assistant_powercalc_2025-05-09T14-56-14.092Z.log

Largelos avatar May 09 '25 15:05 Largelos

I'm not entirely sure about the problem. Where do you see "Saros 10R energy" is missing from "Roborock energy"?

bramstroker avatar May 09 '25 20:05 bramstroker

Check first screenshot, Saros 10r energy value is 0.4661kWh, and Roborock energy only contain 0.01780+0.0005kWh from Status and Dock entries

Largelos avatar May 09 '25 20:05 Largelos

When you add it to the group later it will only start delta increasing the group from then on by default, not all existing energy of the member sensor will be added to the group. You can check the member entities of the group with this service: https://docs.powercalc.nl/actions/get-group-entities/ When Saros 10r energy is also there the group should start increasing with this energy sensor as well.

bramstroker avatar May 09 '25 20:05 bramstroker

All entities was added to group with GUI creation wizard during creation. sensor.roborock_power: entities: - sensor.saros_10r_power - sensor.saros_10r_dock_mop_drying_power - sensor.saros_10r_status_power sensor.roborock_energy: entities: - sensor.saros_10r_status_energy - sensor.saros_10r_dock_mop_drying_energy

Largelos avatar May 09 '25 20:05 Largelos

Hmm I see. Checked your logs but unfortunately I'm not logging yet which entities are passed during creation of the group entities:

2025-05-09 16:54:22.074 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Creating grouped power sensor: Roborock power (entity_id=sensor.roborock_power)
2025-05-09 16:54:22.074 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Creating grouped energy sensor: Roborock energy (entity_id=sensor.roborock_energy)

Could you also share diagnostics of the group Roborock?

bramstroker avatar May 10 '25 06:05 bramstroker

config_entry-powercalc-01JTH999010MC5MEQHR8DE0HX4.json I can add that deleting and adding the device to the group again does not solve the problem, only the power entity added.

Largelos avatar May 10 '25 13:05 Largelos

The problem is _energy_sensor is missing from the config entry data for Saros R10.

For example dock mop drying

config_entry-powercalc-01JTH7VZB5W9BX9SVMT1Q9B2MY.json

"data": {
        "_energy_entity": "sensor.saros_10r_dock_mop_drying_energy",
        "_power_entity": "sensor.saros_10r_dock_mop_drying_power",
}

But the saros r10 only has _power_entity set.

config_entry-powercalc-01JTH9MK0VCJA5J4SHBMCGEPMW.json

"data": {
        "_power_entity": "sensor.saros_10r_power",
}

Will do some further investigation.

According to logs energy sensor is created just fine:

2025-05-09 16:54:22.104 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=vacuum.saros_10r entity_category=None, sensor_name=Saros 10R power strategy=linear manufacturer=roborock model=roborock.vacuum.a144 unique_id=pc_5syprlwf2ymuqk9fmfjpqu)
2025-05-09 16:54:22.104 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor (entity_id=sensor.saros_10r_energy, source_entity=sensor.saros_10r_power, unit_prefix=k)
2025-05-09 16:54:22.104 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.saros_10r_power to device 3728280aa0a157d284b92f7be9548561

But somehow it's entity_id is not save in the config entry data.

bramstroker avatar May 11 '25 06:05 bramstroker

Stepped through the code but I can't see yet where it would go wrong. Very strange.

I have modified method which is reponsible for setting these values to include some more logs. Could you replace line 418-449 with the following code in config/custom_components/powercalc/sensor.py

@callback
def save_entity_ids_on_config_entry(
    hass: HomeAssistant,
    config_entry: ConfigEntry,
    entities: EntitiesBucket,
) -> None:
    """Save the power and energy sensor entity_id's on the config entry
    We need this in group sensor logic to differentiate between energy sensor and utility meters.
    """
    _LOGGER.debug("Saving entity ids on config entry %s", config_entry.entry_id)
    power_entities = [e.entity_id for e in entities.all() if isinstance(e, VirtualPowerSensor)]
    new_data = config_entry.data.copy()
    if power_entities:
        _LOGGER.debug("Setting power entity_id %s on config entry %s", power_entities[0], config_entry.entry_id)
        new_data.update({ENTRY_DATA_POWER_ENTITY: power_entities[0]})

    if bool(config_entry.data.get(CONF_CREATE_ENERGY_SENSOR, False)):
        energy_entities = [e.entity_id for e in entities.all() if isinstance(e, EnergySensor)]
        if not energy_entities:
            raise SensorConfigurationError(  # pragma: no cover
                f"No energy sensor created for config_entry {config_entry.entry_id}",
            )
        new_data.update({ENTRY_DATA_ENERGY_ENTITY: energy_entities[0]})
        _LOGGER.debug("Setting energy entity_id %s on config entry %s", energy_entities[0], config_entry.entry_id)
    elif ENTRY_DATA_ENERGY_ENTITY in new_data:
        _LOGGER.debug("Removing energy entity_id on config entry %s", config_entry.entry_id)
        new_data.pop(ENTRY_DATA_ENERGY_ENTITY)

    hass.config_entries.async_update_entry(
        config_entry,
        data=new_data,
    )

And restart afterwards, hopefully the logs will provide more insights. You can search the logs for 01JTH9MK0VCJA5J4SHBMCGEPMW after restarting.

bramstroker avatar May 11 '25 07:05 bramstroker

I had kind of same issue, I did the action Powercalc: Reload in Action (Dev Tools > Action) and it fixed my group.

Myrz avatar May 22 '25 09:05 Myrz

@bramstroker thx and sorry for late response, didn't seen your update. Unfortunately, I don’t see anything useful here, only what is already visible in config:


2025-05-22 16:10:58.806 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.lumi_lumi_relay_c2acn01_device_power_4 to device d73fd7011826e3c12d1d717f42c64110
2025-05-22 16:10:58.806 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=vacuum.saros_10r entity_category=None, sensor_name=Saros 10R power strategy=linear manufacturer=roborock model=roborock.vacuum.a144 unique_id=pc_5syprlwf2ymuqk9fmfjpqu)
2025-05-22 16:10:58.806 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor (entity_id=sensor.saros_10r_energy, source_entity=sensor.saros_10r_power, unit_prefix=k)
2025-05-22 16:10:58.806 DEBUG (MainThread) [custom_components.powercalc.sensor] Saving entity ids on config entry 01JTH9MK0VCJA5J4SHBMCGEPMW
2025-05-22 16:10:58.806 DEBUG (MainThread) [custom_components.powercalc.sensor] Setting power entity_id sensor.saros_10r_power on config entry 01JTH9MK0VCJA5J4SHBMCGEPMW
2025-05-22 16:10:58.806 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.saros_10r_power to device 3728280aa0a157d284b92f7be9548561
2025-05-22 16:10:58.807 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=sensor.dummy entity_category=None, sensor_name=LUMI lumi.relay.c2acn01 Device Power strategy=fixed manufacturer=aqara model=lumi.relay.c2acn01 unique_id=pc_3b4d9f971f7e0f8c45aea56a98feee74)

Largelos avatar May 22 '25 14:05 Largelos

I had kind of same issue, I did the action Powercalc: Reload in Action (Dev Tools > Action) and it fixed my group.

That would indicate it's a timing issue somehow during startup. thanks for the extra info.

bramstroker avatar May 30 '25 06:05 bramstroker

@Largelos I did have a further look into your logs and the code and I think I have found the issue. Should be fixed with https://github.com/bramstroker/homeassistant-powercalc/pull/3307. Will release new version of Powercalc today. Could you please test when this is released?

bramstroker avatar May 30 '25 06:05 bramstroker

Tested with new version, was not changed after simple update and HA restart but looking fine after manually remove and re-add entity from/to the group:

sensor.roborock_power:
  entities:
    - sensor.saros_10r_power
    - sensor.saros_10r_dock_mop_drying_power
    - sensor.saros_10r_status_power
sensor.roborock_energy:
  entities:
    - sensor.saros_10r_energy
    - sensor.saros_10r_status_energy
    - sensor.saros_10r_dock_mop_drying_energy

Largelos avatar May 30 '25 16:05 Largelos

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] avatar Jun 30 '25 02:06 github-actions[bot]

This issue was closed because it has been stalled for 5 days with no activity.

github-actions[bot] avatar Jul 06 '25 02:07 github-actions[bot]