Dielee / volvo2mqtt

Home Assistant addon for connecting AAOS Volvos
MIT License
127 stars 25 forks source link

Implement sensor Estimated efficiency #83

Closed aerrow5 closed 10 months ago

aerrow5 commented 11 months ago

Calculate the estimated efficiency for BEV models.

Estimated efficiency: the electric range is based on battery capacity and recent energy consumption. This value calculates the estimated efficiency the car is using to calculate the range. Added also to long term statistics. To calculate this value the capacity of the battery is needed (eg. 67). Added it to the configuration.

(not sure if you now can merge both PRs as it touches same code, sorry I'm no expert in it)

aerrow5 commented 11 months ago

If you like to keep the code restricted to first hand API results, then I would suggest to document the implementation of a template sensor to have the efficiency calculated:

template
  - sensor:
      - name: "Estimated efficiency"
        unit_of_measurement: "Wh/km"
        state_class: measurement
        icon: map-marker-distance
        state: >
          {% set capacity = 67 | float %}
          {% set range = states('sensor.volvo_xxx_electric_range') | float %}
          {% set charge = states('sensor.volvo_xxx_battery_charge_level') | float %}
          {{ (( capacity * charge * 10) / range) | round(0, default=0) }}
Dielee commented 11 months ago

Yes. This seems to be a better solution for me. I will add your sensor to the Readme. Thanks!