bramstroker / homeassistant-powercalc

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

Reload every restart #1153

Closed screem20056 closed 1 year ago

screem20056 commented 2 years ago

Hi Fantastic job as always . One issue on my side every time i restart home assistant i need to go through each entity and reload it in order to show the sensor is there a soultion for this Regards

screem20056 commented 2 years ago

I enabled androidtv and powercalc logger. Nothing in the logs. I disconnected my lan cable from the tv and connected it to wifi. Still nothing, problem is the same. Removed androidtv integration and integrated tv again just using wifi, still no progress. When I restarted ha all entities disappeared just like in @screem20056 case and have to manually reload it to reaper. On startup it doesnt list any entities and it's blue configure button and I can open configuration.

😱😱😱😱 welcome to the club For the entities that work do you have tuya one of them

dandek01 commented 2 years ago

Yes, I do. I have tuya wifi switches and they work with powercalc, no issue. I integrated them with localtuya and tuya integration.

screem20056 commented 2 years ago

Yes, I do. I have tuya wifi switches and they work with powercalc, no issue. I integrated them with localtuya and tuya integration.

Do you have a repeater or wifi extender in the middle or it is directly connected to the router ?

dandek01 commented 2 years ago

I have wifi mesh network and I'm using xiaomi routers for it. I don't have wifi extender. I tried it and it doesnt work. All switches are directly connected to a router. But look I had a lot of problems with tuya wifi switches and majority was replaced with zigbee ones. Well they are again tuya based, its hard to dodge them, but now at they are working as expected. My network is kinda complicated. I have two local routers, one cisco dual wan router served as a gateway for local network and two lte routers for internet access. So I have five routers in my house currently.

bramstroker commented 2 years ago

I enabled androidtv and powercalc logger. Nothing in the logs.

You must have done something wrong configuration wise or not restarted after changing the configuration. Maybe you have several logger: entries, the second one overwriting the first. There must be at least 10's of log lines after you restarted.

dandek01 commented 2 years ago

Yeah, you right. I should look at full log. This is part of it for androidtv

2022-10-16 13:32:29.843 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] media_player.android_tv_192_168_31_5: Auto discovered model (manufacturer=Aqara, model=Android TV)
2022-10-16 13:32:29.843 DEBUG (MainThread) [custom_components.powercalc] media_player.android_tv_192_168_31_5: Model not found in library, skipping discovery
2022-10-16 13:32:29.916 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] media_player.android_tv_192_168_31_5: Auto discovered model (manufacturer=Aqara, model=Android TV)
2022-10-16 13:32:29.916 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=media_player.android_tv_192_168_31_5 entity_category=None, sensor_name=Android TV power strategy=FixedStrategy manufacturer= model= standby_power=5.00 unique_id=04:7a:0b:a1:a7:3d)
2022-10-16 13:32:29.916 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Android TV energy
2022-10-16 13:32:29.916 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy daily (entity_id=sensor.android_tv_energy_daily)
2022-10-16 13:32:29.916 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy weekly (entity_id=sensor.android_tv_energy_weekly)
2022-10-16 13:32:29.916 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy monthly (entity_id=sensor.android_tv_energy_monthly)
022-10-16 13:32:29.955 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.android_tv_power to device 97342280dac1048fa07af4313be90b34
2022-10-16 13:32:30.077 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.android_tv_energy to device 97342280dac1048fa07af4313be90b34
2022-10-16 13:32:30.077 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.android_tv_energy_daily to device 97342280dac1048fa07af4313be90b34
2022-10-16 13:32:30.078 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.android_tv_energy_weekly to device 97342280dac1048fa07af4313be90b34
2022-10-16 13:32:30.083 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.android_tv_energy_monthly to device 97342280dac1048fa07af4313be90b34
2022-10-16 13:32:39.865 DEBUG (MainThread) [custom_components.powercalc.sensors.power] media_player.android_tv_192_168_31_5: State changed to "off". Power:5.00

After restart there is no powercalc entities on android tv

dandek01 commented 2 years ago

After I reload androidtv in powercalc I got this in my logs

2022-10-16 13:41:02.643 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] media_player.android_tv_192_168_31_5: Auto discovered model (manufacturer=Beijing Xiaomi Electronics Co., Ltd., model=Android TV)
2022-10-16 13:41:02.643 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=media_player.android_tv_192_168_31_5 entity_category=None, sensor_name=Android TV power strategy=FixedStrategy manufacturer= model= standby_power=5.00 unique_id=04:7a:0b:a1:a7:3d)
2022-10-16 13:41:02.643 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Android TV energy
2022-10-16 13:41:02.644 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy daily (entity_id=sensor.android_tv_energy_daily)
2022-10-16 13:41:02.644 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy weekly (entity_id=sensor.android_tv_energy_weekly)
2022-10-16 13:41:02.644 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy monthly (entity_id=sensor.android_tv_energy_monthly)
2022-10-16 13:41:02.645 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.android_tv_power to device 97342280dac1048fa07af4313be90b34
2022-10-16 13:41:02.649 DEBUG (MainThread) [custom_components.powercalc.sensors.power] media_player.android_tv_192_168_31_5: State changed to "off". Power:5.00
2022-10-16 13:41:02.661 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.android_tv_energy to device 97342280dac1048fa07af4313be90b34
2022-10-16 13:41:02.661 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.android_tv_energy_daily to device 97342280dac1048fa07af4313be90b34
2022-10-16 13:41:02.662 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.android_tv_energy_weekly to device 97342280dac1048fa07af4313be90b34
2022-10-16 13:41:02.663 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.android_tv_energy_monthly to device 97342280dac1048fa07af4313be90b34
bramstroker commented 2 years ago

Yes, this is all looking fine. Similar as @screem20056. I see no indications of any issues in the logs. Could you check the following file config/.storage/core.entity_registry after startup and see if it contains the powercalc power and energy sensors?

dandek01 commented 2 years ago

I restarted again. No, there isn't. All others switches and lights have powercalc entities but androidtv doesnt have any. This is all I have for androidtv. I didnt reload powercalc for androidtv

{
    "area_id": "daniel_bedroom",
    "capabilities": {},
    "config_entry_id": "ccd4664092c798dbb883e7dc5648b072",
    "device_class": null,
    "device_id": "97342280dac1048fa07af4313be90b34",
    "disabled_by": null,
    "entity_category": null,
    "entity_id": "media_player.android_tv_192_168_31_5",
    "hidden_by": null,
    "icon": null,
    "id": "24b59ffa38c7b7765c35a11abfd6b319",
    "has_entity_name": false,
    "name": null,
    "options": {},
    "original_device_class": "tv",
    "original_icon": null,
    "original_name": "Android TV 192.168.31.5",
    "platform": "androidtv",
    "supported_features": 23997,
    "unique_id": "04:7a:0b:a1:a7:3d",
    "unit_of_measurement": null
  },
bramstroker commented 2 years ago

Could you add the following line at line 312 of config/custom_components/powercalc/sensor.py

_LOGGER.debug("Adding entities: %s", [entity.entity_id for entity in entities.new if isinstance(entity, SensorEntity)])

So it reads:

    if entities:
        _LOGGER.debug("Adding entities: %s", [entity.entity_id for entity in entities.new if isinstance(entity, SensorEntity)])
        async_add_entities(

And restart again.

dandek01 commented 2 years ago

I did but there is no powercalc entites. I have in manifest.json

"dependencies": [
    "light",
    "group",
    "template",
    "select",
    "utility_meter",
    "androidtv"
],

Didn't change it back.

This is sensor.py from line 311

if entities:
    _LOGGER.debug("Adding entities: %s", [entity.entity_id for entity in entities.new if isinstance(entity, SensorEntity)])
    async_add_entities(
    )

In config/.storage/core.entity_registry nothing changed. There is no powercalc entities for android tv

bramstroker commented 2 years ago

This addition will only add an additional line to the logs, it will not solve anything yet as I still don't have any clue why it is not working as supposed to be. Adding some logs to get a grasp of what is going on, because I'm unable to reproduce it myself. Just search for Adding entities: in the full logs after restart and share the result.

dandek01 commented 2 years ago

This is what I found in the logs

2022-10-16 14:15:53.407 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] media_player.android_tv_192_168_31_5: Auto discovered model (manufacturer=Aqara, model=Android TV)
2022-10-16 14:15:53.407 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=media_player.android_tv_192_168_31_5 entity_category=None, sensor_name=Android TV power strategy=FixedStrategy manufacturer= model= standby_power=5.00 unique_id=04:7a:0b:a1:a7:3d)
2022-10-16 14:15:53.407 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Android TV energy
2022-10-16 14:15:53.407 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy daily (entity_id=sensor.android_tv_energy_daily)
2022-10-16 14:15:53.408 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy weekly (entity_id=sensor.android_tv_energy_weekly)
2022-10-16 14:15:53.408 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy monthly (entity_id=sensor.android_tv_energy_monthly)
2022-10-16 14:15:53.408 DEBUG (MainThread) [custom_components.powercalc.sensor] Adding entities: ['sensor.android_tv_power', 'sensor.android_tv_energy', 'sensor.android_tv_energy_daily', 'sensor.android_tv_energy_weekly', 'sensor.android_tv_energy_monthly']

and in the end I have this

2022-10-16 14:15:53.411 DEBUG (MainThread) [custom_components.powercalc.sensor] Adding entities: ['sensor.dinning_room_light_power', 'sensor.dinning_room_light_energy', 'sensor.dinning_room_light_energy_daily', 'sensor.dinning_room_light_energy_weekly', 'sensor.dinning_room_light_energy_monthly']
2022-10-16 14:15:53.414 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up powercalc platform for sensor
Traceback (most recent call last):

Dining room light has entites and its working.

dandek01 commented 2 years ago

I reloaded android tv and this is what I got

2022-10-16 14:37:08.812 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] media_player.android_tv_192_168_31_5: Auto discovered model (manufacturer=Beijing Xiaomi Electronics Co., Ltd., model=Android TV)
2022-10-16 14:37:08.812 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=media_player.android_tv_192_168_31_5 entity_category=None, sensor_name=Android TV power strategy=FixedStrategy manufacturer= model= standby_power=5.00 unique_id=04:7a:0b:a1:a7:3d)
2022-10-16 14:37:08.813 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Android TV energy
2022-10-16 14:37:08.813 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy daily (entity_id=sensor.android_tv_energy_daily)
2022-10-16 14:37:08.813 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy weekly (entity_id=sensor.android_tv_energy_weekly)
2022-10-16 14:37:08.813 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy monthly (entity_id=sensor.android_tv_energy_monthly)
2022-10-16 14:37:08.814 DEBUG (MainThread) [custom_components.powercalc.sensor] Adding entities: ['sensor.android_tv_power', 'sensor.android_tv_energy', 'sensor.android_tv_energy_daily', 'sensor.android_tv_energy_weekly', 'sensor.android_tv_energy_monthly']
2022-10-16 14:37:08.816 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 281, in _async_setup_platform
await asyncio.shield(task)
File "/config/custom_components/powercalc/sensor.py", line 290, in async_setup_entry
await _async_setup_entities(hass, sensor_config, async_add_entities)
File "/config/custom_components/powercalc/sensor.py", line 313, in _async_setup_entities
async_add_entities(
TypeError: EntityPlatform._async_schedule_add_entities_for_entry() missing 1 required positional argument: 'new_entities'
bramstroker commented 2 years ago

This is what I found in the logs

2022-10-16 14:15:53.407 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] media_player.android_tv_192_168_31_5: Auto discovered model (manufacturer=Aqara, model=Android TV)
2022-10-16 14:15:53.407 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=media_player.android_tv_192_168_31_5 entity_category=None, sensor_name=Android TV power strategy=FixedStrategy manufacturer= model= standby_power=5.00 unique_id=04:7a:0b:a1:a7:3d)
2022-10-16 14:15:53.407 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Android TV energy
2022-10-16 14:15:53.407 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy daily (entity_id=sensor.android_tv_energy_daily)
2022-10-16 14:15:53.408 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy weekly (entity_id=sensor.android_tv_energy_weekly)
2022-10-16 14:15:53.408 DEBUG (MainThread) [custom_components.powercalc.sensors.utility_meter] Creating utility_meter sensor: Android TV energy monthly (entity_id=sensor.android_tv_energy_monthly)
2022-10-16 14:15:53.408 DEBUG (MainThread) [custom_components.powercalc.sensor] Adding entities: ['sensor.android_tv_power', 'sensor.android_tv_energy', 'sensor.android_tv_energy_daily', 'sensor.android_tv_energy_weekly', 'sensor.android_tv_energy_monthly']

and in the end I have this

2022-10-16 14:15:53.411 DEBUG (MainThread) [custom_components.powercalc.sensor] Adding entities: ['sensor.dinning_room_light_power', 'sensor.dinning_room_light_energy', 'sensor.dinning_room_light_energy_daily', 'sensor.dinning_room_light_energy_weekly', 'sensor.dinning_room_light_energy_monthly']
2022-10-16 14:15:53.414 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up powercalc platform for sensor
Traceback (most recent call last):

Dining room light has entites and its working.

You suppressed this last ERROR, that's definitely something here and should give some further pointers. Didn't you notice that error before?

dandek01 commented 2 years ago

No, I didnt. I would saw it in short logs while it send any error message to it. That is why in the begging I didnt see any error.

bramstroker commented 2 years ago

Could you share full logs after startup please? Not suppressing anything. You can export to a txt file and include it here to not pollute the issue to much wich large comments.

dandek01 commented 2 years ago

This is full log after restart. No entities for android tv log.txt

bramstroker commented 2 years ago

Ah I see you also changed async_add_entities() above, you only needed to add the _LOGGER line before this line (at 312), not change the other lines. That's why you have all these new errors now.

On startup I see: Adding entities: ['sensor.android_tv_power', 'sensor.android_tv_energy', 'sensor.android_tv_energy_daily', 'sensor.android_tv_energy_weekly', 'sensor.android_tv_energy_monthly']

Which is exactly as expected. I will do some digging through the HA core code to see if I can find anything which can cause the entities to not be created.

dandek01 commented 2 years ago

Can you post exactly how code from line 311 should look like. I copy pasted your code in the file.

bramstroker commented 2 years ago

Here you go: https://gist.github.com/bramstroker/db94897e836846215156703cde8a2749

dandek01 commented 2 years ago

As I was messing around with powercalc files, I re downloaded v1.0.0. beta 6. I paste sensor.py from you link and restarted. I'm sending you log files after restart, and after I reload androidtv to get entities.

reload_log.txt restart_log.txt

bramstroker commented 2 years ago

I still have no clue unfortunately, it's a very strange issue. As everything indicates the entity should be created correctly. I also compared you config entry to mine and it's exactly the same exact the unique_id (mac address) and the entity_id of the media player.

There is some strange error in your log which you should have a look at, but I doubt it's related to the powercalc issue.

2022-10-16 15:25:34.987 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 508, in async_update_ha_state
raise NoEntitySpecifiedError(
homeassistant.exceptions.NoEntitySpecifiedError: No entity id specified for entity 100 Registered

Could you try the following:

Restart and see if one of these options "survive" after restart (i.e. if the powercalc entities are created successfully)

dandek01 commented 2 years ago

For time being this just doesn't work. Never mind. This line you point out is perhaps my asteriks integration. This is the only entity 100. I'm experimenting with it. Trying to make successful call between my mob and intercom. For now I can call intercom from my mob, but I can't make call back.

bramstroker commented 2 years ago

@screem20056 @dandek01 I would definitely try to resolve this issue for you before releasing a v1.0.0 stable release, but not sure how to proceed as I'm unable to reproduce in any way.

I need your help in this to check if any of the following solves the issue.

Could you try disabling auto discovery in the YAML:

powercalc:
  enable_autodiscovery: false

And also try the options I asked to @dandek01 two replies above:

Could you try the following:

Restart and see if one of these options "survive" after restart (i.e. if the powercalc entities are created successfully)

dandek01 commented 2 years ago

Hi, I disabled autodiscovery in configuration.yaml file. I created another powercalc meter for android tv. It didn't survive restart. Here is the log. log.txt

bramstroker commented 2 years ago

I also see lines like this:

2022-10-23 12:24:58.729 DEBUG (MainThread) [custom_components.powercalc.sensors.power] media_player.android_tv_192_168_31_5: State changed to "standby". Power:5.00

Which indicates that the entity should be in your HA instance. Maybe it's not bound to the config entry for whatever reason.

Could you search for media_player.android_tv_192_168_31_5 in entities tab under "Settings" -> "Devices & Entities"? Can you find it there?

You are only using the GUI config flow or did you also define entities using the YAML approach?

dandek01 commented 2 years ago

Yes, I can find media_player.android_tv_192_168_31_5. It's there. I didn't define anything in yaml, I just used gui. Should I try something like utility_meter: daily_energy_daniel_bedroom: source: sensor.daniel_bedroom_smart_plug_energy cycle: daily

bramstroker commented 2 years ago

Yes, I can find media_player.android_tv_192_168_31_5.

I'm sorry, I meant to ask for entity_id sensor.android_tv_power

I didn't define anything in yaml, I just used gui. Should I try something like utility_meter: daily_energy_daniel_bedroom: source: sensor.daniel_bedroom_smart_plug_energy cycle: daily

I think you are mixing up things here. Your problem was no powercalc entities were appearing after restart right (no power, energy and utility_meters)? Or do you only have a problem with the utility meters?

dandek01 commented 2 years ago

No, there isnt sensor.android_tv_power

Your problem was no powercalc entities were appearing after restart right (no power, energy and utility_meters)? Yes, that is my problem.

bramstroker commented 2 years ago

You can try creating a sensor with YAML like this:

sensor:
  - platform: powercalc
    entity_id: media_player.android_tv_192_168_31_5
    unique_id: 6cc63373-3f11-4785-9903-59870bb956f8
    name: Android TV YAML
    standby_power: 5
    fixed:
      power: 45

Normally this would work without a unique_id, as it will take the unique_id from the source entity media_player.android_tv_192_168_31_5, but to make sure it does not give any conflicts with the powercalc sensors which are setup with the GUI flow I just gave it some unique id

After restarting you should have a sensor sensor.android_tv_yaml_power

One other thing you can try for the GUI sensor is to toggle both create energy sensors and utility meters off. Than it will only create a power meter and we have the most simple approach. Problems like this are best debugged by eliminating potential issues and bringing things back to basics as much as possible.

dandek01 commented 2 years ago

I can't create sensor in yaml as there is some error when I check configuration. This is sensors.yaml file

- platform: powercalc
  sensors:
      entity_id: sensor.android_tv_energy_daily
      unique_id: 6cc63373-3f11-4785-9903-59870bb956f8
      name: Android TV YAML
      standby_power: 5
      fixed:
        power: 45

And this is error on check configuration Invalid config for [sensor.powercalc]: must contain at least one of entity_id, entities, include, daily_fixed_energy.. Got OrderedDict([('platform', 'powercalc'), ('sensors', OrderedDict([('entity_id', 'sensor.android_tv_energy_daily'), ('unique_id', '6cc63373-3f11-4785-9903-59870bb956f8'), ('name', 'Android TV YAML'), ('standby_power', 5), ('fixed', OrderedDict([('power', 45)]))]))]). (See ?, line ?).

Spacing is oke in editor, but when I copy/paste it spacing was reformat. I tried also with media_player.android_tv_192_168_31_5

Edit: I tried to toggle both create energy sensors and utility meters off but again the same problem. Sensor sensor.android_tv_power wasnt created, I had to reload integration.

bramstroker commented 2 years ago

When you place it in sensors you don't need to use sensors or sensor again.

Just put in:

- platform: powercalc
  entity_id: sensor.android_tv_energy_daily
  unique_id: 6cc63373-3f11-4785-9903-59870bb956f8
  name: Android TV YAML
  standby_power: 5
  fixed:
    power: 45
dandek01 commented 2 years ago

Try it it wont work that way. I have in sensors.yaml file for other sensors

bramstroker commented 2 years ago

This sensors property is only needed for template sensors or maybe some other. But most platforms don't use that. Also see here: https://www.home-assistant.io/docs/configuration/splitting_configuration/. And search for sensor.yaml there you'll find an example.

Make sure your indenting is correct because that's very important in YAML.

You config needs to look something like this:

- platform: template
  sensors:
    ...
- platform: powercalc
  entity_id: sensor.android_tv_energy_daily
  unique_id: 6cc63373-3f11-4785-9903-59870bb956f8
  name: Android TV YAML
  standby_power: 5
  fixed:
    power: 45
dandek01 commented 2 years ago

I checked my configuration.yaml file. I created this when I first started with home assistant. I had this line sensor: !include sensors.yaml and I change this now to sensor: !include sensor.yaml I renamed sensors.yaml to sensor.yaml Now. I can with out any errors add to my sensor.yaml file

When I restarted home assistant I saw this in my logs, didn't saw it befroe 2022-10-23 19:16:47.118 WARNING (MainThread) [homeassistant.components.integration.sensor] sensor.android_tv_yaml_energy could not restore last state unknown: [<class 'decimal.ConversionSyntax'>]

I have this in my configuration.yaml file group: !include groups.yaml automation: !include automations.yaml script: !include script.yaml scene: !include scene.yaml sensor: !include sensor.yaml binary_sensor: !include binary_sensor.yaml template: !include templates.yaml

bramstroker commented 2 years ago

That warning would be expected, because it takes some time for the energy sensor to calculate an initial value.

But you should have sensor.android_tv_yaml_power and sensor.android_tv_yaml_energy now. Just check if they are working as expected an are surviving restarts. When these are surviving restart there is something picky about the GUI setup, not sure what as it is using exactly the same logic and all your other GUI sensors are working fine. But at least you'll have a "solution" now by just setting up this particular sensor with YAML, so you don't need to reload everytime.

dandek01 commented 2 years ago

Yes, senors sensor.android_tv_yaml_power and sensor.android_tv_yaml_energy survived restart but again I have to reload andoid tv to get sensors back. When I check it on developer tools -> sensors created by powercalc are not listed. I tried this, instead of entity_id: media_player.android_tv_192_168_31_5 I put in sesnor.yaml entity_id: sensor.android_tv_power

I restarted home assistant and check for sensors in developer tools -> states. All sensors from powercalc integration for android tv are listed and available, I can open them to check current values but they doesn show on powercalc integration -> android tv and energy dashboard is complaining with Check the integration or your configuration that provides: sensor.android_tv_energy When I open energy Android TV energy is listed no errors. Before it was listed as sensor.android_tv_power

bramstroker commented 2 years ago

YAML currently creates the following sensors:

GUI creates the following sensors:

Entity_id for the yaml sensor needs to be the entity id of the source (in this case the media player), so you must NOT change that.

Of course you still need to reload to get sensor.android_tv_power available as nothing has changed about them, they still are create by the GUI config, as it always was.

When you want the YAML configuration to create sensor.android_tv_power you can change the name to Android TV, and make sure to remove the configuration entry in the GUI.

Or you can just reference sensor.android_tv_energy_yaml in the energy dashboard.

dandek01 commented 2 years ago

I remove android tv from powercalc integration and went just for yaml file. This is what I have in sensor.yaml

 - platform: powercalc
   entity_id: sensor.android_tv_power
   unique_id: 6cc63373-3f11-4785-9903-59870bb956f8
   name: Android TV
   standby_power: 5
   fixed:
     power: 45

After restart I have sensor.android_tv_yaml_energy and it has survived. I added it to energy dashboard and there isnt any errors any more.

screem20056 commented 2 years ago

Hi i was travelling and not up to date so the idea now is to remove all gui created entities and shift them to yaml then they survive the restart Unusual...

bramstroker commented 2 years ago

At least that is working, but not a real solution. I have asked @dandek01 to try this method to see if they survive the restart. When the YAML approach also had the same issue I hoped to get some more insights in the root cause. However still have no clue why the GUI setup routine is behaving differently. Walked through the core code a few times, but that's also complex as it's asynchronous in nature. I cannot figure out yet where the bug is. Not sure how to make any further progress on this. Also you two guys are the only ones reporting this problem among thousands of users of the integration. which makes it very hard to debug. Will ask on discord channel if anyone has an idea.

screem20056 commented 1 year ago

Hi Just worked like a crazy on yaml file i moved all the tuya devices to yaml and it worked out

jfgirouxhome commented 1 year ago

Same issue for me. Only for Tuya after restart and it worked when I move the config from GUI to yaml.

bramstroker commented 1 year ago

Sad to hear you are also experiencing issues with the power sensors configured using the GUI. When more people chime in which have also issues with TuYa I will consider buying a device myself so I will hopefully be able to reproduce and solve the issue. It's Wifi, right? What do I need exactly to get a setup running?

dandek01 commented 1 year ago

I doesn't have to do with a device or integration. I have tuya wifi switches and there is no problem with your integration. Maybe we have something that is misconfigured in our setup and that we are not aware of. Like my sensor/sensors.yaml file. And this is probably more the case then your integration.

dandek01 commented 1 year ago

Hi, I managed to fix my issues with android tv. I have android tv that has built in chromecast. I have google cast integration for that tv in home assistant. Instead of using media_player.android_tv_192_168_31_5 that is entity for my android tv I used media_player.bedroom_tv that is entity for the same device but on chromecast integration. And it just works. When I restarted home assistant all powercalc entites for android tv were there. I removed lines from yaml file and created integration in gui. No more reload. In my case I have two integration basically controlling on device. One integration is android tv for tv itself and other one is google cast for controling built in chromecast in the same tv. And for some reason entity created with android tv integration was or is making problems with powercalc integration. Edit: I also downgraded to the latest stable version of powercalc 0.26.1 and its working.

bramstroker commented 1 year ago

@dandek01 Thanks for the extra information. Not sure how it would help me though as I was unable to reproduce the issue with android TV integration in the first place. But maybe this can be helpful for others.

I also downgraded to the latest stable version of powercalc 0.26.1 and its working.

What do you mean with this? That it continued to work for media_player.android_tv_192_168_31_5 again after downgrading?

dandek01 commented 1 year ago

I'm currently using latest stable version of power calc. But I noticed one thing when I installed zigbee led strip on my tv. I made and automation to turn on led when tv is on and to turn if off when tv is off. It works but only when I'm watching youtube. If I switch to terrestrial tv it turns led off. I went to powercalc and saw that measuring while watching live tv is 5w like when tv is off. I don't know why. Perhaps casting is off.
Edit: It works with media_player.bedroom_tv but this is entity created by google cast integration as tv has built in chromecast device. Entity media_player.android_tv_192_168_31_5 never survived restart and this is entity created by android tv integration. I don't know why is happening. The same device is using two different entities created by two different integrations.

bramstroker commented 1 year ago

Could you please create another issue when you have other questions, this particular issue is getting completely out of control this way.