Giter Site home page Giter Site logo

Comments (8)

bramstroker avatar bramstroker commented on August 12, 2024

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

from homeassistant-powercalc.

bramstroker avatar bramstroker commented on August 12, 2024

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?

from homeassistant-powercalc.

bramstroker avatar bramstroker commented on August 12, 2024

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.

from homeassistant-powercalc.

NachtaktiverHalbaffe avatar NachtaktiverHalbaffe commented on August 12, 2024

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?

from homeassistant-powercalc.

bramstroker avatar bramstroker commented on August 12, 2024

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.

from homeassistant-powercalc.

bramstroker avatar bramstroker commented on August 12, 2024

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.

from homeassistant-powercalc.

NachtaktiverHalbaffe avatar NachtaktiverHalbaffe commented on August 12, 2024

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

from homeassistant-powercalc.

bramstroker avatar bramstroker commented on August 12, 2024

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.

from homeassistant-powercalc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.