bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
1.02k stars 263 forks source link

Not all Power Sensors fall into the group, when selected by Area #1741

Closed andrewjswan closed 1 year ago

andrewjswan commented 1 year ago

System Health details

System Information

version core-2023.7.0
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.11.4
os_name Linux
os_version 6.1.34
arch x86_64
timezone Europe/Kiev
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.32.1 Stage | running Available Repositories | 1281 Downloaded Repositories | 36
AccuWeather can_reach_server | ok -- | -- remaining_requests | 20
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 10.3 -- | -- update_channel | stable supervisor_version | supervisor-2023.07.1 agent_version | 1.5.1 docker_version | 23.0.6 disk_total | 116.7 GB disk_used | 24.3 GB healthy | true supported | true board | generic-x86-64 supervisor_api | ok version_api | ok installed_addons | Samba share (10.0.2), Advanced SSH & Web Terminal (15.0.2), Home Assistant Google Drive Backup (0.111.1), HDD Tools (1.1.0), File editor (5.6.0), ESPHome (2023.6.4), VLC (0.2.0), MQTT Explorer (browser-1.0.1), Photoprism (ubuntu)
Dashboards dashboards | 13 -- | -- resources | 20 views | 56 mode | storage
Recorder oldest_recorder_run | 28 июня 2023 г. в 04:23 -- | -- current_recorder_run | 5 июля 2023 г. в 22:01 estimated_db_size | 2921.84 MiB database_engine | mysql database_version | 10.11.2
Sonoff version | 3.5.1 (122751c) -- | -- cloud_online | 3 / 3 local_online | 0 / 0
Xiaomi Miot Auto component_version | 0.7.10 -- | -- can_reach_server | ok can_reach_spec | ok logged_accounts | 1 total_devices | 34

Checklist

Describe the issue

Not all Power Sensors fall into the group, when selected by Area, example: Config:

powercalc:
  enable_autodiscovery: true
  power_sensor_naming: "{} Power"
  create_energy_sensors: true
  energy_sensor_naming: "{} Energy"
  create_utility_meters: false

sensor:
  - platform: powercalc
    create_group: Спальня
    include:
      area: Спальня

Template:

From Area:
{% for entity in area_entities('Спальня') -%}
{%- if state_attr(entity, 'device_class') == 'power' -%}
{{ entity }} - {{ state_attr(entity, 'device_class') }} - {{ states(entity) }}
{% endif -%}
{%- endfor -%}
Count: {{ area_entities('Спальня') | select('search', '_power$') | list | count }}

From Powercalc sensor:
{% for entity in state_attr('sensor.spalnia_power', 'entities') -%}
{%- if state_attr(entity, 'device_class') == 'power' -%}
{{ entity }} - {{ state_attr(entity, 'device_class') }} - {{ states(entity) }}
{% endif -%}
{%- endfor -%}
Count: {{ state_attr('sensor.spalnia_power', 'entities') | list | count }}

Result:

From Area:
sensor.bedroom_socket_power - power - 6.1
sensor.nest_hub_bedroom_power - power - 0.39
sensor.smart_power_strip_power - power - 6.1
sensor.nest_mini_bedroom_power - power - 1.65
sensor.lampa_spalnia_power - power - 0.64
sensor.bedroom_christmas_light_power - power - 0.0
sensor.spalnia_girlianda_device_power - power - 0.29
sensor.bedroom_iron_power - power - 0.0
sensor.spalnia_utiug_device_power - power - 0.29
Count: 9

From Powercalc sensor:
sensor.nest_mini_bedroom_power - power - 1.65
Count: 1

Reproduction steps

  1. Add group by Area
  2. Check

Debug logs

If you need a fresh one, I'll make a previous one here
https://github.com/bramstroker/homeassistant-powercalc/issues/1739#issuecomment-1618916234

Diagnostics dump or YAML config

powercalc:
  enable_autodiscovery: true
  power_sensor_naming: "{} Power"
  create_energy_sensors: true
  energy_sensor_naming: "{} Energy"
  create_utility_meters: false

sensor:
  - platform: powercalc
    create_group: Спальня
    include:
      area: Спальня
bramstroker commented 1 year ago

I cannot understand ukranian ;-). But if I understand correctly Спальня is sensor.spalnia_power, and you expect 9 sensors in this group as they are all part of the bedroom area? Are all these other 8 sensors created with powercalc or existing power sensors from another integration?

Could you share clean new debug logs? You could also search yourself for Including entities from area, that should also list the found entities in your area. Maybe you can find out the culprit yourself this way.

andrewjswan commented 1 year ago

I cannot understand ukranian ;-).

Sorry, my English is not good, so I use a translator.

But if I understand correctly Спальня is sensor.spalnia_power, and you expect 9 sensors in this group as they are all part of the bedroom area?

Yes, that's right.

Are all these other 8 sensors created with powercalc or existing power sensors from another integration?

Where the True is, it is the sensor from PowerCalc

From Area:
sensor.bedroom_socket_power - power - 6.9 - False
sensor.nest_hub_bedroom_power - power - 0.39 - True
sensor.smart_power_strip_power - power - 6.9 - False
sensor.nest_mini_bedroom_power - power - 1.65 - True
sensor.lampa_spalnia_power - power - 0.64 - True
sensor.bedroom_christmas_light_power - power - 0.0 - False
sensor.spalnia_girlianda_device_power - power - 0.29 - True
sensor.bedroom_iron_power - power - 0.0 - False
sensor.spalnia_utiug_device_power - power - 0.29 - True
Count: 9

From Powercalc sensor:
sensor.nest_mini_bedroom_power - power - 1.65 - True
Count: 1

Could you share clean new debug logs?

Sure, I'll do it now and post it.

You could also search yourself for Including entities from area, that should also list the found entities in your area. Maybe you can find out the culprit yourself this way.

I'll see what I can find.

andrewjswan commented 1 year ago

I looked at the log file, it finds entities but doesn't add them. No errors, but the result is the same. home-assistant.log.zip

bramstroker commented 1 year ago

I suggest to create the groups using the GUI as also suggested in other issue. It should only be a few minutes work but should solve all your 3 issues, as it's less magic and far less complicated.

andrewjswan commented 1 year ago

I suggest to create the groups using the GUI as also suggested in other issue. It should only be a few minutes work but should solve all your 3 issues, as it's less magic and far less complicated.

How do I create a Group for Area in the GUI? I haven't found such an option.

bramstroker commented 1 year ago

How do I create a Group for Area in the GUI? I haven't found such an option.

See the documentation: https://homeassistant-powercalc.readthedocs.io/en/latest/group.html Click the blue button. Or click add entry from the integration page.

andrewjswan commented 1 year ago

See the documentation:

image I saw that, but when creating a Group, I can't select Area, only the sensors by name, and that doesn't work (just wanted to get rid of the template that collects the total power consumption by sensors name).

bramstroker commented 1 year ago

Area and the include options are not supported here in the GUI. You must specify the member sensors manually. But you won't have hundreds of them probably and it's only a one time task.

andrewjswan commented 1 year ago

But with each new device, I have to add them by hand. I want to get rid of that. And since powercalc integration has this feature, it would be great to make it work. It doesn't matter where to set it up, either in Yaml or in GUI. The main thing is that it works.

https://homeassistant-powercalc.readthedocs.io/en/latest/include-entities.html#area

bramstroker commented 1 year ago

I might have a look into excluding entities which your explicitely ignored in the discovery flow from the include area. But have no eta for that.

so for example assuming you have 3 lights in bedroom area which are discovered by powercalc:

These 3 are discovered and you click the blue button to accept for light.a and light.b.

No when you use the following configuration powercalc will only include the power sensors for light a and b in the group and not light c.

powercalc:
  sensors:
    - create_group: Bedroom
      include:
        area: bedroom

Currently it will include all 3 sensors, even the ones you did not accept or ignore.

andrewjswan commented 1 year ago

Currently it will include all 3 sensors, even the ones you did not accept or ignore.

I'm not ignoring anything, sensor by Area, should enable all sensors with device_class = power, if it doesn't specify exclude any sensors.

Right now, it feels like it only includes those sensors created by the powercalc integration in the GUI and ignores all others. But that's not true either, I have at least 4 devices in a given Area created in GUI (powercalc) and the sensor in the group is one and not 4.

Powercalc GUI created Sensors in Area

sensor.nest_hub_bedroom_power - power - 0.39 - True
sensor.lampa_spalnia_power - power - 0.64 - True
sensor.spalnia_girlianda_device_power - power - 0.29 - True
sensor.spalnia_utiug_device_power - power - 0.29 - True

Powercalc Automatic created Sensors in Area

sensor.nest_mini_bedroom_power - power - 1.65 - True
bramstroker commented 1 year ago

That's in the documentation, see the blue note. Only entities which don't require manual configuration are included. It's because of loading order of YAML entities which I can't influence. Manually configured power sensor using YAML could come later than an include group, so than I can't include that.

https://homeassistant-powercalc.readthedocs.io/en/latest/include-entities.html

I will have a look if I can include GUI manually configured power sensors, as these are created earlier than YAML sensors, so that would maybe be feasible.

Will add that to the feature request. https://github.com/bramstroker/homeassistant-powercalc/issues/1744

andrewjswan commented 1 year ago

Will add that to the feature request.

Did I understand correctly that a power sensor that is provided by another integration will not automatically be added to the group?

PS: How about adding an Area Group sensor to the GUI? And include all sensors with device_class - power in that Area?

bramstroker commented 1 year ago

Did I understand correctly that a power sensor that is provided by another integration will not automatically be added to the group?

Correct. currently not. Also , it's rather complicated to add. Multiple reasons for that, but I investigated in the past.

PS: How about adding an Area Group sensor to the GUI? And include all sensors with device_class - power in that Area?

Maybe in the future. Looked into to adding include capabilities to the group configuration. But need to have a look into how to do that cleanly. Maybe just only for the area option as that is most commonly used. Will be a nice addition and I definitely consider.

andrewjswan commented 1 year ago

Thank you, I will wait for the news.

PS: I don't quite understand what All standby power sensor does, and can it be turned off?

bramstroker commented 1 year ago

It is an automatic group sensor which will sum all the power where the source entity is turned off. You can just disable it if you don't want it.

bramstroker commented 1 year ago

I have rewritten a lot of logic regarding include functionality. You can try https://github.com/bramstroker/homeassistant-powercalc/releases/tag/v1.8.0-beta.3

It should include area entities in the group when the entity is set up with either:

So in your case you should get 5 sensors in the group now and not 1.

Only power/energy sensors created with Powercalc are included. Not from other integrations, this is also something I won't implement. When you also have other power sensors which you want to include in the group you can use this method: https://homeassistant-powercalc.readthedocs.io/en/latest/group.html#adding-non-powercalc-sensors

bramstroker commented 1 year ago

I have also added selection of area in the GUI group configuration. Let me know if it works for you. It's in v1.8.0-beta.5

Screenshot 2023-07-08 at 21 58 26
andrewjswan commented 1 year ago

Only power/energy sensors created with Powercalc are included. Not from other integrations, this is also something I won't implement.

Too bad, there was a hope that the integration would automatically collect all power sensors into one common one for Area. That would be power, add a sensor to an Area and it's already in the group, move a sensor from one Area to another and it's done. In my opinion, it should work like this. Maybe there is a possibility to add a setting, to include all sensors (if a group by Area is selected)?

Let me know if it works for you. It's in v1.8.0-beta.5

I'll give it a try, but from the description, it's not quite what I expected. I have a lot of power sensors from ESPHome, Shelly, Tuya devices and would like to be able to automatically add them to the group, with the ability to exclude those I don't need.

andrewjswan commented 1 year ago

Let me know if it works for you. It's in v1.8.0-beta.5

The group got together, all the power sensors from powercalc got in, the others didn't.

bramstroker commented 1 year ago

Also including non powercalc entities will be added with https://github.com/bramstroker/homeassistant-powercalc/pull/1752

andrewjswan commented 1 year ago

Do i have to reconfigure the group somehow? Because I installed 1.8.1, but it still shows 5 sensors in the Bedroom (Спальня) (from Powercalc), although if i make a selection by Area, there are 9 of them.

From Area:
sensor.bedroom_socket_power - power - 7.1 - Integration: Other
sensor.nest_hub_bedroom_power - power - 0.39 - Integration: Powercalc
sensor.smart_power_strip_power - power - 7.1 - Integration: Other
sensor.nest_mini_bedroom_power - power - 1.65 - Integration: Powercalc
sensor.lampa_spalnia_power - power - 0.64 - Integration: Powercalc
sensor.bedroom_christmas_light_power - power - 0.0 - Integration: Other
sensor.spalnia_girlianda_device_power - power - 0.29 - Integration: Powercalc
sensor.bedroom_iron_power - power - 0.0 - Integration: Other
sensor.spalnia_utiug_device_power - power - 0.29 - Integration: Powercalc
Count: 9

From Powercalc sensor:
sensor.spalnia_utiug_device_power - power - 0.29 - Integration: Powercalc
sensor.spalnia_girlianda_device_power - power - 0.29 - Integration: Powercalc
sensor.nest_mini_bedroom_power - power - 1.65 - Integration: Powercalc
sensor.nest_hub_bedroom_power - power - 0.39 - Integration: Powercalc
sensor.lampa_spalnia_power - power - 0.64 - Integration: Powercalc
Count: 5
bramstroker commented 1 year ago

Please enable powercalc debug logs, restart and check or share logs.

andrewjswan commented 1 year ago

share logs

In attach home-assistant.log.zip

bramstroker commented 1 year ago

Could you please try with v1.8.2, which I just released? Also the debug logs listing the include entities are a lot more compact in this version, so it's much easier to debug what goes wrong on your system. When still not working please share the debug logs generated with this version.

andrewjswan commented 1 year ago

Could you please try with v1.8.2, which I just released?

Only 5 sensor from 9 ...

home-assistant.log.zip

bramstroker commented 1 year ago

The lines below are relevant. I might change area id to the name of the area in the log, so it's more clear. But probably area 667bcf7b02e711eb90ffd1b0f1a2f3c7 is the bedroom area.

The 4 missing sensors are in the list of sensors powercalc finds in the area, so that's all good.

I will add a few extra debug logs to investigate why they are not added to the powercalc group, as they should.

2023-07-19 10:28:28.694 DEBUG (MainThread) [custom_components.powercalc.group_include.include] Including entities from area: 667bcf7b02e711eb90ffd1b0f1a2f3c7
2023-07-19 10:28:28.698 DEBUG (MainThread) [custom_components.powercalc.group_include.include] Found possible include entities: ['input_number.climat_bedroom_cold', 'input_number.climat_bedroom_warm', 'input_boolean.climat_bedroom_am', 'input_boolean.climat_bedroom_pm', 'input_boolean.climat_bedroom_workday', 'automation.bedroom_ac_am_schedule', 'automation.bedroom_ac_pm_schedule', 'automation.bedroom_ac_am_off', 'automation.bedroom_ac_pm_off', 'automation.alarm_bedroom', 'automation.bedroom_provetrivanie', 'automation.bedroom_provetrivanie_okoncheno', 'automation.bedroom_co2', 'device_tracker.bedroom_wall_panel', 'device_tracker.google_nest_mini_bedroom', 'device_tracker.htpc', 'device_tracker.h1pc', 'switch.htpc', 'switch.h1pc', 'device_tracker.bedroom_pc', 'climate.spalnia', 'input_boolean.climat_bedroom_action', 'device_tracker.google_nest_hub_mini_bedroom', 'device_tracker.google_tv_bedroom', 'switch.bedroom_tv', 'sensor.bedroom_energy', 'sensor.ble_temperature_alarm_clock', 'sensor.ble_humidity_alarm_clock', 'sensor.ble_battery_alarm_clock', 'sensor.ble_rssi_alarm_clock', 'binary_sensor.ble_light_bedroom_mi', 'binary_sensor.ble_motion_bedroom_mi', 'sensor.ble_illuminance_bedroom_mi', 'sensor.ble_battery_bedroom_mi', 'sensor.ble_rssi_bedroom_mi', 'sensor.bedroom_socket_current', 'sensor.bedroom_socket_power', 'sensor.bedroom_socket_voltage', 'switch.bedroom_google_tv_socket', 'switch.bedroom_tv_socket', 'switch.bedroom_google_mini_socket', 'switch.bedroom_usb_socket', 'binary_sensor.bedroom_oksana_status', 'switch.bedroom_oksana_restart', 'light.bedroom_oksana_neopixel', 'sensor.bedroom_oksana_uptime', 'sensor.bedroom_oksana_wifi_signal', 'sensor.bedroom_oksana_esphome_version', 'sensor.bedroom_oksana_uptime_formatted', 'binary_sensor.bedroom_andrey_status', 'sensor.bedroom_andrey_uptime', 'sensor.bedroom_andrey_wifi_signal', 'sensor.bedroom_andrey_esphome_version', 'sensor.bedroom_andrey_uptime_formatted', 'switch.bedroom_andrey_restart', 'light.bedroom_andrey_neopixel', 'media_player.kodi_bedroom', 'button.bedroom_sensair_s8_calibrate', 'button.bedroom_sensair_s8_calibrate_result', 'binary_sensor.bedroom_status', 'light.bedroom_neopixel', 'switch.bedroom_restart', 'switch.bedroom_automatic', 'sensor.bedroom_uptime', 'sensor.bedroom_wifi_signal', 'sensor.bedroom_co2', 'sensor.bedroom_esphome_version', 'sensor.bedroom_uptime_formatted', 'media_player.nest_hub_bedroom', 'sensor.nest_hub_bedroom_power', 'sensor.nest_hub_bedroom_energy', 'sensor.smart_power_strip_current', 'sensor.smart_power_strip_power', 'sensor.smart_power_strip_voltage', 'switch.smart_power_strip_socket_google_tv', 'switch.smart_power_strip_socket_tv', 'switch.smart_power_strip_socket_google_mini', 'switch.smart_power_strip_socket_usb', 'media_player.nest_mini_bedroom', 'sensor.nest_mini_bedroom_power', 'sensor.nest_mini_bedroom_energy', 'media_player.google_tv_bedroom', 'media_player.android_tv_bedroom', 'binary_sensor.h1pc_status', 'binary_sensor.h1pc_internet', 'binary_sensor.h1pc_meeting', 'sensor.h1pc_uptime', 'sensor.h1pc_cpu', 'sensor.h1pc_cpu0', 'sensor.h1pc_cpu1', 'sensor.h1pc_cpu2', 'sensor.h1pc_cpu3', 'sensor.h1pc_memory', 'sensor.h1pc_disk_c', 'sensor.h1pc_network_received', 'sensor.h1pc_network_sent', 'sensor.h1pc_network_total_received', 'sensor.h1pc_network_total_sent', 'light.nochnik_oksana', 'binary_sensor.nochnik_oksana_nightlight', 'light.nochnik_oksana_nightlight', 'light.nochnik_andrei', 'binary_sensor.nochnik_andrei_nightlight', 'light.nochnik_andrei_nightlight', 'sensor.ble_temperature_bedroom', 'sensor.ble_humidity_bedroom', 'sensor.ble_battery_bedroom', 'sensor.ble_voltage_bedroom', 'sensor.ble_rssi_bedroom', 'light.lampa_spalnia', 'sensor.lampa_spalnia_power', 'sensor.lampa_spalnia_energy', 'sensor.bedroom_window_uptime', 'sensor.bedroom_window_wifi_signal', 'sensor.bedroom_window_esphome_version', 'sensor.bedroom_window_uptime_formatted', 'light.bedroom_window_neopixel', 'binary_sensor.bedroom_window_status', 'switch.bedroom_window_restart', 'number.bedroom_window_fastled_speed', 'number.bedroom_window_fastled_variant', 'number.bedroom_window_fastled_palette', 'sensor.bedroom_window_device_temperature', 'sensor.bedroom_christmas_light_uptime', 'sensor.bedroom_christmas_light_wifi_signal', 'sensor.bedroom_christmas_light_energy', 'sensor.bedroom_christmas_light_voltage', 'sensor.bedroom_christmas_light_current', 'sensor.bedroom_christmas_light_power', 'sensor.bedroom_christmas_light_esphome_version', 'sensor.bedroom_christmas_light_uptime_formatted', 'binary_sensor.bedroom_christmas_light_status', 'binary_sensor.bedroom_christmas_light_overpowering', 'switch.bedroom_christmas_light_restart', 'switch.bedroom_christmas_light_switch', 'select.bedroom_christmas_light_power_on_default', 'sensor.spalnia_girlianda_device_power', 'sensor.spalnia_girlianda_device_energy', 'binary_sensor.bedroom_tv_status', 'sensor.bedroom_tv_uptime', 'sensor.bedroom_tv_wifi_signal', 'sensor.bedroom_tv_esphome_version', 'sensor.bedroom_tv_uptime_formatted', 'switch.bedroom_tv_restart', 'sensor.wallpanel_bedroom_battery_level', 'sensor.wallpanel_bedroom_light_level', 'sensor.wallpanel_bedroom_magnetic_field', 'binary_sensor.wallpanel_bedroom_motion', 'binary_sensor.wallpanel_bedroom_charging', 'binary_sensor.wallpanel_bedroom_ac_plugged', 'binary_sensor.bedroom_iron_status', 'binary_sensor.bedroom_iron_overpowering', 'select.bedroom_iron_power_on_default', 'switch.bedroom_iron_restart', 'switch.bedroom_iron_switch', 'sensor.bedroom_iron_uptime', 'sensor.bedroom_iron_wifi_signal', 'sensor.bedroom_iron_energy', 'sensor.bedroom_iron_voltage', 'sensor.bedroom_iron_current', 'sensor.bedroom_iron_power', 'sensor.bedroom_iron_esphome_version', 'sensor.bedroom_iron_uptime_formatted', 'sensor.spalnia_utiug_device_power', 'sensor.spalnia_utiug_device_energy', 'remote.google_tv_bedroom', 'media_player.google_tv_bedroom_remote']
bramstroker commented 1 year ago

Could you please overwrite config/custom_components/powercalc/group_include/include.py with https://gist.github.com/bramstroker/06181928e1a8dc03058eff26ffbcd40c? Restart after that and share logs again? Thanks.

andrewjswan commented 1 year ago

Restart after that and share logs again?

Very strange log, all sensors do not have a device_class, although in fact they do.

2023-07-24 10:31:49.202 DEBUG (MainThread) [custom_components.powercalc.group_include.include] _1: sensor.bedroom_socket_power - deviceclass=None

image

home-assistant.log.zip

andrewjswan commented 1 year ago

In other Area:

2023-07-24 10:31:49.219 DEBUG (MainThread) [custom_components.powercalc.group_include.include] _1: sensor.saeco_power - deviceclass=None

Its ESPHome entity with:

platform: hlw8012
power:
  name: "${name} Power"
  unit_of_measurement: W
  id: power
  device_class: power
  state_class: measurement
bramstroker commented 1 year ago

Do you have output from config/.storage/core.entity_registry from one of these entities.

andrewjswan commented 1 year ago

Do you have output from config/.storage/core.entity_registry from one of these entities.

Looked everywhere, this is the record "device_class": null everywhere, both Shelly's and ESPHome and others. It's very strange. Even weirder is that the sensor created by the power calc integration is the same:

      {
        "aliases": [],
        "area_id": null,
        "capabilities": {
          "state_class": "measurement"
        },
        "config_entry_id": "98b9df68861d708ce4786277d37e4e78",
        "device_class": null,
        "device_id": "724aadfbe386aaee3162783499d34703",
        "disabled_by": null,
        "entity_category": null,
        "entity_id": "sensor.gril_device_power",
        "hidden_by": null,
        "icon": null,
        "id": "4407a98ab55dec607d1052a569a5ea21",
        "has_entity_name": false,
        "name": null,
        "options": {
          "conversation": {
            "should_expose": false
          }
        },
        "original_device_class": "power",
        "original_icon": null,
        "original_name": "Гриль Device Power",
        "platform": "powercalc",
        "supported_features": 0,
        "translation_key": null,
        "unique_id": "pc_esp_nous_a1_grillswitchgrill_switch",
        "unit_of_measurement": "W"
      },

But "original_device_class": "power" seems to be correct everywhere.

      {
        "aliases": [],
        "area_id": null,
        "capabilities": null,
        "config_entry_id": "104fc37f242cb84638dd7e3abb21538c",
        "device_class": null,
        "device_id": "02a5fdeafb20ed677592fb178897a382",
        "disabled_by": null,
        "entity_category": null,
        "entity_id": "sensor.bedroom_socket_power",
        "hidden_by": null,
        "icon": null,
        "id": "e1cf612e61057a2687bf93e1eb448e19",
        "has_entity_name": false,
        "name": null,
        "options": {
          "conversation": {
            "should_expose": false
          }
        },
        "original_device_class": "power",
        "original_icon": null,
        "original_name": "Bedroom Socket Power",
        "platform": "localtuya",
        "supported_features": 0,
        "translation_key": null,
        "unique_id": "local_45863170c4dd57330bb0_19",
        "unit_of_measurement": "W"
      },
andrewjswan commented 1 year ago

Look: https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/entity.py#L132C15-L132C15

andrewjswan commented 1 year ago

And https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/entity_registry.py#L512-L513

andrewjswan commented 1 year ago

I add to log original device class output and get:

2023-07-24 14:20:35.115 DEBUG (MainThread) [custom_components.powercalc.group_include.include] _1: sensor.bedroom_socket_power - deviceclass=None - originaldeviceclass=power
2023-07-24 14:20:35.136 DEBUG (MainThread) [custom_components.powercalc.group_include.include] _1: sensor.grill_energy - deviceclass=None - originaldeviceclass=energy
2023-07-24 14:20:35.136 DEBUG (MainThread) [custom_components.powercalc.group_include.include] _1: sensor.grill_voltage - deviceclass=None - originaldeviceclass=voltage
2023-07-24 14:20:35.136 DEBUG (MainThread) [custom_components.powercalc.group_include.include] _1: sensor.grill_current - deviceclass=None - originaldeviceclass=current
2023-07-24 14:20:35.136 DEBUG (MainThread) [custom_components.powercalc.group_include.include] _1: sensor.grill_power - deviceclass=None - originaldeviceclass=power
bramstroker commented 1 year ago

Ok cool, thanks for the info. Will make some modifications later today or tomorrow to also look at the original_device_class. I think original is wat is configured by the integration code providing the entities, and device_class is a value which is potentially overwritten by the user.

So I will look at device_class first, and fallback to original_device_class when not set.

bramstroker commented 1 year ago

I see HA also does the same looking at the code you referred:

return entry.device_class or entry.original_device_class

andrewjswan commented 1 year ago

I see HA also does the same looking at the code you referred:

Wouldn't it be easier to use a helper? Then any change in it will immediately work in the integration.

https://github.com/home-assistant/core/blob/dev/homeassistant/helpers/entity.py#L132

andrewjswan commented 1 year ago

Any news?

bramstroker commented 1 year ago

Just a little patience ;-). Busy with work and life in general. Will probably work on powercalc this weekend.

bramstroker commented 1 year ago

Fixed with #1769. Are you able to try again by installing the latest master branch version?

andrewjswan commented 1 year ago

Are you able to try again by installing the latest master branch version?

For the Power sensor, everything is fine, everyone got into the group, but for Energy one didn’t get it, it was created in Integration - "platform": "integration", and in core.entity_registry it has "device_class": null, and "original_device_class": null , but in the configuration it is assigned device_class via customize. Like:

    sensor.bedroom_energy:
      friendly_name: Bedroom Energy
      device_class: energy
      state_class: total_increasing
      icon: mdi:lightning-bolt

I can probably remove it and create an energy sensor using PowerCalc.

But I still do not quite understand how to add it so that there is no duplication of sensors in the group.

andrewjswan commented 1 year ago

In Development tools i see

state_class: total_increasing
unit_of_measurement: kWh
icon: mdi:lightning-bolt
friendly_name: Bedroom Energy
device_class: energy
source: sensor.bedroom_socket_power
andrewjswan commented 1 year ago

I did not find how to create an Energy sensor in the GUI for an existing Power sensor, but I think it was before. Is it possible to add this?

bramstroker commented 1 year ago

Strange that device_class is missing here. How did you create the energy sensor? using the YAML for rieman integral sensor? https://www.home-assistant.io/integrations/integration/#yaml-configuration Anyway, you could just try to create an energy sensor with the GUI using the helpers section in HA. Select "Riemann sum" there. That would create a similar sensor as powercalc automatically creates for all virtual power sensors setup with powercalc.

Screenshot 2023-07-28 at 13 38 36
andrewjswan commented 1 year ago

Strange that device_class is missing here. How did you create the energy sensor? using the YAML for rieman integral sensor?

YAML

Select "Riemann sum" there. That would create a similar sensor as powercalc automatically creates for all virtual power sensors setup with powercalc.

I would not like to mix YAML and GUI in this case, but I will think about how it is more convenient to do it.

PS: I tried to create a general group in PowerCalc, but the list of subgroups is empty (although I have 2 groups for Area), open a new Issue?

andrewjswan commented 1 year ago

Anyway, you could just try to create an energy sensor with the GUI using the helpers section in HA.

Registered by hand device_class - energy, everything worked, I'll see how it will work.

bramstroker commented 1 year ago

PS: I tried to create a general group in PowerCalc, but the list of subgroups is empty (although I have 2 groups for Area), open a new Issue?

Yes please create a new issue.