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

Entities manually configured in configuration.yaml are not recognized by powercalc #52

Closed
felipebbmp opened this issue Jul 20, 2021 · 8 comments

Comments

@felipebbmp
Copy link

felipebbmp commented Jul 20, 2021

Hi guys

I have 5 switch entities and 2 light entities configured manually in my configuration.yaml, but none of them the electrical consumption sensor works only in auto-discoveries.

This is an example of a part of my configuration and my problem:

switch in configuration.yaml:

 - platform: mqtt
    name: Central Cozinha
    state_topic: "mr2/status"
    command_topic: "mr2/cmd"
    payload_on: "1"
    payload_off: "0"
    state_on: "1"
    state_off: "0"

sensor in configuration.yaml:

 - platform: powercalc
   entity_id: switch.central_cozinha
   standby_usage: 0.6
   fixed:
     power: 36.9

Log:

2021-07-20 17:28:51 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up powercalc platform for sensor
Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 250, in 
_async_setup_platform
    await asyncio.shield(task)
  File "/home/homeassistant/.homeassistant/custom_components/powercalc/sensor.py", line 120, in async_setup_platform
   entity_name = entity_state.name
AttributeError: 'NoneType' object has no attribute 'name'

What should i do to solve this problem? I thank the attention.

Sorry for formatting the codes, I had problems with formatting the text here.

@bramstroker
Copy link
Owner

Thanks for reporting. I have formatted the code. Think I will be able to reproduce and fix the issue with this information

@bramstroker
Copy link
Owner

bramstroker commented Jul 23, 2021

I am not able to reproduce this issue yet.

Have the following configuration:

switch:
  - platform: mqtt
    name: Mqtt
    state_topic: "mr2/status"
    command_topic: "mr2/cmd"
    payload_on: "1"
    payload_off: "0"
    state_on: "1"
    state_off: "0"
sensor:
  - platform: powercalc
    entity_id: switch.mqtt
    standby_usage: 0.6
    fixed:
      power: 36.9

and in my log:
2021-07-23 16:23:51 DEBUG (MainThread) [custom_components.powercalc.sensor] Setting up power sensor. entity_id:switch.mqtt sensor_name:Mqtt power strategy=FixedStrategy manufacturer= model= standby_usage=0.6

Which version of home assistant are you running?

@bramstroker
Copy link
Owner

Could you enable debug logging for both powercalc and mqtt?

logger:
  default: warning
  logs:
    custom_components.powercalc: debug
    homeassistant.components.mqtt: debug

Next restart home assistant, wait for the power calc sensor error, and post the full logs from the beginning of the restart.

@NachtaktiverHalbaffe
Copy link
Contributor

Have also a similiar problem to this. In my case in combination with flux_led. The logs from startup:

2021-07-30 16:55:12 WARNING (SyncWorker_1) [homeassistant.loader] We found a custom integration truenas which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-07-30 16:55:12 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration powercalc which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-07-30 16:55:12 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration skodaconnect which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-07-30 16:55:12 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration alexa_media which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-07-30 16:55:12 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration fontawesome which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-07-30 16:55:12 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-07-30 16:55:12 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration rki_covid which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-07-30 16:55:12 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration cryptoinfo which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-07-30 16:55:12 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration spotcast which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2021-07-30 16:55:15 WARNING (MainThread) [alexapy.alexalogin] No access token found; falling back to credential login instead of oauth.
2021-07-30 16:55:16 WARNING (MainThread) [homeassistant.config_entries] Config entry 'InternetGatewayDeviceV2 - FRITZ!Box 7490 (UI)' for upnp integration not ready yet: None; Retrying in background
2021-07-30 16:55:16 WARNING (MainThread) [homeassistant.config_entries] Config entry 'FRITZ!Box 7490 (UI)' for upnp integration not ready yet: None; Retrying in background
2021-07-30 16:55:16 DEBUG (MainThread) [custom_components.powercalc.sensor] Setting up power sensor. entity_id:light.deckenlicht_wohnzimmer1 sensor_name:Deckenlicht Wohnzimmer 1 power strategy=LinearStrategy manufacturer= model= standby_usage=0.2
2021-07-30 16:55:16 DEBUG (MainThread) [custom_components.powercalc.sensor] Setting up power sensor. entity_id:light.deckenlicht_wohnzimmer2 sensor_name:Deckenlicht Wohnzimmer 2 power strategy=LinearStrategy manufacturer= model= standby_usage=0.2
2021-07-30 16:55:16 DEBUG (MainThread) [custom_components.powercalc.sensor] Setting up power sensor. entity_id:light.deckenlicht_wohnzimmer3 sensor_name:Deckenlicht Wohnzimmer 3 power strategy=LinearStrategy manufacturer= model= standby_usage=0.2
2021-07-30 16:55:16 DEBUG (MainThread) [custom_components.powercalc.sensor] Setting up power sensor. entity_id:light.deckenlicht_schreibtisch sensor_name:Deckenlicht Schreibtisch power strategy=LinearStrategy manufacturer= model= standby_usage=0.2
2021-07-30 16:55:16 DEBUG (MainThread) [custom_components.powercalc.sensor] Setting up power sensor. entity_id:media_player.lg_fernseher sensor_name:LG Fernseher power strategy=FixedStrategy manufacturer= model= standby_usage=0.5
2021-07-30 16:55:16 DEBUG (MainThread) [custom_components.powercalc.sensor] Setting up power sensor. entity_id:binary_sensor.desktop sensor_name:Desktop power strategy=FixedStrategy manufacturer= model= standby_usage=0.0
2021-07-30 16:55:16 DEBUG (MainThread) [custom_components.powercalc.sensor] Setting up power sensor. entity_id:binary_sensor.hassio_virtural_machine_running sensor_name:KingKong strategy=FixedStrategy manufacturer= model= standby_usage=0.0
2021-07-30 16:55:16 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 250, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/powercalc/sensor.py", line 120, in async_setup_platform
entity_name = entity_state.name
AttributeError: 'NoneType' object has no attribute 'name'
2021-07-30 16:55:16 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 250, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/powercalc/sensor.py", line 120, in async_setup_platform
entity_name = entity_state.name
AttributeError: 'NoneType' object has no attribute 'name'
2021-07-30 16:55:24 WARNING (MainThread) [homeassistant.components.light] Setup of light platform flux_led is taking over 10 seconds.
2021-07-30 16:55:30 WARNING (SyncWorker_4) [homeassistant.components.tplink.common] Unable to communicate with device 192.168.178.75: Communication error
2021-07-30 16:55:30 WARNING (MainThread) [homeassistant.components.switch] Platform tplink not ready yet: None; Retrying in background in 30 seconds
2021-07-30 16:55:53 DEBUG (MainThread) [custom_components.powercalc.sensor] State changed to "on" for entity "light.deckenlicht_wohnzimmer1". Power:5.98
2021-07-30 16:55:53 DEBUG (MainThread) [custom_components.powercalc.sensor] State changed to "on" for entity "light.deckenlicht_wohnzimmer2". Power:5.98
2021-07-30 16:55:53 DEBUG (MainThread) [custom_components.powercalc.sensor] State changed to "on" for entity "light.deckenlicht_wohnzimmer3". Power:5.98
2021-07-30 16:55:53 DEBUG (MainThread) [custom_components.powercalc.sensor] State changed to "on" for entity "light.deckenlicht_schreibtisch". Power:8.47
2021-07-30 16:55:53 DEBUG (MainThread) [custom_components.powercalc.sensor] State changed to "off" for entity "media_player.lg_fernseher". Power:0.5
2021-07-30 16:55:53 DEBUG (MainThread) [custom_components.powercalc.sensor] State changed to "on" for entity "binary_sensor.desktop". Power:90.0
2021-07-30 16:55:53 DEBUG (MainThread) [custom_components.powercalc.sensor] State changed to "on" for entity "binary_sensor.hassio_virtural_machine_running". Power:120.0
2021-07-30 16:55:57 WARNING (SyncWorker_3) [homeassistant.components.tplink.common] Unable to communicate with device 192.168.178.75: Communication error

My yaml-config for the lights:

- platform: flux_led
  automatic_add: true
  devices:
    !secret IP_LED_Fernseher:
      name: LED Fernseher
      mode: "rgb"
    !secret IP_LED_Couchtisch:
      name: LED Couchtisch
      mode: "rgb"

My yaml- config for powercalc:

- platform: powercalc
  entity_id: light.led_couchtisch
  name: "Licht LED Couchtisch"
  standby_usage: 0.2
  linear:
    min_power: 0
    max_power: 36
- platform: powercalc
  entity_id: light.led_fernseher
  name: "Licht LED Couchtisch"
  standby_usage: 0.2
  linear:
    min_power: 0
    max_power: 14.4

I have HA 2021.7.4 running. Powercalc is setting up before flux_led (my lights), so could this be a problem?

@bramstroker
Copy link
Owner

Yes I think it's the order in which integrations are loaded. I made my integration dependant on some other integrations to make sure they are loaded first, but I cannot add all kind of exotic integrations as a dependency. At the moment the powercalc integration is trying to get the name of your device it was not created yet by the flux_led integration.

I wanted to propose a workaround to see if adding the name property would help, but I see you already specified a name yourself. The error is thrown when the powercalc integration is trying to retrieve the name of the device you are setting up the virtual power sensor. However I don't need to do that when you manually specify a name for the power sensor. Will have a look if I can fix this logic.

@bramstroker
Copy link
Owner

I just modified the code to extract the name and entity domain from the entity_id, this should get rid of the error you both reported here and should make the power sensor work.
Are you able to test with the master branch?
When it is solved for you I will create a new release.

@NachtaktiverHalbaffe
Copy link
Contributor

I installed the master branch via HACS and in my case everything works now 👍

I'm not deeply into the Home assistant architecture, but is there a way to check if all entities from a domain e.g. lights are loaded? In long term this would be the best solution, to check if all supported domains are fully loaded and then load the powercalc component. Checking via some integration dependencys seems to be annoying in long term, a approach via domains seems more promising if possible

@bramstroker
Copy link
Owner

Nice that it's working for you! The fix is in version 0.2.7

I did have a look around the home assistant codebase how to check if all entities from a domain (ie light) are initialized, but could not really find anything. Also the developers docs and architecture does not mention this.
However the solution I implemented now should fix for all possible use cases and entity types, so no need to search further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants