virtualdj / pun_sensor

Prezzi PUN del mese - Home Assistant Integration
MIT License
78 stars 13 forks source link

Provide retail pricing dummy sensor by applying a formula over PUN prices #11

Closed Ocramius closed 8 months ago

Ocramius commented 12 months ago

Ref: https://github.com/virtualdj/pun_sensor/issues/6 Ref: https://github.com/virtualdj/pun_sensor/issues/10

As explained by @ virtualdj, retail prices depend on the current contract with the electricity retailer, and therefore need to be computed with a template sensor.

This patch provides an example, although it is unclear where this would be positioned in configuration.yml

Ocramius commented 12 months ago

Meanwhile, my local formula, if I understood this correctly:


template:
  - sensor:
      # see https://github.com/virtualdj/pun_sensor/pull/11
      - unique_id: current_retail_electricity_price
        name: 'Current retail electricity price'
        icon: mdi:currency-eur
        unit_of_measurement: '€/kWh'
        # 1.102 = 10.2% spread
        # 1.038 = 3.8% MT (not sure what this is)
        # 0.073 = delivery fees
        # 0.042 = distribution/measurement fees
        state: >
          {{ (1.102 * 1.038 * (states('sensor.pun_prezzo_fascia_corrente')|float(0) + 0.073 + 0.042))|round(3) }}

Probably mixed up the formula a bit, so please do feel free to correct me, so I both get it right for myself and for others here :D

EDIT: in fact, I think it's like this

template:
  - sensor:
      # see https://github.com/virtualdj/pun_sensor/pull/11
      - unique_id: current_retail_electricity_price
        name: 'Current retail electricity price'
        icon: mdi:currency-eur
        unit_of_measurement: '€/kWh'
        # 1.102 = 10.2% spread
        # 1.038 = 3.8% MT (not sure what this is)
        # 0.073 = delivery fees
        # 0.042 = distribution/measurement fees
        state: >
-          {{ (1.102 * 1.038 * (states('sensor.pun_prezzo_fascia_corrente')|float(0) + 0.073 + 0.042))|round(3) }}
+          {{ (states('sensor.pun_prezzo_fascia_corrente')|float(0) * 1.102 * 1.038 + 0.073 + 0.042)|round(3) }}
virtualdj commented 12 months ago

To be honest, I don't remember at the moment where I found that formula... and I'm not sure it's actually perfect. For example grid losses and dispatchment costs are based on the kWh (so they must be multiplied) but there are also monthly costs that are not included here.

Anyway, everything it's just an indication because you won't get the correct result until near the end of the month.