Get attribute to template sensor

This seems to be a somewhat common topic, the solutions i have read are all unique and none seem to work in my case. I always end up with the sensor being unavailable.
I haven’t figured exactly how i will deal with this data, for now i just want to make a template sensor that makes any of these numbers available that are under the source sensor’s state attributes. As you see comma separated under the label “today”.

today: 1.065, 1.059, 0.994, 1.061, 1.153, 1.12, 1.027, 1.468, 1.699, 1.61, 1.672, 1.67, 1.617, 1.171, 1.129, 1.152, 1.34, 1.795, 3.151, 3.413, 3.523, 3.155, 2.659, 2.042

Post what you have tried but didn’t work.

Well for example

      today1: 
        value_template: "{{ state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'today[1]') }}"

in several variations that i picked up in various posts around the internet.
Another was

      today1: 
        value_template: "{{ state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'today', [1]) }}"

And so on and so forth.

1 Like

Copy-paste the following template into the Template Editor and let me know if it reports anything useful (or an error message):

{{ state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'today').split(', ')[1] }}

NOTE

I am unfamiliar with the information contained by a Nordpool sensor so it’s unclear to me if the value of the today attribute is a comma-separated string or a list. The template above assumes it’s a string.

The sensor once again ends up unavailable and i get the following in the log:

TemplateError('UndefinedError: 'list object' has no attribute 'split'') while processing template 'Template("{{ state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'today').split(', ')[1] }}")' for attribute '_attr_native_value' in entity 'sensor.today1'

Don’t put the template I posted into a Template Sensor. Just put it into the Template Editor where it’s easy to experiment with it.

Anyway, the error message confirms what I was trying to determine (the attribute’s value is not a string but a list.

Copy-paste the following template into the Template Editor and let me know what it reports :

{{ state_attr('sensor.nordpool_kwh_se4_sek_3_10_025', 'today')[1] }}
1 Like

Wasn’t aware of the template editor, useful tool.
That did it, as expected i end up with the second value in the list. Thanks a bunch.

1 Like

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information, refer to guideline 21 in the FAQ.