Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group power sensors not loaded during startup #2962

Closed
kbullet opened this issue Jan 15, 2025 · 23 comments
Closed

Group power sensors not loaded during startup #2962

kbullet opened this issue Jan 15, 2025 · 23 comments
Labels
bug Something isn't working group

Comments

@kbullet
Copy link

kbullet commented Jan 15, 2025

version core-2025.1.2
installation_type Home Assistant Container
dev false
hassio false
docker true
user root
virtualenv false
python_version 3.13.1
os_name Linux
os_version 6.1.0-27-amd64
arch x86_64
timezone Asia/Ho_Chi_Minh
config_dir /config

Home Assistant Community Store
Home Assistant Cloud
Dashboards
Recorder
Sonoff

Checklist

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

Describe the issue

Not sure why but with one of the recent update, Each time restarting homeassistant I need to reload the existing groups i've created to get the power sensors to be initialised correctly. Everything else is loaded correctly. I don't see anything significant or failures in the debug logs.

Screenshot 2025-01-15 at 08 24 06

Reproduction steps

  1. Create a group with fixed power sensor for switches
  2. Check the power sensors have been added correctly
  3. Restart homeassistant, the new power sensor for the group won't load unless manually reloading that group's configuration

Debug logs

Startup Logs:

2025-01-15 08:16:17.836 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=switch.dual_relay_bathroom_left entity_category=None, sensor_name=Bathroom Lights Group 1 power strategy=fixed manufacturer= model= unique_id=pc_0xa4c138d4f2de8691_switch_left_zigbee2mqtt)
2025-01-15 08:16:17.837 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.bathroom_lights_group_1_power to device 33d9ebbbb7c61cd97dbadf87bc68449e
2025-01-15 08:16:17.838 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Creating grouped power sensor: Bathroom Lights power (entity_id=sensor.bathroom_lights_power)
2025-01-15 08:16:17.838 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Creating grouped energy sensor: Bathroom Lights energy (entity_id=sensor.bathroom_lights_energy)
2025-01-15 08:16:17.839 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Load previous energy sensor states from store
2025-01-15 08:16:17.848 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=switch.dual_relay_bathroom_right entity_category=None, sensor_name=Bathroom Lights Group 2 power strategy=fixed manufacturer= model= unique_id=pc_0xa4c138d4f2de8691_switch_right_zigbee2mqtt)
2025-01-15 08:16:17.849 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.bathroom_lights_group_2_power to device 33d9ebbbb7c61cd97dbadf87bc68449e

Manual reload logs:

2025-01-15 08:20:57.044 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=switch.dual_relay_bathroom_left entity_category=None, sensor_name=Bathroom Lights Group 1 power strategy=fixed manufacturer= model= unique_id=pc_0xa4c138d4f2de8691_switch_left_zigbee2mqtt)
2025-01-15 08:20:57.053 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.bathroom_lights_group_1_power to device 33d9ebbbb7c61cd97dbadf87bc68449e
2025-01-15 08:20:57.093 DEBUG (MainThread) [custom_components.powercalc.sensors.power] switch.dual_relay_bathroom_left: State changed to "off". Power:0.00
2025-01-15 08:20:57.113 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Group sensor sensor.bathroom_lights_power. State change for sensor.bathroom_lights_group_1_power: <state sensor.bathroom_lights_group_1_power=unavailable; state_class=measurement, unit_of_measurement=W, device_class=power, friendly_name=Bathroom Lights Group 1 power @ 2025-01-15T08:20:57.053777+07:00>
2025-01-15 08:20:57.114 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Group sensor sensor.bathroom_lights_power. State change for sensor.bathroom_lights_group_1_power: <state sensor.bathroom_lights_group_1_power=unavailable; state_class=measurement, unit_of_measurement=W, device_class=power, friendly_name=Bathroom Lights Group 1 power @ 2025-01-15T08:20:57.054598+07:00>
2025-01-15 08:20:57.114 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Group sensor sensor.bathroom_lights_power. State change for sensor.bathroom_lights_group_1_power: <state sensor.bathroom_lights_group_1_power=0.00; state_class=measurement, calculation_mode=fixed, integration=powercalc, source_entity=switch.dual_relay_bathroom_left, source_domain=switch, unit_of_measurement=W, device_class=power, friendly_name=Bathroom Lights Group 1 power @ 2025-01-15T08:20:57.093796+07:00>
2025-01-15 08:20:57.115 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Group sensor sensor.bathroom_lights_power. State change for sensor.bathroom_lights_group_1_power: <state sensor.bathroom_lights_group_1_power=0.00; state_class=measurement, calculation_mode=fixed, integration=powercalc, source_entity=switch.dual_relay_bathroom_left, source_domain=switch, unit_of_measurement=W, device_class=power, friendly_name=Bathroom Lights Group 1 power @ 2025-01-15T08:20:57.095285+07:00>

2025-01-15 08:21:50.362 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=switch.dual_relay_bathroom_right entity_category=None, sensor_name=Bathroom Lights Group 2 power strategy=fixed manufacturer= model= unique_id=pc_0xa4c138d4f2de8691_switch_right_zigbee2mqtt)
2025-01-15 08:21:50.366 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.bathroom_lights_group_2_power to device 33d9ebbbb7c61cd97dbadf87bc68449e
2025-01-15 08:21:50.377 DEBUG (MainThread) [custom_components.powercalc.sensors.power] switch.dual_relay_bathroom_right: State changed to "off". Power:0.00
2025-01-15 08:21:50.381 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Group sensor sensor.bathroom_lights_power. State change for sensor.bathroom_lights_group_2_power: <state sensor.bathroom_lights_group_2_power=unavailable; state_class=measurement, unit_of_measurement=W, device_class=power, friendly_name=Bathroom Lights Group 2 power @ 2025-01-15T08:21:50.367074+07:00>
2025-01-15 08:21:50.382 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Group sensor sensor.bathroom_lights_power. State change for sensor.bathroom_lights_group_2_power: <state sensor.bathroom_lights_group_2_power=unavailable; state_class=measurement, unit_of_measurement=W, device_class=power, friendly_name=Bathroom Lights Group 2 power @ 2025-01-15T08:21:50.367478+07:00>
2025-01-15 08:21:50.382 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Group sensor sensor.bathroom_lights_power. State change for sensor.bathroom_lights_group_2_power: <state sensor.bathroom_lights_group_2_power=0.00; state_class=measurement, calculation_mode=fixed, integration=powercalc, source_entity=switch.dual_relay_bathroom_right, source_domain=switch, unit_of_measurement=W, device_class=power, friendly_name=Bathroom Lights Group 2 power @ 2025-01-15T08:21:50.377992+07:00>
2025-01-15 08:21:50.383 DEBUG (MainThread) [custom_components.powercalc.sensors.group.custom] Group sensor sensor.bathroom_lights_power. State change for sensor.bathroom_lights_group_2_power: <state sensor.bathroom_lights_group_2_power=0.00; state_class=measurement, calculation_mode=fixed, integration=powercalc, source_entity=switch.dual_relay_bathroom_right, source_domain=switch, unit_of_measurement=W, device_class=power, friendly_name=Bathroom Lights Group 2 power @ 2025-01-15T08:21:50.378953+07:00>

Config entry:

{"created_at":"2024-10-30T09:58:15.905986+00:00","data":{"_power_entity":"sensor.bathroom_lights_group_1_power","create_energy_sensor":false,"create_utility_meters":false,"entity_id":"switch.dual_relay_bathroom_left","fixed":{"power":21.0},"group":"Bathroom Lights","ignore_unavailable_state":false,"mode":"fixed","name":"Bathroom Lights Group 1","sensor_type":"virtual_power","unique_id":"pc_0xa4c138d4f2de8691_switch_left_zigbee2mqtt"},"disabled_by":null,"discovery_keys":{},"domain":"powercalc","entry_id":"01JBEDS4K1D9TSCEAKGT1JR8S2","minor_version":1,"modified_at":"2024-10-30T09:58:15.908125+00:00","options":{},"pref_disable_new_entities":false,"pref_disable_polling":false,"source":"user","title":"Bathroom Lights Group 1","unique_id":"pc_0xa4c138d4f2de8691_switch_left_zigbee2mqtt","version":4},

@kbullet kbullet added the bug Something isn't working label Jan 15, 2025
@kbullet kbullet closed this as not planned Won't fix, can't repro, duplicate, stale Jan 15, 2025
@kbullet kbullet reopened this Jan 15, 2025
@bramstroker
Copy link
Owner

bramstroker commented Jan 15, 2025

Will have a further look and ask more questions later.
But just a quick check.
Could you try downgrading from 1.17.1 to 1.17.0? I suspect this change maybe: #2893
Or do you have issues longer than a few days?

@kbullet
Copy link
Author

kbullet commented Jan 15, 2025

Will have a further look and ask more questions later.

But just a quick check.

Could you try downgrading from 1.17.1 to 1.17.0? I suspect this change maybe: #2893

Or do you have issues longer than a few days?

Yeah I only noticed it started happening quite recently when HA's statistics kept suggesting to remove the unavailable sensors. I will try downgrading and dig further

@bramstroker
Copy link
Owner

Yeah your issue is definitely different then the unavailable template sensor issue, that's about the state of an entity. In your case no entities seem to be created at all on startup.
Very strange there is no error or any issue to be seen in the logs.

@kbullet
Copy link
Author

kbullet commented Jan 16, 2025

Yeah I think there's some funky edge case going on. Yes my bad the sensors are not created on startup. I tried downgrading it didn't help (even with 1.67.1), deleting and recreating the affected sensors and groups didn't help either. But then I've added another virtual power sensor for a different switch with a new group and it's working fine...?

I checked the history it seemed to started to happen from the 10th ish

Image

Will try to debug further to to see if i can find a way to reproduce it properly

@erkr
Copy link

erkr commented Jan 16, 2025

Hi,

I lost some sensors as well when upgrading from 1.16.7 to 1.17.1:

  • sensor.vloerverwarming_unit_power
  • sensor.vloerverwarming_unit_energy
  • sensor.itho_fan_control_power
  • sensor.itho_fan_control_energy
  • sensor.harmony57_power

They have in common that there is a manual power configuration. Example 1:

  - create_group: multimedia
    unique_id: powercalc_group_multimedia 
    create_energy_sensor: true
    force_calculate_group_energy: true
    entities:
      - entity_id: remote.harmony57             
        standby_power: 13.0
        fixed:
          power: >
            {% set activity=state_attr("remote.harmony57", 'current_activity') or 'PowerOff' %}
            {% if activity == "PowerOff" %}
              13.0 
            {% elif activity == "Listen Radio" %}
              60.0
            {% elif activity == "Listen Chromecast" %}
              60.0
            {% elif activity == "Watch TV" %}
              110.0
            {% else %}
              160.0
            {% endif %}

example 2 & 3:

  - create_group: climate
    unique_id: powercalc_group_climate
    create_energy_sensor: true
    entities:
    - power_sensor_id: sensor.cv_ketel_power
      energy_sensor_id: sensor.cv_ketel_summation_delivered
    - entity_id: binary_sensor.cvzones_floor_unit_pump
      name: Vloerverwarming Unit 
      create_energy_sensor: true
      standby_power: 3.5 # controller + 24v trafo
      fixed:
        power: >
         {{ (59.5 if is_state('binary_sensor.cvzones_floor_unit_pump','on') else 0)
           + (4 if states('sensor.cvzones_living_valve') in ['Open','Opening'] else 0)
           + (4 if states('sensor.cvzones_kitchen_valve') in ['Open','Opening'] else 0) }}
    - entity_id: fan.itho_fan_control 
      create_energy_sensor: true
      standby_power: 0.4
      fixed:
        power: > 
          {% if state_attr("fan.itho_fan_control", 'percentage')|int(0) > 75  %}
          19.0 
          {% elif state_attr("fan.itho_fan_control", 'percentage')|int(0) > 50 %}
          7.0
          {% else %}
          3.0
          {% endif %}

@erkr
Copy link

erkr commented Jan 16, 2025

downgrading didn't fix ?! No warnings nor errors in the log either.

Edit: downgrade did fix it. Need to change state to get them back

@bramstroker
Copy link
Owner

@erkr thanks for chiming in. Which downgrade fixed it in the end? So do you know which version introduced the regression exactly?
That will make it easier for me to zoom in on partical PR's which might have introduced this regression.

@erkr
Copy link

erkr commented Jan 16, 2025

@bramstroker Your are welcome :). I downgraded to 1.16.7 (from 1.17.1). Then I updated to previous release 1.17.0 and that release has the same issue.
Edit: but I now deliberately changed the state of the monitored entity, and than it comes back!!! will test 1.17.1 now
Edit2: Yes same in 1.17.1: the power/energy sensors with these templated power settings are unavailable after a restart, until the source state changes -> initial value issue!

@bramstroker
Copy link
Owner

@erkr Your issue seems exactly the same as #2911
This issue is particularly about group sensor not being created at all, seems unrelated to me to.
Your issue seems to be about individual entities and particularly where templates are used in fixed strategy.
So could you please at your comments there?

@erkr
Copy link

erkr commented Jan 16, 2025

Yeah, didn't realise that difference tbh until I discovered that the sensors get back after the first state change.
Wondering if the OP checked that.
Exit: but maybe there groups aren't created because all fixed power members are unavailable.

@bramstroker
Copy link
Owner

@erkr please see my comments on #2911, was able to reproduce the template sensor unavailable issue.

Probably still unrelated to the issue @kbullet reported here, but makes sense for @kbullet to retest after I fixed the other issue and create a new release.
When the group sensor issue still persists we will investigate further.

@kbullet
Copy link
Author

kbullet commented Jan 18, 2025

@bramstroker i'm still unable to reproduce my issue with a completely new group, virtual power sensor of a different switch...

Though FYI a workaround I found out to seem to have fixed it, is to create an energy sensor for the virtual power sensor (deleting the created energy sensor afterwards seems to work still). It is quite strange hope that can give you some clues. Though I'll leave couple of my groups that are affected untouched to test your fix/new release.

@bramstroker
Copy link
Owner

Could you share some diagnostics for groups which are working and groups which are not? Click 3 dots and "Download diagnostics"
Then we can compare, and see if there is something in common between them.

@bramstroker
Copy link
Owner

@kbullet I'm pretty sure your issue was similar as reported in #3005.
Have a fix for that now which I will release today.
Please let me know if it also solves for you.

@kbullet
Copy link
Author

kbullet commented Jan 26, 2025

@bramstroker awesome, thanks! Apologies I've been away to be able to test your fixes and give you more info. Will report back once I get home next weekend.

p.s. Thanks for this amazing integration and keep up the good work!

@kbullet
Copy link
Author

kbullet commented Feb 1, 2025

@bramstroker just upgraded to the latest version unfortunately my issue still persists.

here's the diagnostics of the affected groups and sensors. https://pastebin.com/wZvyKfnf i've included both when sensors are missing/unavailable & reloading the sensors manually hope that is of help. Though I think this might be some super weird edge case

@bramstroker
Copy link
Owner

@kbullet the config entries looks perfectly fine and exactly as expected.
The diagnostics won't change after a reload, because the configuration entry data won't change.

Too further investigate we really need to focus on the logs, and having that extended with more debug logs when needed.

Let's please focus on one entity / problem at a time, otherwise it gets very confusing for me because I'm working on numerous issues constantly. And need to reread / distill all available information each time.
Asking that because your initial screenshot was about Bedroom lights.
The first logs you shared about Bathroom lights.
And the config entries shared in last post on Livingroom lights.
It probably all boils down to the same issue, but to avoid confusion it would help a lot to zoom in on one certain entity.

@kbullet
Copy link
Author

kbullet commented Feb 1, 2025

@bramstroker i'm still unable to reproduce my issue with a completely new group, virtual power sensor of a different switch...

Though FYI a workaround I found out to seem to have fixed it, is to create an energy sensor for the virtual power sensor (deleting the created energy sensor afterwards seems to work still). It is quite strange hope that can give you some clues. Though I'll leave couple of my groups that are affected untouched to test your fix/new release.

Apologies, as i mentioned in one of my previous posts the workaround I found that I applied to the "bathroom lights" entities is to create an energy for the power sensor which seems to somehow fix the issue. The living room lights entities is the one I left untouched with the issue still persisting hence I took those logs.

@bramstroker
Copy link
Owner

Please bear with me I didn't remember this, and don't read each issue all comments again :-)
That's indeed very strange behaviour. Pretty sure that action would have changed something on the configuration entry which causes it to load correctly now.
Only relevant information on the config entry is the data attribute, that contains the actual configuration for the powercalc group.

So on your latest shared diagnostics for Living room lights this is:

{
    "_energy_entity": "sensor.living_room_lights_energy",
    "create_energy_sensor": true,
    "group_member_sensors": [
        "01JBEF9JHZV7CC7N3T0N7S4YZ9",
        "01JBEFAW9PDWYRGM3AABHJKCHN"
    ],
    "name": "Living Room Lights",
    "sensor_type": "group"
}

Might be a good idea to compare that with the diagnostics for Bathroom lights, and see if there is any difference.

@kbullet
Copy link
Author

kbullet commented Feb 2, 2025

No worries at all, I did a comparison before I could not see anything out of the ordinary.

      "data": {
        "_energy_entity": "sensor.bathroom_lights_energy",
        "create_energy_sensor": true,
        "group_member_sensors": [
          "01JBEDS4K1D9TSCEAKGT1JR8S2",
          "01JBEDTCEF9BXD3WK4ATK7QXSR"
        ],
        "name": "Bathroom Lights",
        "sensor_type": "group"
      },

The only thing I could see that was different is the living room power sensor is using the group's entry_id instead of the name. Though I did try changing that in the config entry before and for sanity check just did again but it didn't help.

e.g.

      "data": {
        "_power_entity": "sensor.bathroom_lights_group_1_power",
        "create_energy_sensor": false,
        "create_utility_meters": false,
        "entity_id": "switch.dual_relay_bathroom_left",
        "fixed": {
          "power": 21.0
        },
        "group": "Bathroom Lights",
        "ignore_unavailable_state": false,
        "mode": "fixed",
        "name": "Bathroom Lights Group 1",
        "sensor_type": "virtual_power",
        "unique_id": "pc_0xa4c138d4f2de8691_switch_left_zigbee2mqtt"
      },

vs

      "data": {
        "_power_entity": "sensor.living_room_lights_group_1_power",
        "create_energy_sensor": false,
        "create_utility_meters": false,
        "entity_id": "switch.sonoff_zbminil2_relay_living_room_1",
        "fixed": {
          "power": 27.0
        },
        "group": "01JBEF823ARPGABWQ441Q2F2C9",
        "ignore_unavailable_state": false,
        "mode": "fixed",
        "name": "Living Room Lights Group 1",
        "sensor_type": "virtual_power",
        "unique_id": "pc_0x842712fffe4117de_update_zigbee2mqtt"
      },

Anyhow no worries, I can use the workaround if we can't narrow it down. Maybe we can close this for now and reopen it if someone can reproduce it properly. Cheers for all of your support and help!

@bramstroker
Copy link
Owner

@kbullet I don't see anything obvious as well, everything looks fine.
group prop will be set to the config entry id of the group when you select an existing group when creating the virtual power sensor.
When you type one manually it will be set to the group name, and powercalc will dynamically create that group when it doesn't exists.

Might very well be related to the issue somehow. You might try removing the group property completely from sensor.living_room_lights_group_1_power config entry.
As it is only needed once for powercalc to dynamically add the entry to the group. It will update the group config entry member_sensors when it find group property on a virtual power entry.

@kbullet
Copy link
Author

kbullet commented Feb 3, 2025

Yeah removing the group property did nothing aswell, it is really funky setting create_energy_sensor to true once, somehow fixes the issue. I did not see any difference in the logs or configs (once it is set to true i cannot reproduce it at all for it not to load on startup even removing the newly created energy sensor and reverting back to false).

But yeah I don't want to waste much more of your time on this maybe something dodgy is going on specifically on my setup.

@bramstroker
Copy link
Owner

Yes, I think we need to close. I'm getting frustrated when things are not working as expected, and always want to get to the bottom.
But I agree it takes a lot of time for both of us, and seems rather an edge case.
Let me know if you have any further insights in the future and feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working group
Projects
None yet
Development

No branches or pull requests

3 participants