Energy Peaks Per Month Average EPPMA - electricity (eg Ellevio) consumption daily peaks per month calculations for eventual load shedding/balancing

thanks so much for this.
I have been testing this for a few weeks and it seems to help!

To reduce weight of this another thing one can do is limit the amount of data from the large span I have as default.

I included the statistics even for EPPMA 7 and 8 which I also included in the apex which also seems to work fine.

I have added it to the github now!

thanks for this help!!

ECPM (Energy Cost Per Month)

In other news I have been testing (but done mostly pre 15min window change in nordpool .. so, I missed to change the scope from hourly to 15min.. which I am now developing adding updates below as I go) for some time a next step of this where I am including costs which I am calling ECPM (Energy Cost Per Month) for load shedding. Basically I connect EPPMA to the prices that we have (nordpool). It monitors the +/- cost, hourly, daily, monthly. In general this seems quite good on random checks in a day or period of time, the monthly values are deviating a bit more than I like. Therefore, I would call this more directional and not sure how exact I can get it as it is more difficult to compare to actual bills we receive - while it is good enough for load shedding.

Below you will find the code for this if someone wants to test it as well it would be appreciated!

code updated 260416 - now including import/export cost per month
260417- /15min on ecpm 4 & 3 .. and 2 making it quarter-hourly later then included a 15min for eppma 3 now “ecpm_3_hourly_max_eppma” as well as fixing “unknown” when there is no import (eg solar, wind, etc..) it is assumed there is always some usage.

<- clck for : Installation & code for ECPM

installation

installation requires EPPMA and nordpool or likely other prices.
One puts the code below in a file for example called ecpm_energy_cost_per_month.yaml in the folder “packages” from EPPMA

and in your configuration.yaml include even this (with the file name above):

homeassistant:  
    packages:
      ecpm_energy_cost_per_month: !include packages/ecpm_energy_cost_per_month.yaml

then you need to find and replace your nordpool sensor into:

nord_pool_se3_tomorrow_and_today

which for me contains tomorrow (when available and today).. but it really only needs the current values.

more details are included in ECPM_4 to debug including import/export in kWh and value (currency in nordpool)

code

## ENERGY COST PER MONTH (ECPM)
## NOTES
  # utilizing import and export per hour utility meters
  # requires: 
     # EPPMA for import information
     # prices from nordpool or similar in the appropriate form
     # power information (eg from inverter)
      # sensor.export_power - for what is exported to the grid 
      # sensor.load_power - for load information wip

utility_meter:
## UTILITY METER ENERGY COST PER MONTH (ECPM)
  ecpm_2_utility_meter_export_power_hourly:
    name: "ECPM 2 utility meter export power hourly"
    source: sensor.ecpm_1_export_power_to_energy_saved_integral
    unique_id: 163605df-8951-435a-9f89-022279394ed0
    cycle: quarter-hourly

  ecpm_2_utility_meter_load_power_hourly:
    name: "ECPM 2 utility meter load power hourly"
    source: sensor.ecpm_1_load_power_to_energy_saved_integral
    unique_id: 2c3202e7-38f5-44da-83c4-683bb8e82d7c
    cycle: quarter-hourly

  ecpm_5_utility_meter_monthly_cost:
    name: "ECPM 5 utility meter monthly"
    source: sensor.ecpm_4_hourly_cost_incl_export_import
    unique_id: ebe5ee9d-d0d1-4d66-a76e-6e9c7e42ec44
    delta_values: true
    net_consumption: true
    cycle: monthly

  ecpm_5_utility_meter_monthly_kwh:
    name: "ECPM 5 utility meter monthly kWh"
    source: sensor.ecpm_4_hourly_cost_incl_export_import_kWh
    unique_id: 742c9887-7270-4df2-869c-94122d78e0c2
    delta_values: true
    net_consumption: true
    cycle: monthly

  ecpm_5_utility_meter_daily_cost:
    name: "ECPM 5 utility meter daily"
    source: sensor.ecpm_4_hourly_cost_incl_export_import
    unique_id: 45a2e306-1d1a-4819-a2f5-6475da30a26d
    delta_values: true
    net_consumption: true
    cycle: daily

  ecpm_5_utility_meter_monthly_export_cost:
    name: "ECPM 5 utility meter monthly export"
    source: sensor.ecpm_4_hourly_cost_export
    unique_id: 94797aa9-639d-47b4-a956-c230f8adec3e
    delta_values: true
    net_consumption: true
    cycle: monthly
  
  ecpm_5_utility_meter_monthly_import_cost:
    name: "ECPM 5 utility meter monthly import"
    source: sensor.ecpm_4_hourly_cost_import
    unique_id: 75ac6dfc-ec84-4726-a881-dff806e0b3ac
    delta_values: true
    net_consumption: true
    cycle: monthly

template:
## TEMPLATES ENERGY COST PER MONTH (ECPM)
  - trigger:
      - trigger: time_pattern
        minutes: /15
      - trigger: state
        entity_id:
          - input_button.ecpm_4_trigger
    sensor:
      - name: ECPM 4 hourly cost incl export import
        #     ecpm_4_hourly_cost_incl_export_import
        
        unique_id: 327da1dc-b917-450a-bbea-adad75f8e6eb
        unit_of_measurement: 'SEK'
        state: '{{ ( ( states.sensor.ecpm_3_hourly_max.state | float -  ( 0 if states.sensor.ecpm_3_hourly_max_eppma.state == "unknown" else states.sensor.ecpm_3_hourly_max_eppma.state)  | float ) * states.sensor.nord_pool_se3_tomorrow_and_today.attributes.data[(now().strftime("%H") | int) * 4 + ( ( ( now().strftime("%M") | float  / 60 ) * 4  ) | int ) ].price | float ) | float }}'
        attributes:
          export_value: '{{ ( states.sensor.ecpm_3_hourly_max.state | float ) * states.sensor.nord_pool_se3_tomorrow_and_today.attributes.data[(now().strftime("%H") | int) * 4 + ( ( ( now().strftime("%M") | float  / 60 ) * 4  ) | int ) ].price | float }}'
          export_kWh: '{{ states.sensor.ecpm_3_hourly_max.state | float }}'
          import_value: '{{ -1*(  ( 0 if states.sensor.ecpm_3_hourly_max_eppma.state == "unknown" else states.sensor.ecpm_3_hourly_max_eppma.state)  | float ) * states.sensor.nord_pool_se3_tomorrow_and_today.attributes.data[(now().strftime("%H") | int) * 4 + ( ( ( now().strftime("%M") | float  / 60 ) * 4  ) | int ) ].price | float }}'
          import_kWh: '{{ -1* ( 0 if states.sensor.ecpm_3_hourly_max_eppma.state == "unknown" else states.sensor.ecpm_3_hourly_max_eppma.state)  | float }}'
          nord_pool_price: '{{ states.sensor.nord_pool_se3_tomorrow_and_today.attributes.data[(now().strftime("%H") | int) * 4 + ( ( ( now().strftime("%M") | float  / 60 ) * 4  ) | int ) ].price | float }}'
          load_kWh: '{{ states.sensor.ecpm_3_load_power_hourly_max.state | float }}'
          load_value: '{{ states.sensor.ecpm_3_load_power_hourly_max.state | float * states.sensor.nord_pool_se3_tomorrow_and_today.attributes.data[(now().strftime("%H") | int) * 4 + ( ( ( now().strftime("%M") | float  / 60 ) * 4  ) | int ) ].price | float }}'

      - name: ECPM 4 hourly cost incl export import kWh
        #     ecpm_4_hourly_cost_incl_export_import_kwh
        unique_id: 4c28ae25-0eb7-4ba4-9cc7-0b112bdae00c
        unit_of_measurement: 'kWh'
        state: '{{ ( ( states.sensor.ecpm_3_hourly_max.state | float -  ( 0 if states.sensor.ecpm_3_hourly_max_eppma.state == "unknown" else states.sensor.ecpm_3_hourly_max_eppma.state)  | float ) ) | float }}'
      
      - name: ECPM 4 hourly cost export
        #     ecpm_4_hourly_cost_export
        unique_id: 80a16189-7dec-4b5a-ac8a-6bef940efeb9
        unit_of_measurement: 'SEK'
        state: '{{ ( states.sensor.ecpm_3_hourly_max.state | float ) * states.sensor.nord_pool_se3_tomorrow_and_today.attributes.data[(now().strftime("%H") | int) * 4 + ( ( ( now().strftime("%M") | float  / 60 ) * 4  ) | int ) ].price | float }}'

      - name: ECPM 4 hourly cost import
        #     ecpm_4_hourly_cost_import
        unique_id: 75b76a11-f39c-4738-b559-9a3efb4457a8
        unit_of_measurement: 'SEK'
        state: '{{ -1*(  ( 0 if states.sensor.ecpm_3_hourly_max_eppma.state == "unknown" else states.sensor.ecpm_3_hourly_max_eppma.state)  | float ) * states.sensor.nord_pool_se3_tomorrow_and_today.attributes.data[(now().strftime("%H") | int) * 4 + ( ( ( now().strftime("%M") | float  / 60 ) * 4  ) | int ) ].price | float }}'



sensor: 
## SENSORS ENERGY COST PER MONTH (ECPM)
  - platform: integration
    # name: ecpm_1_export_power_to_energy_saved_integral
    name:  "ECPM 1 Export power to energy saved integral"
    unique_id: 1665e804-3b40-4f73-b360-7de259029d57
    source: sensor.export_power
    unit_prefix: k
    round: 4
    max_sub_interval:
      minutes: 5

  - platform: integration
    # name: ecpm_1_load_power_to_energy_saved_integral
    name:  "ECPM 1 Load power to energy saved integral"
    unique_id: ff31e78e-0017-4b9c-80b0-00c5905a7329
    source: sensor.load_power
    unit_prefix: k
    round: 4
    max_sub_interval:
      minutes: 5

  - platform: statistics
    name:  "ECPM 3 hourly max"
    # name: ecpm_3_hourly_max
    ## max at end of period is max for previous hour
    unique_id: 8060023f-4e36-4386-8816-85d9347134cd
    entity_id: sensor.ecpm_2_utility_meter_export_power_hourly
    state_characteristic: value_max
    max_age:
      minutes: 15
    precision: 4

  - platform: statistics
    name:  "ECPM 3 hourly max eppma"
    # name: ecpm_3_hourly_max_eppma
    ## max at end of period is max for previous hour
    unique_id: 464832cb-3363-48e4-a1ac-8a4777e9bc13
    entity_id: sensor.eppma_2_energy_per_hour
    state_characteristic: value_max
    max_age:
      minutes: 15
    precision: 4

  - platform: statistics
    name:  "ECPM 3 load power hourly max"
    # name: ecpm_3_load_power_hourly_max
    ## max at end of period is max for previous hour
    unique_id: 334e5577-5520-4925-8412-e38090aa32cf
    entity_id: sensor.ecpm_2_utility_meter_load_power_hourly
    state_characteristic: value_max
    max_age:
      minutes: 15
    precision: 4

input_button:
  epcm_4_trigger:
    name: ECPM 4 trigger

if you do test, let me know if you run into any issues!