core: Energy doesn't support negative power prices

The problem

I’m getting this error even though it should be completely valid to have a negative price.

The following entities have a negative state while a positive state is expected:
sensor.home_general_energy_price (-0.06)

I do get paid to use power during this time.

What is version of Home Assistant Core has the issue?

core-2021.9.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

https://github.com/madpilot/hass-amber-electric/issues/24

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 25 (9 by maintainers)

Most upvoted comments

There hasn’t been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

Never mind about that, the problem is likely in the template, | float will actually return 0 if the input is not a valid number. It means if any of the sensors is unavailable, that sensor’s value will be replaced by 0.

In this case it makes more sense to fail, if you update the template to use the float() function instead of the | float filter it should do just that:

{{float(states('sensor.no_such_sensor'))}} -> `unknown` this uses Home Assistant's `forgiving_float` and returns unknown
{{(states('sensor.no_such_sensor')) | float }} - > this uses jinja's float and returns 0

That is, change to:

{%- set ellas_desk = float(sensor.ellas_desk_total_consumption.state) %}

Related PR: https://github.com/home-assistant/core/pull/56051

2021.9.5 has been released with this fix included.

The energy dashboard allows you to add both a sensor which provides the energy consumption and a a sensor which provides the energy price.

The cost sensor does not handle negative prices

The energy consumption sensor together with the price sensor will calculate the cost of the electricity consumption, and that sensor doesn’t currently handle negative energy price, that’s why you get this error message:

The following entities have a negative state while a positive state is expected:
sensor.home_general_energy_price (-0.06)

It would be very helpful if you could share a screenshot of the cost graph too.

Your energy usage looks strange, with a huge bump of ~100kWh around noon

This is a problem with the energy usage calculation, which is derived from sensor.house_total_consumption. Note that this is energy consumption in kWh, not cost in AUD. The reason why the energy usage graph has a huge bump is because that sensor sensor.house_total_consumption was briefly at 0, which is interpreted as the start of a new billing cycle.

In order to have some progress with this problem, can you please share details on which integration is providing sensor.house_total_consumption?

Hey there @home-assistant/core, mind taking a look at this issue as it has been labeled with an integration (energy) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)