Extracting attributes for current date

I have this entity and want to extract the values of current day into entities through templating. Can anyone help me?

entity:
sensor.kona_daily_driving_stats

Returns:
2023-12-01:
total_consumed: 7568
engine_consumption: 5174
climate_consumption: 1524
onboard_electronics_consumption: 870
battery_care_consumption: 0
regenerated_energy: 2618
distance: 48

Tried this, but doesn’t work. Returns 0

{% set attr = state_attr(“sensor.kona_daily_driving_stats”, now().date()) %}
{{ 0 if attr == None else attr[“total_consumed”] /1000|int }}

Please format your code correctly.

It’s not completely clear from your post what the entity state and attributes are. Please post a screenshot like this showing it:

or the properly-formatted output of this in the TEMPLATE editor:

{{ states.sensor.kona_daily_driving_stats }}

In addition to everything Troon said:

now().date() isn’t a string and state_attr() expects a string value for the attributes name. To get the date string use now().date() | string.

{% set attr = state_attr("sensor.kona_daily_driving_stats", now().date() | string ) %}
{{ 0 if attr == none else (attr["total_consumed"] /1000) | int }}

Here is a screenshot:

Many thanks for your kindness

In that case, Drew’s suggestion above should work for you. Just turn the date into a string, and make sure you are applying int to the whole statement not just the 1000.

Works. :slight_smile:

Many thanks to you both

/Lars

Hi Lars, please take the time to mark the answer as solution, you do that by selecting the three dots under the post:

image

Then select the check box:

image

By doing so this can be useful to other users as well and prevents that someone else steps in and still tries to help you.