-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Add Polarity Invert option to Power sensors in Energy dashboard #28397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Conversation
This is a boolean flag which will be used to indicate whether a bi-directional power sensor should be negated if a negative value indicates the wrong direction to expected.
When there is a negate preference present and it is set to true, the value for power retrieved from the entity will be negated (value = 0 - value).
The new form field configures whether a power meter has inverted polarity.
|
Can you also do this for Solar? My kWh meter also gives negative values |
Suggest to wait for approval of the current before adding anything more. Can always go back and add more when/if the concept is generally approved. |
|
Maybe add the checkbox for both battery power sensors. There are integrations which reverse the logic HA uses, so they are negative when HA expects positive, and the other way around. Anyway, very nice that you're adding this. Thanks! Edit: based on the comment above, maybe wait until this one is merged and add that as a follow up :) |
|
@pergolafabio This PR is only dealing with the power sensors which use a specific function to access the data. Energy sensors would be possibly more complex, and so ought to be a different FR. @TheFes There's only one power sensor for the battery as far as I can tell. The other two are energy sensors. |
No. Im talking about power sensors, I use a KWh meter for my solar, the kwh meter reports also negative... I had to create a template entity to add solar as power source to make it positive |
|
@pergolafabio kWh is energy, power sensors will be using (k)W. |
|
Sorry, I'm talking about Watt ... |
|
@pergolafabio Ah ok, I was confused as kWh is energy unit. It should be easy enough to add the checkbox for the solar power sensor as well. |
Would be great, thnx |
To make it clearer what entity it is related to.
Sensor doesn't have to be bi-directional to invert it.
The negate preference had not being used when getting the battery data.
|
Thank you for this. SolarEdge inverters with an Export+Import meter provide a negative power value when importing from grid and a positive power value when exporting to grid (positive means excess solar generation). I'd already created a new inverted meter power sensor entity in solaredge-modbus-multi to provide the polarity HA wanted from the integration so that users aren't forced to create template sensors, but I'll hold off on that for a bit. |
Some exotic setups may have a negative power value for solar. Given grid and battery have negate options it doesn't seem out of place for solar to have that also.
ff47d74 to
7bc8f44
Compare
MindFreeze
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this would be very useful but I don't think this is the way to do it. It adds a lot of complexity and fragility to the data handling. I already see that you don't properly handle the polarity of statistics data in the power sources graph, just the latest value, and these kinds of bugs will just keep multiplying every time we add something new about power data.
A more robust approach would be to create new sensors in the energy integration in core. That basically act as the template sensor you would normally create yourself but handled internally.
|
The same approach could be used for energy sensors btw. If the user only has a power sensor, the integration can auto create an energy sensor out of it. |
|
@MindFreeze the disadvantage of that, is that you won't have LTS for the new sensor. For my power consumption sensor (from grid) I have years of history. For the newly created template sensor I now use for power production (to grid) I only have history since this month. |
|
True, but we mostly care about the current value and most recent history. Showing the full power history in the summary is not intended. It just happened because of last minute changes. Power history has performance issues and little utility for users |
Hi pergolafabio would it be possible to share your template ? I use the same kWh meter rom Homewizard as well see topic 👍😉 |
Like this: |
Nice 👍 Thank you and thank you for your very quick reply. I will start this right now, Again huge appreciated 😉 |
|
You can also create it in the GUI as template helper using this template The template sensor will be |
Thank you TheFes, that worked also great much appreciated 👍😉 |
ffe6775 to
d2031f8
Compare
|
@MindFreeze I appreciate you checking this. I've added a fix for the statistics issue, you're right I missed that. While its possible to add extra template sensors to negate the values, be that manually or internally, IMHO this kind of defeats the point. Firstly, I agree with @TheFes that this loses historical information which is somewhat irritating, but it also doubles the amount of statistics data stored because you have the original sensor and the new negated sensor. I guess the issue really stems from their being no hard and fast rule for how direction is encoded in power data from the myriad of different bits of hardware. IMHO This should realistically be handled internally one way or another, but I'm sure others would disagree. |
|
I will discuss this with the team but my opinion is that this should be handled with a new sensor. Either core creates and manages it, or we provide an easy UI for the user to create and manage it. |
|
I totally get where your coming from. Having said that to a certain extent negating if necessary is realistically for all intents and purposes the same operation as scaling of units (kW -> W) which is already directly handled at the data import stage here. I wonder if the approach that is needed for adding a new attribute or state information for power sensors that specifies direction. That way the actual sensors themselves are tagged to say what they represent and the negation if needed can be handled more consistently. That would relieve the need for extra sensors and additional preferences, while also giving a potentially more manageable way to handle these sensors going forward (including for the potential use in integrating power to energy). Although how you define that attribute is possibly a whole other can of worms. e. g. is it something like relative to the home - true or false. But then there's still no consistent default as we've seen. |

In #27373 the option to track power as well as energy was added. In the case of the Grid and Battery power sources, these are added as a single bi-directional sensor which requires a specific polarity to be meaningful. However not all integrations or hardware use the expected polarity meaning additional template sensors would need to be created to negate these values before they could be used with the energy dashboard.
Proposed change
In this PR, and the associated core PR, we add the option to invert the polarity of a power sensor used for grid/battery/solar power data. This is saved in the preferences as stat_rate_negate alongside with the stat_rate entity id.
In the dialog entries, a check-box is added to select whether to invert the polarity.
The scope was limited to these two sources as they are likely to be bidirectional. Solar and individual loads are unlikely to need inverting, though that could be added at a later date.
Type of change
Additional information
Solar power not shown in energy dashboard 2025.12.1 #28409
[FR]: 'Reverse battery combined power' wills106/homeassistant-solax-modbus#1751
Add inverted power sensor WillCodeForCats/solaredge-modbus-multi#927
There was a similar proposal to add a direction toggle in the comments of the original PR: home-assistant/core#153809 (comment)
Checklist
If user exposed functionality or configuration variables are added/changed: