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

bramstroker commented 2 years ago

When you setup a new sensor using the GUI there is no need to restart. Setting up a sensor using YAML requires a restart, unfortunately this is something the HA architecture enforces and there are no workaround for that.

screem20056 commented 2 years ago

Thanks i understand but i meant after i set the sensor with GUI and they are working perfectly. But the issue is when i restart HA they don't show up i need to go through each entity and reload it to make sensor show again Thanks

screem20056 commented 2 years ago

Worthy to mention is that the first entity show sensor adter restart but i have 7 other which failed to

bramstroker commented 2 years ago

Thanks i understand but i meant after i set the sensor with GUI and they are working perfectly. But the issue is when i restart HA they don't show up i need to go through each entity and reload it to make sensor show again Thanks

That's strange, did not see that behaviour before. Any clues in the logs? When there are no errors in the logs I suggest to enable debug logging for powercalc (see last section of readme).

bramstroker commented 2 years ago

Btw do you have the following in configuration.yaml as described in installation steps.

powercalc:

That is required to run powercalc setup routine during startup.

screem20056 commented 2 years ago

Not sure if this can help Logger: homeassistant.components.sensor Source: util/dt.py:185 Integration: Sensor (documentation, issues) First occurred: 1:29:07 PM (2 occurrences) Last logged: 1:29:07 PM

Error adding entities for domain sensor with platform utility_meter Error while setting up utility_meter platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 428, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 691, in _async_add_entity await entity.add_to_platform_finish() File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 776, in add_to_platform_finish await self.async_added_to_hass() File "/usr/src/homeassistant/homeassistant/components/utility_meter/sensor.py", line 512, in async_added_to_hass dt_util.parse_datetime(state.attributes.get(ATTR_LAST_RESET)) File "/usr/src/homeassistant/homeassistant/util/dt.py", line 185, in parse_datetime return ciso8601.parse_datetime(dt_str) TypeError: argument 1 must be str, not None SmartSelect_20221011_133508_Home Assistant.jpgSmartSelect_20221011_133457_Home Assistant.jpg

bramstroker commented 2 years ago

Not seen this error before, but that's definitely not something which should happen. Not sure what causes that yet. Seem to be some corrupt state of your utility meter.

Which version of powercalc and HA do you use?

bramstroker commented 2 years ago

You shouldn't really edit that one, but I suggest you to take a look at config/.storage/core.restore_state and remove all the powercalc utility meter entries from it, as there seem to be some invalid state attributes there. After each restart HA will have a look here and restore entities to reflect the last state. Hopefully that will make the error disappear.

screem20056 commented 2 years ago

I did delete them but after restarting they appear again in the file 😅 i saved the file before restarting Im running 0.26.1 with HA 9.2

bramstroker commented 2 years ago

Could you try stopping HA, then delete and start again? HA will write the state from memory to restore_state when it is shutdown (also happens when you restart), so that would be the reason they appear again.

screem20056 commented 2 years ago

Sorry i did not understand how i can stop HA and edit the file !!! Will not be able to access the file

bramstroker commented 2 years ago

hmm yes, I understand your issue. I have ssh access to my HA instance so I can edit that way. Anyways I suggest to just wait 24 hours to see if the error disappears. I have good hopes when the utility meter has calculated a new state the error will just disappear. Still not sure if this is related to your other powercalc sensors not being setup correctly, but let's first wait a bit until investigating that further.

screem20056 commented 2 years ago

Thank you for putting time to this will share what i found after 48 hrs

screem20056 commented 2 years ago

hmm yes, I understand your issue. I have ssh access to my HA instance so I can edit that way. Anyways I suggest to just wait 24 hours to see if the error disappears. I have good hopes when the utility meter has calculated a new state the error will just disappear. Still not sure if this is related to your other powercalc sensors not being setup correctly, but let's first wait a bit until investigating that further.

Hi i found out that the issue is powercalc start before the integration of the source entity in this case tuya . So on the next step where HA needs to start and reload tuya integration powercalc lose the values and never return them till i manually reload the entity. Is their a way to fire powercalc after tuya integration Regards

bramstroker commented 2 years ago

Powercalc should not be dependant on loading order of other integrations. You could try adding tuya to dependencies in manifest.json in custom_components/powercalc directory. But this is not something I can (and will) add for all kind of integrations. Powercalc should populate the value for power sensor after HA is fully started or when the underlying source entity changes state. The second condition should happen when Tuya does it's thing later than powercalc. Hard to say what exactly goes wrong on your installation. Could you please enable debug logging for powercalc? That should hopefully give some more pointers what is exactly happening. Otherwise it is just a guessing game.

screem20056 commented 2 years ago

Powercalc should not be dependant on loading order of other integrations. You could try adding tuya to dependencies in manifest.json in custom_components/powercalc directory. But this is not something I can (and will) add for all kind of integrations. Powercalc should populate the value for power sensor after HA is fully started or when the underlying source entity changes state. The second condition should happen when Tuya does it's thing later than powercalc. Hard to say what exactly goes wrong on your installation. Could you please enable debug logging for powercalc? That should hopefully give some more pointers what is exactly happening. Otherwise it is just a guessing game.

Note: I already enabled it nothing relative in the log

bramstroker commented 2 years ago

There should be numerous log entries when setting the log level to debug. You should at least see a few "Creating power sensor ..." entries. For each powercalc sensor you should see more than 2 lines, sometimes even 10 lines.

What does your configuration.yaml look like now?

screem20056 commented 2 years ago

Powercalc should not be dependant on loading order of other integrations. You could try adding tuya to dependencies in manifest.json in custom_components/powercalc directory. But this is not something I can (and will) add for all kind of integrations. Powercalc should populate the value for power sensor after HA is fully started or when the underlying source entity changes state. The second condition should happen when Tuya does it's thing later than powercalc. Hard to say what exactly goes wrong on your installation. Could you please enable debug logging for powercalc? That should hopefully give some more pointers what is exactly happening. Otherwise it is just a guessing game.

Note: I already enabled it nothing relative in the log

Wow HA did not start i needed to setup it again and go to a backup 😅😅

For the yaml file it is like this SmartSelect_20221012_231048_Home Assistant.jpg

screem20056 commented 2 years ago

Powercalc should not be dependant on loading order of other integrations. You could try adding tuya to dependencies in manifest.json in custom_components/powercalc directory. But this is not something I can (and will) add for all kind of integrations. Powercalc should populate the value for power sensor after HA is fully started or when the underlying source entity changes state. The second condition should happen when Tuya does it's thing later than powercalc. Hard to say what exactly goes wrong on your installation. Could you please enable debug logging for powercalc? That should hopefully give some more pointers what is exactly happening. Otherwise it is just a guessing game.

Note: I already enabled it nothing relative in the log

Wow HA did not start i needed to setup it again and go to a backup 😅😅

For the yaml file it is like this SmartSelect_20221012_231048_Home Assistant.jpg

I found those registered for all sensors i copied samples (MainThread) [custom_components.powercalc] switch.wifi_switch: Model not found in library, skipping auto configuration 2022-10-12 23:09:52.146 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] switch.roof_round_light_switch_1: Auto discovered model (manufacturer=Tuya, model=k34prlxwjymp50cx) 2022-10-12 23:09:52.147 DEBUG (MainThread) [custom_components.powercalc] switch.roof_round_light_switch_1: Model not found in library, skipping auto configuration 2022-10-12 23:09:52.147 DEBUG (MainThread) [custom_components.powercalc] Done auto discovering entities

.....

(MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh bed light energy 2022-10-12 23:09:52.697 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] light.left_ground_cabinet: Auto discovered model (manufacturer=Tuya, model=tmy7lcbauqtcy2cc) 2022-10-12 23:09:52.698 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=light.left_ground_cabinet entity_category=None, sensor_name=Wh kitchen cabines power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=tuya.bfce0866448823bca1qyq1switch_led) 2022-10-12 23:09:52.698 DEBUG

Thanks

bramstroker commented 2 years ago

So for example Wh kitchen cabines power is missing and not working after startup? Because the logs say it is created correctly, I don't see any issues here.

screem20056 commented 2 years ago

and you are right even when i manually reload the entity it repeats the same steps and works fine the only difference that during the startup after restart those steps is not in order !! so this is the log after manual reload 2022-10-14 00:06:23.676 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=switch.aubess_smart_switch_em_switch_1 entity_category=None, sensor_name=Wh water pump power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=tuya.bf84a549f8de279e7dlvufswitch_1) 2022-10-14 00:06:23.676 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh water pump energy 2022-10-14 00:06:23.680 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.wh_water_pump_power to device 1b9bb4c6595cacbf12972b728a2bc0e0 2022-10-14 00:06:23.688 DEBUG (MainThread) [custom_components.powercalc.sensors.power] switch.aubess_smart_switch_em_switch_1: State changed to "off". Power:0.00 2022-10-14 00:06:23.705 DEBUG (MainThread) [custom_components.powercalc.sensors.abstract] Binding sensor.wh_water_pump_energy to device 1b9bb4c6595cacbf12972b728a2bc0e0

bramstroker commented 2 years ago

Please share the full logs after startup completed, all these different snippets won't help a bit an seems fine. Because I also don't see the errors you were initially talking about. You can copy paste that to a txt file and attach to the reply.

screem20056 commented 2 years ago

powercalc.txt powercalc full log

bramstroker commented 2 years ago

The relevant log entries indicating the creation of the power and energy sensors are here:

2022-10-15 11:52:01.878 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] switch.heater_socket_1: Auto discovered model (manufacturer=Tuya, model=j0zozzoarutv0nu1)
2022-10-15 11:52:01.878 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=switch.heater_socket_1 entity_category=None, sensor_name=Wh heater power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=tuya.bfaab7ed5688fc5520uo7jswitch_1)
2022-10-15 11:52:01.879 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh heater energy
2022-10-15 11:52:01.879 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] media_player.abood_tv: Auto discovered model (manufacturer=LG, model=55LH600V-TB)
2022-10-15 11:52:01.880 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=media_player.abood_tv entity_category=None, sensor_name=Wh abood tv power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=ba7c3cd6-9b15-a6eb-9748-78d22fc07970)
2022-10-15 11:52:01.881 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh abood tv energy
2022-10-15 11:52:01.881 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] switch.exhust_fan_switch_1: Auto discovered model (manufacturer=Tuya, model=ogupymaavjyzigvr)
2022-10-15 11:52:01.882 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=switch.exhust_fan_switch_1 entity_category=None, sensor_name=Wh exhust fan power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=tuya.bf8893cd4ab7ad91311xtsswitch_1)
2022-10-15 11:52:01.882 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh exhust fan energy
2022-10-15 11:52:01.882 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] light.bed: Auto discovered model (manufacturer=Tuya, model=tmy7lcbauqtcy2cc)
2022-10-15 11:52:01.883 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=light.bed entity_category=None, sensor_name=Wh bed light power strategy=LinearStrategy manufacturer= model= standby_power=0.00 unique_id=tuya.bf8262a095cda3846emmxnswitch_led)
2022-10-15 11:52:01.883 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh bed light energy
2022-10-15 11:52:01.883 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] light.left_ground_cabinet: Auto discovered model (manufacturer=Tuya, model=tmy7lcbauqtcy2cc)
2022-10-15 11:52:01.884 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=light.left_ground_cabinet entity_category=None, sensor_name=Wh kitchen cabines power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=tuya.bfce0866448823bca1qyq1switch_led)
2022-10-15 11:52:01.884 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh kitchen cabines energy
2022-10-15 11:52:01.884 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] switch.aubess_smart_switch_em_switch_1: Auto discovered model (manufacturer=Tuya, model=labfkgzm2ikdcpdp)
2022-10-15 11:52:01.885 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=switch.aubess_smart_switch_em_switch_1 entity_category=None, sensor_name=Wh water pump power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=tuya.bf84a549f8de279e7dlvufswitch_1)
2022-10-15 11:52:01.885 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh water pump energy
2022-10-15 11:52:01.886 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] switch.wall_lights_switch_1: Auto discovered model (manufacturer=Tuya, model=ogupymaavjyzigvr)
2022-10-15 11:52:01.886 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=switch.wall_lights_switch_1 entity_category=None, sensor_name=Wh wall lights power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=tuya.bf7e3c5b8d03bc8358fsmkswitch_1)
2022-10-15 11:52:01.886 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh wall lights energy
2022-10-15 11:52:01.887 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] switch.roof_round_light_switch_1: Auto discovered model (manufacturer=Tuya, model=k34prlxwjymp50cx)
2022-10-15 11:52:01.887 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=switch.roof_round_light_switch_1 entity_category=None, sensor_name=Wh roof round light power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=tuya.bfbcfa5c9692fa4ef9rictswitch_1)
2022-10-15 11:52:01.887 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh roof round light energy
2022-10-15 11:52:01.887 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] climate.bedroom_ac_gree: Auto discovered model (manufacturer=Gree, model=None)
2022-10-15 11:52:01.888 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=climate.bedroom_ac_gree entity_category=None, sensor_name=Wh bedroom ac power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=502cc68516c2)
2022-10-15 11:52:01.888 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh bedroom ac energy
2022-10-15 11:52:01.888 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] climate.office_ac: Auto discovered model (manufacturer=Gree, model=None)
2022-10-15 11:52:01.889 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=climate.office_ac entity_category=None, sensor_name=Wh office ac power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=502cc6853a6d)
2022-10-15 11:52:01.889 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh office ac energy
2022-10-15 11:52:01.889 DEBUG (MainThread) [custom_components.powercalc.power_profile.model_discovery] climate.living_room_ac: Auto discovered model (manufacturer=Gree, model=None)
2022-10-15 11:52:01.890 DEBUG (MainThread) [custom_components.powercalc.sensors.power] Creating power sensor (entity_id=climate.living_room_ac entity_category=None, sensor_name=Wh living room ac power strategy=FixedStrategy manufacturer= model= standby_power=0.00 unique_id=502cc684ba5b)
2022-10-15 11:52:01.890 DEBUG (MainThread) [custom_components.powercalc.sensors.energy] Creating energy sensor: Wh living room ac energy

I don't see anything wrong with that. All this is exactly as expected. After that you must have several power and energy sensors available in HA.

You can verify that in the entities list, developer tools or you can click on the entry in the GUI like this screenshot.

Screenshot 2022-10-15 at 11 07 36

After HA fully started I see the following in the logs, which is powercalc handling the initial state update for the power sensor. For climate.bedroom_ac_gree and switch.heater_socket_1 there is a problem with the state of these entities. That's why powercalc cannot calculate the power for that and it will make the power and energy sensor unavailable.

2022-10-15 11:52:07.788 DEBUG (MainThread) [custom_components.powercalc.sensors.power] light.bed: State changed to "off". Power:0.00
2022-10-15 11:52:07.789 DEBUG (MainThread) [custom_components.powercalc.sensors.power] light.left_ground_cabinet: State changed to "off". Power:0.00
2022-10-15 11:52:07.797 DEBUG (MainThread) [custom_components.powercalc.sensors.power] switch.roof_round_light_switch_1: State changed to "off". Power:0.00
2022-10-15 11:52:07.798 DEBUG (MainThread) [custom_components.powercalc.sensors.power] switch.aubess_smart_switch_em_switch_1: State changed to "off". Power:0.00
2022-10-15 11:52:07.798 DEBUG (MainThread) [custom_components.powercalc.sensors.power] switch.heater_socket_1: Source entity has an invalid state, setting power sensor to unavailable
2022-10-15 11:52:07.798 DEBUG (MainThread) [custom_components.powercalc.sensors.power] switch.wall_lights_switch_1: State changed to "off". Power:0.00
2022-10-15 11:52:07.798 DEBUG (MainThread) [custom_components.powercalc.sensors.power] switch.exhust_fan_switch_1: State changed to "off". Power:0.00

2022-10-15 11:52:09.035 DEBUG (MainThread) [custom_components.powercalc.sensors.power] media_player.abood_tv: State changed to "on". Power:81.00
2022-10-15 11:52:09.035 DEBUG (MainThread) [custom_components.powercalc.sensors.power] climate.bedroom_ac_gree: Source entity has an invalid state, setting power sensor to unavailable
2022-10-15 11:52:09.036 DEBUG (MainThread) [custom_components.powercalc.sensors.power] climate.office_ac: State changed to "off". Power:0.00
2022-10-15 11:52:09.037 DEBUG (MainThread) [custom_components.powercalc.sensors.power] climate.living_room_ac: State changed to "off". Power:0.00
2022-10-15 11:52:09.045 DEBUG (MainThread) [custom_components.powercalc.sensors.power] climate.bedroom_ac_gree: Source entity has an invalid state, setting power sensor to unavailable
2022-10-15 11:52:09.046 DEBUG (MainThread) [custom_components.powercalc.sensors.power] climate.bedroom_ac_gree: Source entity has an invalid state, setting power sensor to unavailable
screem20056 commented 2 years ago

That is really unusual 🤔 they are not available cause tuya is loading at that point !! In the screen shot how they looks after restarting then i need to reload each one separately. I can't reload the whole integration at once SmartSelect_20221015_124826_Home Assistant.jpg

bramstroker commented 2 years ago

Very very strange, there should be entities listed here. I am not able to reproduce yet, impossible to solve if I cannot debug the issue and have no clue what could be the cause. Also don't have TuYa, so cannot test with that. There is one other user reporting a similar issue on community forum and he has the androidTV integration. I will have a look if I can reproduce the issue with that one. Could you have a look into the logs after you reload this one "Wh kitchen cabines", then we can compare if all these lines are exactly the same as the logs after HA startup. And you were saying one powercalc sensor was working correctly after startup. Which one is that exactly?

dandek01 commented 2 years ago

I have similar issue maybe the same. I set up powercalc to calculate power usage on my lights controlled by smart switches and smart bulbs. Everything is working fine. I set up powercalc to monitor my tv energy consumption but when I restart my ha power / energy sensors created by powercalc just dissaper. When I reload powercalc for tv they just reaper. I use android tv integration and had set up powercalc using media_player.android_tv_192_168_31_5 entity. I don't have any error in logs related to powercalc, but I didn't enabled debug mode. I set up power consumption on wifi smart switches integrated with tuya integration and zigbe smart switches and smart bulbs integrated with zigbee2mqtt and mqtt integration. In my opinion this problem is somehow entities related but I don't know how exactly to trace this problem.

bramstroker commented 2 years ago

@dandek01 You only have a problem with a single powercalc sensor, right? The android TV one, all the others are working fine also after restart? Could you have a look into config/.storage/core.config_entries and search for the powercalc sensor here. than copy the JSON data for that one and share it here.

bramstroker commented 2 years ago

Also which versions of HA and powercalc are you guys on?

dandek01 commented 2 years ago

Yes, I have only problem with single powerccalc sensor, everything else is working fine after restart. This is androidtv related data { "entry_id": "49c3700f7523318e9e99b1b24654dbc6", "version": 1, "domain": "androidtv", "title": "192.168.31.5", "data": { "host": "192.168.31.5", "device_class": "androidtv", "port": 5555, "adb_server_port": 5037 }, "options": {}, "pref_disable_new_entities": false, "pref_disable_polling": false, "source": "user", "unique_id": "04:7a:0b:a1:a7:3d", "disabled_by": null }, { "entry_id": "95e78e9ed256afba0a94698f40006930", "version": 1, "domain": "nfandroidtv", "title": "Android TV", "data": { "host": "192.168.31.5", "name": "Android TV" }, "options": {}, "pref_disable_new_entities": false, "pref_disable_polling": false, "source": "user", "unique_id": "192.168.31.5", "disabled_by": null },

dandek01 commented 2 years ago

Maybe powercalc integration is loaded before android tv integration.

screem20056 commented 2 years ago

Hi I'm using 26.1 this is what i found on that file: the problem on my side is only with Tuya switches the rest like ACs TVs Sonoff lights is ok

      {
        "entry_id": "3c1042d4cbf0739edf4a54770eacc09c",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh heater",
        "data": {
          "entity_id": "switch.heater_socket_1",
          "mode": "fixed",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh heater",
          "fixed": {
            "power": 2100.0
          },
          "sensor_type": "virtual_power",
          "unique_id": "tuya.bfaab7ed5688fc5520uo7jswitch_1",
          "standby_power": 0.0
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "tuya.bfaab7ed5688fc5520uo7jswitch_1",
        "disabled_by": null
      },
      {
        "entry_id": "3b00681d23ba11a260d43f36ff40fec8",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh abood tv",
        "data": {
          "entity_id": "media_player.abood_tv",
          "mode": "fixed",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh abood tv",
          "fixed": {
            "power": 81.0
          },
          "sensor_type": "virtual_power",
          "unique_id": "ba7c3cd6-9b15-a6eb-9748-78d22fc07970"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "ba7c3cd6-9b15-a6eb-9748-78d22fc07970",
        "disabled_by": null
      },
      {
        "entry_id": "4b884f7fcefe5d766befb56e3a8ef84d",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh exhust fan",
        "data": {
          "entity_id": "switch.exhust_fan_switch_1",
          "mode": "fixed",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh exhust fan",
          "fixed": {
            "power": 40.0
          },
          "sensor_type": "virtual_power",
          "unique_id": "tuya.bf8893cd4ab7ad91311xtsswitch_1"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "tuya.bf8893cd4ab7ad91311xtsswitch_1",
        "disabled_by": null
      },
      {
        "entry_id": "f9c63385bd959cd518ace920a94c6661",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh bed light",
        "data": {
          "entity_id": "light.bed",
          "mode": "linear",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh bed light",
          "standby_power": 0.0,
          "linear": {
            "min_power": 3.0,
            "max_power": 25.0
          },
          "sensor_type": "virtual_power",
          "unique_id": "tuya.bf8262a095cda3846emmxnswitch_led"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "tuya.bf8262a095cda3846emmxnswitch_led",
        "disabled_by": null
      },
      {
        "entry_id": "c6286894f4825400f13bc83136b3a931",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh kitchen cabines",
        "data": {
          "entity_id": "light.left_ground_cabinet",
          "mode": "fixed",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh kitchen cabines",
          "standby_power": 0.0,
          "fixed": {
            "power": 30.0
          },
          "sensor_type": "virtual_power",
          "unique_id": "tuya.bfce0866448823bca1qyq1switch_led"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "tuya.bfce0866448823bca1qyq1switch_led",
        "disabled_by": null
      },
      {
        "entry_id": "6c0ee348679ab9d08069b1144dd0da12",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh water pump",
        "data": {
          "entity_id": "switch.aubess_smart_switch_em_switch_1",
          "mode": "fixed",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh water pump",
          "standby_power": 0.0,
          "fixed": {
            "power": 700.0
          },
          "sensor_type": "virtual_power",
          "unique_id": "tuya.bf84a549f8de279e7dlvufswitch_1"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "tuya.bf84a549f8de279e7dlvufswitch_1",
        "disabled_by": null
      },
      {
        "entry_id": "2e3466c8ee1c628d8c72fb519355ceb7",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh wall lights",
        "data": {
          "entity_id": "switch.wall_lights_switch_1",
          "mode": "fixed",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh wall lights",
          "standby_power": 0.0,
          "fixed": {
            "power": 27.0
          },
          "sensor_type": "virtual_power",
          "unique_id": "tuya.bf7e3c5b8d03bc8358fsmkswitch_1"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "tuya.bf7e3c5b8d03bc8358fsmkswitch_1",
        "disabled_by": null
      },
      {
        "entry_id": "577f3aab655f3fd9d7b766ee726caaf7",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh roof round light",
        "data": {
          "entity_id": "switch.roof_round_light_switch_1",
          "mode": "fixed",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh roof round light",
          "standby_power": 0.0,
          "fixed": {
            "power": 95.0
          },
          "sensor_type": "virtual_power",
          "unique_id": "tuya.bfbcfa5c9692fa4ef9rictswitch_1"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "tuya.bfbcfa5c9692fa4ef9rictswitch_1",
        "disabled_by": null
      },
      {
        "entry_id": "280497623fe2ed1daba6bf4775593f28",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh bedroom ac",
        "data": {
          "entity_id": "climate.bedroom_ac_gree",
          "mode": "fixed",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh bedroom ac",
          "fixed": {
            "power_template": "{% if states ('climate.bedroom_ac_gree') == 'cool' and state_attr ('climate.bedroom_ac_gree' , 'current_temperature') - state_attr ('climate.bedroom_ac_gree' , 'temperature') >0 %}\n1000\n{% elif states ('climate.bedroom_ac_gree') == 'cool' and state_attr ('climate.bedroom_ac_gree' , 'current_temperature') - state_attr ('climate.bedroom_ac_gree' , 'temperature') <=0 %}\n100\n{% elif states ('climate.bedroom_ac_gree') == 'heat' and state_attr ('climate.bedroom_ac_gree' , 'current_temperature') - state_attr ('climate.bedroom_ac_gree' , 'temperature') <0 %}\n1600\n{% elif states ('climate.bedroom_ac_gree') == 'heat' and state_attr ('climate.bedroom_ac_gree' , 'current_temperature') - state_attr ('climate.bedroom_ac_gree' , 'temperature') >0 %}\n500\n{% elif states ('climate.bedroom_ac_gree') == 'fan_only' %}\n90\n{% endif %}",
            "states_power": {}
          },
          "sensor_type": "virtual_power",
          "unique_id": "502cc68516c2"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "502cc68516c2",
        "disabled_by": null
      },
      {
        "entry_id": "6aebb74dfa9f940a04b68740d6a715a9",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh office ac ",
        "data": {
          "entity_id": "climate.office_ac",
          "mode": "fixed",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh office ac ",
          "fixed": {
            "power_template": "{% if states ('climate.office_ac') == 'cool' and state_attr ('climate.office_ac' , 'current_temperature') - state_attr ('climate.office_ac' , 'temperature') > 0 %}\n1000\n{% elif states ('climate.office_ac') == 'cool' and state_attr ('climate.office_ac' , 'current_temperature') - state_attr ('climate.office_ac' , 'temperature') <= 0 %}\n100\n{% elif states ('climate.office_ac') == 'heat' and state_attr ('climate.office_ac' , 'current_temperature') - state_attr ('climate.office_ac' , 'temperature') < 0 %}\n1500\n{% elif states ('climate.office_ac') == 'heat' and state_attr ('climate.office_ac' , 'current_temperature') - state_attr ('climate.office_ac' , 'temperature') > 0 %}\n400\n{% elif states ('climate.office_ac') == 'fan_only'%}\n90\n{% endif %}",
            "states_power": {}
          },
          "sensor_type": "virtual_power",
          "unique_id": "502cc6853a6d",
          "calculation_enabled_condition": "for:"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "502cc6853a6d",
        "disabled_by": null
      },
      {
        "entry_id": "1e2e295cf9278f667ccd3bccd2f6dea4",
        "version": 1,
        "domain": "powercalc",
        "title": "Wh living room ac",
        "data": {
          "entity_id": "climate.living_room_ac",
          "mode": "fixed",
          "create_energy_sensor": true,
          "create_utility_meters": false,
          "name": "Wh living room ac",
          "fixed": {
            "power_template": "{% if states ('climate.living_room_ac') == 'cool' and state_attr ('climate.living_room_ac' , 'current_temperature') - state_attr ('climate.living_room_ac' , 'temperature') > 0 %}\n1300\n{% elif states ('climate.living_room_ac') == 'cool' and state_attr ('climate.living_room_ac' , 'current_temperature') - state_attr ('climate.living_room_ac' , 'temperature') <= 0 %}\n90\n{% elif states ('climate.living_room_ac') == 'heat' and state_attr ('climate.living_room_ac' , 'current_temperature') - state_attr ('climate.living_room_ac' , 'temperature') < 0 %}\n2000\n{% elif states ('climate.living_room_ac') == 'heat' and state_attr ('climate.living_room_ac' , 'current_temperature') - state_attr ('climate.living_room_ac' , 'temperature') > 0 %}\n400\n{% elif states ('climate.living_room_ac') == 'fan_only' %}\n90\n{% endif %}",
            "states_power": {}
          },
          "sensor_type": "virtual_power",
          "unique_id": "502cc684ba5b"
        },
        "options": {},
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": "502cc684ba5b",
        "disabled_by": null
      },
      {
        "entry_id": "ded709d951c73307fe19acc362ae4236",
        "version": 1,
        "domain": "utility_meter",
        "title": "Wh kitchen consumption",
        "data": {},
        "options": {
          "name": "Wh kitchen consumption",
          "source": "sensor.water_pump_power",
          "cycle": "daily",
          "offset": 0.0,
          "tariffs": [],
          "net_consumption": false,
          "delta_values": false
        },
        "pref_disable_new_entities": false,
        "pref_disable_polling": false,
        "source": "user",
        "unique_id": null,
        "disabled_by": null
      }
    ]
  }
}
bramstroker commented 2 years ago

Yes, I have only problem with single powerccalc sensor, everything else is working fine after restart. This is androidtv related data { "entry_id": "49c3700f7523318e9e99b1b24654dbc6", "version": 1, "domain": "androidtv", "title": "192.168.31.5", "data": { "host": "192.168.31.5", "device_class": "androidtv", "port": 5555, "adb_server_port": 5037 }, "options": {}, "pref_disable_new_entities": false, "pref_disable_polling": false, "source": "user", "unique_id": "04:7a:0b:a1:a7:3d", "disabled_by": null }, { "entry_id": "95e78e9ed256afba0a94698f40006930", "version": 1, "domain": "nfandroidtv", "title": "Android TV", "data": { "host": "192.168.31.5", "name": "Android TV" }, "options": {}, "pref_disable_new_entities": false, "pref_disable_polling": false, "source": "user", "unique_id": "192.168.31.5", "disabled_by": null },

There should also be an entry with "domain": "powercalc", could you include that one as well, most interested in that.

screem20056 commented 2 years ago

Very very strange, there should be entities listed here. I am not able to reproduce yet, impossible to solve if I cannot debug the issue and have no clue what could be the cause. Also don't have TuYa, so cannot test with that. There is one other user reporting a similar issue on community forum and he has the androidTV integration. I will have a look if I can reproduce the issue with that one. Could you have a look into the logs after you reload this one "Wh kitchen cabines", then we can compare if all these lines are exactly the same as the logs after HA startup. And you were saying one powercalc sensor was working correctly after startup. Which one is that exactly?

sorry overlooked this one it is Abood Tv (not android) it is webos LG and the integration used is media player

dandek01 commented 2 years ago

There it is

"entry_id": "8c443e5aa70c76185dd57b83409c019d", "version": 1, "domain": "powercalc", "title": "Android TV", "data": { "entity_id": "media_player.android_tv_192_168_31_5", "mode": "fixed", "create_energy_sensor": true, "create_utility_meters": true, "name": "Android TV", "standby_power": 5.0, "fixed": { "power": 45.0 }, "sensor_type": "virtual_power", "unique_id": "04:7a:0b:a1:a7:3d" }, "options": {}, "pref_disable_new_entities": false, "pref_disable_polling": false, "source": "user", "unique_id": "04:7a:0b:a1:a7:3d", "disabled_by": null }

bramstroker commented 2 years ago

@screem20056 @dandek01 Thanks for providing this extra information. Hopefully I will be able to reproduce something. Not sure when I can have a further look, quite busy the coming days.

Only thing missing is which HA version you are using, and @dandek01 which powercalc version.

Would be nice if any of you would be able to test with latest v1.0.0 beta. Maybe it's already resolved in that one and we are wasting our precious time here.

dandek01 commented 2 years ago

I'm using Home Assistant 2022.10.4 Supervisor 2022.10.0 and powercalc version .. 0.26.1

dandek01 commented 2 years ago

I'm installing v1.0.0.0 beta 6 to try it.

screem20056 commented 2 years ago

Im using HA version. core-2022.10.4 I tested 1.0.0 beta 6 same issue. Thanks for support

dandek01 commented 2 years ago

No, problem stays the same. There is no entities after restart, energy dashboard says Entity not defined Check the integration or your configuration that provides: sensor.android_tv_energy Reloading powercalc resolve the issue. Powercalc version v1.0.0-beta.6

screem20056 commented 2 years ago

I have no clue if this can help but once HA start to boot i do not lose entity immediately have a look to the restart record from my phone 😄

https://linksharing.samsungcloud.com/kvp3y51p4JHr

bramstroker commented 2 years ago

I have upgraded my test HA instance to 2022.10.4, Upgraded powercalc to v1.0.0-beta.6. Setup AndroidTV integration for my TV. Next create a powercalc sensor using the GUI with fixed strategy for this android tv media player, similar configuration as @dandek01. After every restart the entities are just create correctly and don't disappear for me :-(

Screenshot 2022-10-15 at 13 23 20

Maybe it's a timing issue between integrations which is triggered for you but nog for me. As a lot of things are happening in parallel in HA execution. My hardware is Intel NUC, so that's quite overpowered for running HA.

@dandek01 Could you try adding androidtv to dependencies in config/custom_components/powercalc/manifest.json, and restart another time?

dandek01 commented 2 years ago

Unfortunately it doesnt work. This is part of manifest,json "dependencies": [ "light", "group", "template", "select", "utility_meter", "androidtv" ],

dandek01 commented 2 years ago

I'm running ha on debian linux. Comp has plenty of power, i3 3.4GHz cpu, 8 gb of ram, 2 ssd hdd.

bramstroker commented 2 years ago

@dandek01 hmm that's a pitty. @dandek01 could you also share your powercalc logs after restart? Hopefully your logs give some pointers.

dandek01 commented 2 years ago

The only thing I can think of is that my tv is connected to my router via powerline adapter. I use static ip to ping my tv from ha. in combination with android remote app installed on tv I can use my tv as casting device for my dorbell. The problem might be somewhere in integrations startup, I don't know. But I could try this integration on another tv, just to see will it work there.

dandek01 commented 2 years ago

Yeah, I created two powercalc meters. One for my Samsung TV and other for my alexa. Both are connected over wifi and there is no problems with powerclac integration after restart. Entities are there. My android tv that is connected to my router with lan cable and has wifi disabled has the same problem. Entities disappeared after ha restart and have to manually reload it to reappear.

dandek01 commented 2 years ago

I edit my configuration.yaml file with

logger: default: warning logs: custom_components.powercalc: debug

but there is no error in powercalc integration. This problem is probably somehow network related and it occurs when system is restating. When system is fully reloaded there is no problem.

bramstroker commented 2 years ago

@dandek01 I meant the lines starting with DEBUG (MainThread) [custom_components.powercalc. I was not expecting errors on your HA as these would be logged previously as well without any additional logging configuration. You can also enable android TV debug logging.

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

How does your powercalc card for the androidTV look like after startup? It also does not list any entities and it's blue, right? Similar as @screem20056

dandek01 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.