Filtering entity card value based on selected period

I’ve added this new sensor to my configuration.yaml file:

      - name: "Consumo diretto"
        unit_of_measurement: Wh
        device_class: energy       
        state: "{{ states('sensor.photovoltaics_energy') | float(default=0) - states('sensor.battery_energy_charged') | float(default=0) + states('sensor.grid_energy_immessa') | float(default=0) }}"

and I’ve added an entity card to show this sensor in my dashboard.

The problem is that it always shows the total value since the beginning, no matter what I select in the Energy Period Selector Plus Card (e.g. TODAY) that is also present in the dashboard.

How can I make the Energy Period Selector affect the value of the entity card?

Not sure about your question, maybe as it is new it has no history yet?

However…

That sensor is going to mess up your energy dashboard eventually and you should protect against this by adding an availability template.

      - name: "Consumo diretto"
        unit_of_measurement: Wh
        device_class: energy       
        state: "{{ states('sensor.photovoltaics_energy') | float(default=0) - states('sensor.battery_energy_charged') | float(default=0) + states('sensor.grid_energy_immessa') | float(default=0) }}"
        availability: "{{ has_value('sensor.photovoltaics_energy') and has_value('sensor.battery_energy_charged') and has_value('sensor.grid_energy_immessa') }}"

I just explained why here: How can I merge the values of 2 meters into 1 and use them in the energy dashboard? - #3 by tom_l

The sensor seems to be working.

Screenshot 2024-03-09 at 14.57.54

but it shows the cumulated value since the beginning while I would like to show only the daily value (or the period I select with the Energy Period Selector).

Thanks for your suggestion… I’ve added the availability template.

Use this helper: