Extracting attributes to new sensor

Hello. My 1st post as a HA user, after many years of Openhab use. I have to say I wish I switched earlier - HA so much quicker and easier to use, especially with Z2M integration. Thank you all.

I’m trying to extract the ‘Last period’ attribute from a utility sensor. Using the Template editor (which is excellent) I can extract attributes with a single word, but not those with a space.

The attributes of the sensor below, plus some lines from template editor I’ve been trying.


Source -
Status - collecting
Last period - 0.28
Meter period - hourly
Cron pattern - 0 * * * *

Template Editor

{{ state_attr(‘sensor.hourly_electricity’, ‘Last period’) }}
{{ state_attr(‘sensor.hourly_electricity’, ‘status’) }}
{{ states.sensor.hourly_electricity.attributes.status }}
{{ states(‘sensor.hourly_electricity’) }}



Running latest HAOS on pi4

Thanks in advance

I am no way the expert but I have never seen attribs with a space, with me they are all with underscore… Shere did you get that info from? check developer tools > states (if not already done so)

Thank you! Still finding my way but states tool shows there is an underscore:

state_class: total_increasing
source: sensor.house_power_consumption_kwh
status: collecting
last_period: ‘1.16’
meter_period: hourly
cron pattern: 0 * * * *
last_reset: ‘2023-01-14T09:00:00.007218+00:00’
unit_of_measurement: kWh
device_class: energy
icon: mdi:counter
friendly_name: hourly_electricity

Working now once added the underscores.

The info shared earlier is from the attributes drop-down in the UI.

For completeness, revised line in template editor:

{{ state_attr(‘sensor.hourly_electricity’, ‘last_period’) }}

Thanks again @vingerha