JonahKr / power-distribution-card

A Lovelace Card for visualizing power distributions.
MIT License
219 stars 13 forks source link

Autarky calculation #146

Closed slipx06 closed 1 year ago

slipx06 commented 1 year ago

Hi I cant figure out how the card is calculating the autarky value shown below? I'm using presets for all of these so I assume the default consumer/producer tags would apply. Grid is excluded since it has no tag in the preset? Battery is a producer but value is negative so why is this not excluded as well?

   this._config.entities.forEach((item, index) => {
      const value = this._val(item);

      if (!item.calc_excluded) {
        if (item.producer && value > 0) {
          production += value;
        }
        if (item.consumer && value < 0) {
          consumption -= value;
        }
      }

Autarky = production *100 /consumption = 8800/530 = 17%.

image

image

Ratio = consumption *100/production = 34400/3687 = 9%

JonahKr commented 1 year ago

Hey there 👋 ,

I think the issue is due to a configuration error. So when the battery is charging the arrows should point towards the battery. If the battery is releasing energy for consumption, it should point towards the middle.

The Grid is excluded since it doesn't actually have an impact on the result of the values.

I will just go through the first image to explain. Autarky: is the rate at which the consumed energy is produced by yourself. Therefore for image one:

slipx06 commented 1 year ago

Hi Thanks for the feedback and explanation. My battery provides a negative number when charging and a positive number when releasing energy. I have absolute values being displayed so the arrows are behaving as expected. Maybe I don't understand the battery preset. According to the code how does it contribute to consumption as wont the logic conditions fail since it is tagged as a producer. so when charging and the number is - wont it be ignored in the calculations?

i.e. if (item.consumer && value < 0) consumption -= value;

JonahKr commented 1 year ago

So your battery should work just fine. I know what you mean now. If you look here: https://github.com/JonahKr/power-distribution-card/blob/1fc6a2fe8f3b5effe4b7336c78bddb37eb771758/src/presets.ts#L21-L26 You'll see that a battery is actually both a consumer and producer, since it can provide aswell as consume power. In the calculations you can think of it as a e.g. car charger and additional solar panel in one entity, differentiated by the positive or negative value.

The formula you referenced works completely fine in that context. If we have a consumer, consuming power (negative value), we add it to the total consumption. (total - - value == total + value)

I hope that clears things up a bit for you. 😄

slipx06 commented 1 year ago

Than you for explaining it. I missed the consumer and producer bit. Great work on the card 👍

JonahKr commented 1 year ago

@slipx06 I just saw your development on your custom card, keep up the good work! If you need any help regarding this topic, feel free to message me.

slipx06 commented 1 year ago

Thank you so much.