I am trying to make my own “solar saving sensors” but have issues with the Riemann sum integration that perhaps someone have a good answer to…
As an example:
I have made a sensor that calculates the energy cost my PV is putting in my battery bank
- unique_id: pv_to_batt
name: pv_to_batt
unit_of_measurement: 'kr'
device_class: monetary
state: >
{% set batt = states('sensor.battery_charge_discharge_power')|float %}
{% set price = states('sensor.electricity_price')|float %}
{% set batt_charging = batt > 0 %}
{% set pv2batt = batt if batt_charging else 0 %}
{{ pv2batt * price *0.001 }}
availability: >
{% set sstate = states('sensor.battery_charge_discharge_power') %}
{{ sstate != 'unavailable' and sstate != 'unknown' }}
That part works fine but its the integral that follows thats giving me issues
- platform: integration
unique_id: pv2batt_integral
source: sensor.pv_to_batt
name: test_pv_to_batt_integral
round: 2
method:
left
The integral is always adding a “unit_time” prefix to the sensor.
So in this case its an “h” as its the default, so its presented as “krh”
Been trying to get around this by playing with the “unit_time” variable but without success.
Any suggestions
edit: I mean without cheating and using the customizing function ofc…