I want to obtain the energy consumed from a power sensor. I know I can get it with the Riemann Sum Integral, but I want to get the sum only when an input_boolean
has a given value (on
or off
).
To give some context, I have a tariff with two time periods, one cheap (valley) period and another expensive (peak) period. I’d like to get the energy consumed (and also the cost) of each period. Latter on, I’d get the energy (cost) of electricy in each period for today, yesterday, … with the new Statistic Card.
This information is not given in the energy panel, although it can be taken it into account there to get the total cost of energy.
Thanks
I’ve solved this creating template sensors with power consumption in cheap and expensive periods by means of:
sensor:
- platform: template
sensors:
piso_calefaccion_potencia_barato:
friendly_name: Piso calefacción potencia barato
device_class: power
unit_of_measurement: W
value_template: >
{% if states('input_boolean.piso_horario_barato') == 'on' %}
{{ states('sensor.shelly_piso_channel_1_power') }}
{% else %}
{{0 | float }}
{% endif %}
piso_calefaccion_potencia_caro:
friendly_name: Piso calefaccion potencia caro
device_class: power
unit_of_measurement: W
value_template: >
{% if states('input_boolean.piso_horario_barato') == 'off' %}
{{ states('sensor.shelly_piso_channel_1_power') }}
{% else %}
{{0 | float }}
{% endif %}
where input_boolean.piso_horario_barato
is on
for cheap period and off
for expensive one.
After that, I’ve created integration sensor helpers, which can be loaded into energy panel.
In this way, the energy panel will split energy consumption and costs among cheap and expesive periods.