drc38 / DiUS_Powersensor

Home Assistant Custom Integration for DiUS Powersensors
MIT License
9 stars 0 forks source link

2 sensors problem #303

Open edkazic opened 10 months ago

edkazic commented 10 months ago

Version of the custom_component

just updated new version 0.2.8 but still having problems

Configuration

Add your logs here.

Describe the bug

I have 2 plugs and 2 sensors I have removed old installation and reinstalled fresh copy of 0.2.8.

The installation only detected one plug and one sensor. Interesting part is that one sensor that was detected actually picking information for both sensors. I can tell as every 15-30 seconds the sensor attributes change and I can see 2 different MAC addresses alternating with corresponding values for the power. I made a configuration where I can read this one sensor but I filter info into 2 entities belonging to 2 sensors so I have actual power values for the solar as well as power for the grid. I can use this as is but it would be much cleaner if I can read 2 sensors independently. And I can not avoid errors in the log but still everything works?

Also interesting thing I have noticed when I made "reload" (three dots on the top right corner) on the DiUS_Powersensor integration page. Then i have noticed second sensor showed up but with no entities and with the same name as the first one. So I had to rename one sensor so that I have unique names and after that new reload is not creating more sensors and my workaround to read solar and grid power works. It is just error log that is annoying.

Debug log

2023-12-02 17:38:25.579 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform dius Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities await asyncio.gather(tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 563, in _async_add_entity entity.add_to_platform_start( File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 218, in add_to_platform_start if self.unique_id is None or self.device_class is None: ^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 356, in unique_id return self._attr_unique_id ^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dius/entity.py", line 22, in _attr_unique_id return data.get(Msg_keys.mac.value) ^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'get' 2023-12-02 17:38:25.582 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up dius platform for sensor Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 367, in _async_setup_platform await asyncio.gather(pending) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 507, in async_add_entities await asyncio.gather(*tasks) File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 563, in _async_add_entity entity.add_to_platform_start( File "/usr/src/homeassistant/homeassistant/components/sensor/init.py", line 218, in add_to_platform_start if self.unique_id is None or self.device_class is None: ^^^^^^^^^^^^^^ File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 356, in unique_id return self._attr_unique_id ^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/dius/entity.py", line 22, in _attr_unique_id return data.get(Msg_keys.mac.value) ^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'get'

drc38 commented 10 months ago

Thanks for clarifying you have multiple sensors. I only have 1 of each so have no plan to support multiple sensors/plugs, but welcome a PR that would support this.

ninjapdx commented 9 months ago

I made a configuration where I can read this one sensor but I filter info into 2 entities belonging to 2 sensors so I have actual power values for the solar as well as power for the grid.

Wondering if you can share how you did this? I've been trying everything I can and can't get it to work properly.

edkazic commented 9 months ago

Hi,

Here is the way I managed to have both DiUS sensors working:

First when you install DiUS_Powersensor through the integration you can see a plug and 2 sensors show-up. At first it may be just one sensor but if you “reload” integration the second sensor will show up.

If you examine sensors attributes you can see that only one sensor is working and other one is undefined. Also the one that is working and showing attributes actually alternate between two sensors. You can tell as MAC address change as well as corresponding power reading. You can indentify MAC address for each sensor in the Powersensor mobile application so you know which one is for grid power and which one is for solar power.

First rename sensors to sensor1 and sensor2 as this will come handy later.

I have setup configuration in configuration.yaml as follows

template:

This may look convoluted and lots of unnecessary conditions but this is the one that is working with no errors in the log.

Here are few problems that this configuration solving.

First it is necessary to read attributes from the working sensor and create entities grid and solar based on different MAC addresses. Since only one sensor displaying both power values there is an “if” statement checking attribute MAC to match the sensor.

The problem is that occasionally (not sure when and why) the two sensors variables swap the roles. So the one that was working become undefined and the other one start working. This is why you have first if statement filtering on sensor availability (sensor1 and sensor2) and using available sensor to read attributes.

Power1 and Power2 are temporary variable that are used just to go through the checkups and are holding final state result. In the first instance I have tried to set initial Power1 and Power2 to: unavailable, null, undefined... hoping that once sensor is unavailable it will not record the state and I would have continuous graphs for grid and for the solar. So you could use ‘unaivalable’ instead of the ‘0’ as initial value and it would work but it would be creating errors in the log. So I found that setting 0 preventing the log errors but then I had problems with graphs.

Now graphs for the solar and grid looks like a comb.

You can see on the picture both solar and grid graphs. Here is the problem where only one have a value at one time while the other one is set to 0.

This can be useful “as is” especially if you make an average (purple line) then you can use in the automations.

Average you can make as:

sensor:

But I didn’t like it and I made separate automation where I modified the “comb” graphs to only update if the value is not zero. The configuration is like this.

And this produced graphs that are working very well and doesn’t generate any error logs. Adding an average you can have perfect base for automation.

Hope it is helpful?

Regards

Ed

From: ninjapdx @.*** Sent: Thursday, 7 December 2023 2:40 PM To: drc38/DiUS_Powersensor Cc: edkazic; Author Subject: Re: [drc38/DiUS_Powersensor] 2 sensors problem (Issue #303)

I made a configuration where I can read this one sensor but I filter info into 2 entities belonging to 2 sensors so I have actual power values for the solar as well as power for the grid.

Wondering if you can share how you did this? I've been trying everything I can and can't get it to work properly.

— Reply to this email directly, view it on GitHub https://github.com/drc38/DiUS_Powersensor/issues/303#issuecomment-1844205048 , or unsubscribe https://github.com/notifications/unsubscribe-auth/ABRGV67MLF3Z44OSH656ZCDYIE3BFAVCNFSM6AAAAABADZ457CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNBUGIYDKMBUHA . You are receiving this because you authored the thread. https://github.com/notifications/beacon/ABRGV66LCRMT6CZL3JAWHV3YIE3BFA5CNFSM6AAAAABADZ457CWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTN5RK7Q.gif Message ID: @.***>

ninjapdx commented 9 months ago

Thanks so much!! I'm testing out some other methods for getting the data in a format that works well for me (wanting to get the data in kWh etc), unfortunately it's been a horrible day for solar generation so testing has been a pain.