martinarva / dynamic_energy_cost

35 stars 9 forks source link

Use solar production to reduce usage cost #16

Closed jkkataja closed 1 month ago

jkkataja commented 2 months ago

I think it would be beneficial to be able to add solar production sensor that would be used to reduce the cost of usage when there is solar production available. Furthermore, I think it would need to be able to rank different items to which to allocate the solar production.

example: Energy meter for appliance 1, associated rank 1 for solar production Energy meter for appliance 2, rank 3 Energy meter for appliance 3, rank 2 solar production sensor

-> first the appliance 1 calculation reduces the solar production from used energy, cost might end up being 0 -> if there is still solar production left, use it to reduce appliance 3 (note rank 2) consumption -> if still left, use it for rank 3 item and so on

let me know if I managed to explain it reasonably

darkrain-nl commented 2 months ago

I like this idea, have been thinking about it as well...

martinarva commented 1 month ago

I think that this will make the integration too complex and my aim is to keep it simple and universal.

But you can achieve this by making template sensors for the appliances and then feed in the template sensors to my custom integration.

Example code:

template:
  - sensor:
      - name: "Appliance 1 Net Energy"
        unit_of_measurement: 'kWh'
        state: >
          {% set solar = states('sensor.solar_production') | float %}
          {% set consumption = states('sensor.appliance_1_energy') | float %}
          {% set net_consumption = consumption - solar %}
          {{ [net_consumption, 0] | max }}
        attributes:
          original_consumption: "{{ states('sensor.appliance_1_energy') | float }}"
          solar_used: >
            {% set solar_used = states('sensor.solar_production') | float %}
            {% set consumption = states('sensor.appliance_1_energy') | float %}
            {% set solar_allocation = solar_used if solar_used < consumption else consumption %}
            {{ solar_allocation }}

      - name: "Appliance 3 Net Energy"
        unit_of_measurement: 'kWh'
        state: >
          {% set solar_left_1 = states('sensor.solar_production') | float - states('sensor.appliance_1_net_energy').attributes.solar_used %}
          {% set consumption = states('sensor.appliance_3_energy') | float %}
          {% set net_consumption = consumption - solar_left_1 %}
          {{ [net_consumption, 0] | max }}
        attributes:
          original_consumption: "{{ states('sensor.appliance_3_energy') | float }}"
          solar_used: >
            {% set solar_left_1 = states('sensor.solar_production') | float - states('sensor.appliance_1_net_energy').attributes.solar_used %}
            {% set consumption = states('sensor.appliance_3_energy') | float %}
            {% set solar_allocation = solar_left_1 if solar_left_1 < consumption else consumption %}
            {{ solar_allocation }}

      - name: "Appliance 2 Net Energy"
        unit_of_measurement: 'kWh'
        state: >
          {% set solar_left_2 = states('sensor.solar_production') | float - states('sensor.appliance_1_net_energy').attributes.solar_used - states('sensor.appliance_3_net_energy').attributes.solar_used %}
          {% set consumption = states('sensor.appliance_2_energy') | float %}
          {% set net_consumption = consumption - solar_left_2 %}
          {{ [net_consumption, 0] | max }}
        attributes:
          original_consumption: "{{ states('sensor.appliance_2_energy') | float }}"
          solar_used: >
            {% set solar_left_2 = states('sensor.solar_production') | float - states('sensor.appliance_1_net_energy').attributes.solar_used - states('sensor.appliance_3_net_energy').attributes.solar_used %}
            {% set consumption = states('sensor.appliance_2_energy') | float %}
            {% set solar_allocation = solar_left_2 if solar_left_2 < consumption else consumption %}
            {{ solar_allocation }}

Explanation:

This method ensures that each appliance's net energy usage is dynamically adjusted based on available solar energy, prioritized by your predefined ranking.

martinarva commented 1 month ago

For solar overall benefit check you can check this method i'm using: https://community.home-assistant.io/t/solar-benefit-calculations

jkkataja commented 1 month ago

I think it's a valid design decision to keep the solar energy out of this one and do it via templating. I would suggest that when you have time, you would add your nice template example as an section to the README part, that way people have instant information how they can achieve this.

darkrain-nl commented 1 month ago

Yep, sounds good, will give it a try later today with a template sensor. BTW template sensors can now be done via the UI, so there is no need to work with YAML for people that don't like or know YAML :-)

martinarva commented 1 month ago

Yep, sounds good, will give it a try later today with a template sensor. BTW template sensors can now be done via the UI, so there is no need to work with YAML for people that don't like or know YAML :-)

Didn't know that. To be honest i feel more comfortable still using yaml

darkrain-nl commented 1 month ago

Which is fine of course, but the UI way is nice as well, it gives you the current state immediately when setting up the sensor and you have some options to define what sensor it is... So it is a great option to have.

martinarva commented 1 month ago

I will close this issue, as it's not in a scope of this integration