bramstroker / homeassistant-powercalc

Custom component to calculate estimated power consumption of lights and other appliances
MIT License
896 stars 250 forks source link

New smart plug won't show energy sensor #2305

Closed igorsantos07 closed 1 week ago

igorsantos07 commented 1 week ago

System Health details

System Information

version core-2024.6.2
installation_type Home Assistant OS
dev false
hassio true
docker true
user root
virtualenv false
python_version 3.12.2
os_name Linux
os_version 6.6.31-haos-raspi
arch aarch64
timezone America/Sao_Paulo
config_dir /config
Home Assistant Community Store GitHub API | ok -- | -- GitHub Content | ok GitHub Web | ok GitHub API Calls Remaining | 5000 Installed Version | 1.34.0 Stage | running Available Repositories | 1389 Downloaded Repositories | 59
AccuWeather can_reach_server | ok -- | -- remaining_requests | 33
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 12.4 -- | -- update_channel | stable supervisor_version | supervisor-2024.06.0 agent_version | 1.6.0 docker_version | 26.1.4 disk_total | 28.5 GB disk_used | 19.6 GB healthy | true supported | true host_connectivity | true supervisor_connectivity | true ntp_synchronized | true virtualization | board | rpi3-64 supervisor_api | ok version_api | ok installed_addons | Duck DNS (1.17.0), File editor (5.8.0), AirCast (4.2.1), Home Assistant Google Drive Backup (0.112.1), Advanced SSH & Web Terminal (18.0.0), Grocy (0.21.0), RPC Shutdown (2.5), Scrypted (v0.111.0-jammy-full)
Dashboards dashboards | 6 -- | -- resources | 39 views | 16 mode | storage
Recorder oldest_recorder_run | June 10, 2024 at 01:53 -- | -- current_recorder_run | June 19, 2024 at 22:07 estimated_db_size | 350.89 MiB database_engine | sqlite database_version | 3.44.2
Sonoff version | 3.7.3 (e240aaf) -- | -- cloud_online | 6 / 6 local_online | 6 / 6

Checklist

Describe the issue

First of all, sorry if this is a duplicated. I swear I searched around, but given it seems a pretty common problem if it is really a problem...

Anyway, I bought 4 of those generic Tuya smart plugs and distributed around the house, and configured them at different times. My fridge one is working great, as expected. However, I cannot seem to be able to create the energy sensor for one of the other plugs. I'm not sure if this could be caused by a naming confusion I made, where I renamed some plugs (as I had mixed them for installing all at the same time lol).

HA log states power sensors were not created as, indeed, they weren't needed for smart plugs - actually, I would even say this shouldn't cause an error entry?

HA log This error originated from a custom integration. Logger: custom_components.powercalc.sensor Source: custom_components/powercalc/sensor.py:382 integration: Powercalc (documentation, issues) First occurred: 00:36:18 (11 occurrences) Last logged: 01:12:07 sensor.tomada_power: This entity has already configured a power sensor. When you want to configure it twice make sure to give it a unique_id sensor.escritorio_pc_power: This entity has already configured a power sensor. When you want to configure it twice make sure to give it a unique_id sensor.cinema_pc_power: This entity has already configured a power sensor. When you want to configure it twice make sure to give it a unique_id sensor.quarto_tv_tomada_active_power: This entity has already configured a power sensor. When you want to configure it twice make sure to give it a unique_id

Reproduction steps

  1. HA > Integrations > PowerCalc > Add Entry
  2. Energy from real power sensor
  3. write a name, select the power sensor and the device; leave the utility meters off.
  4. Yay, it confirmed it worked!
  5. However, no energy sensor: image image

...

Debug logs

home-assistant_powercalc_2024-06-20T04-18-24.315Z.log

Diagnostics dump or YAML config

config_entry-powercalc-4c036dd8b51062d912e31c4ff5da0031.json

bramstroker commented 1 week ago

Looking at the logs you have the following error:

sensor.cinema_pc_power: This entity has already configured a power sensor. When you want to configure it twice make sure to give it a unique_id

I means you have setup the config flow twice selecting the same source entity.

Please check in the integration listing in powercalc page if you have setup a duplicate.

igorsantos07 commented 1 week ago

I think I had, indeed, created a dupe to try to repeat the issue. I didn't understand that error message as the one I would be looking for, since the device is missing an energy sensor; the power sensor is already present, given it is a smart plug that already provides one.

I erased the entries in the PowerCalc page and recreated it, debug logs here. HA still states the same, about the repeated power sensor.

bramstroker commented 1 week ago

@igorsantos07 This is very strange. I expect to see at least a few times Creating energy sensor in the logs, but there is none such entry. Only errors about: this entity has already configured ..... This error should only appear when there was a succesfull setup for the same sensor in the first place.

Could you share a screenshot of all the powercalc configurations you have setup? And ideally also download and share the diagnostics for all of them?

Did you also define sensors using YAML configuration or did you only use the GUI?

Are you using latest version of Powercalc?

igorsantos07 commented 1 week ago

Strange indeed! haha

All GUI, latest version. The only mention to powercalc in my YAML files was enabling the debug logger, which could be helpful so I enabled it as well. After some restarts and the fact I changed tabs to other problematic integrations and forgot this one (lol), I enabled debug logging for PowerCalc, and went to delete the affected device........... guess what, the energy sensor was there :joy:

I'm glad I took screenshots, so you don't think I'm a liar. At some point, in between this morning and my last posts, the sensor was created - I know because when I saw your message this morning I took an early screenshot from the list, before wandering away, and the entity was already there.

2024-06-22 18:24:28.720 DEBUG (MainThread) [custom_components.powercalc.discovery] sensor.tomada_do_pc_do_cinema_energy: Auto discovered model (manufacturer=Tuya, model=Smart Plug (j20xh6tbtz8rn2sr)) 2024-06-22 18:24:28.721 DEBUG (MainThread) [custom_components.powercalc.discovery] sensor.tomada_do_pc_do_cinema_energy: Model not found in library, skipping discovery 2024-06-22 18:24:29.338 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor (entity_id=sensor.tomada_do_pc_do_cinema_energy, source_entity=sensor.cinema_pc_power, unit_prefix=k)

Then, I created the sensors for the last power plug... and the energy entity was created correctly.

Bottom-line: I guess the culprit is the wind :man_shrugging: Thanks for the emotional support anyway :joy:

igorsantos07 commented 1 week ago

I just set up two other devices (so I could erase my old "integral sensors" from my smart ACs) and, again, the entities were created correctly - even though the devices already had an energy sensor (not with the same entity ID, though).

bramstroker commented 1 week ago

Oh haha, glad you got it resolved. Must be the wind :wink: Keep an eye on it, let me know if you experience any errors or stability issues.