Can't get separate list items in a template


i have a sensor that has a list as one of its attributes.
{{states.sensor.solaredge_equipment}} has the following result:
<template state sensor.solaredge_equipment=on; reporters=count=1, list=[{'name': 'Inverter 1', 'manufacturer': 'SolarEdge', 'model': 'SE7k', 'serialNumber': 'serial number', 'kWpDC': None}], friendly_name=SolarEdge Equipment, custom_ui_state_card=state-card-custom-ui, state_card_mode=badges @ 2018-01-30T09:45:55.951846+01:00>

I can narrow it down to the list, but then i don’t know how to filter out the separate list items. the list structure is new to me and i can’t find any documentation how templating works with this structure.

{{states.sensor.solaredge_equipment.attributes.reporters.list}} results in :

[{'name': 'Inverter 1', 'manufacturer': 'SolarEdge', 'model': 'SE7k', 'serialNumber': 'serial number', 'kWpDC': None}]

I want these items to be displayed separately but the [ ] is keeping me from succes…

Please have a look?


You can get the first item of a list with list[0], the second with list[1], and so on…
As your list contains only one item (a dictionary) you need [0]
Example from the Dev Tool/Templates:

{% set list = [{'name': 'Inverter 1', 'manufacturer': 'SolarEdge', 'model': 'SE7k', 'serialNumber': 'serial number', 'kWpDC': None}] %}
{{ list[0].name }} # returns 'Inverter 1'

Thank you!

I can now create the the template_sensors:

{{states.sensor.solaredge_equipment.attributes.reporters.list[0].name }} resulting in Inverter 1

    platform: template
          friendly_name: Name
          value_template: '{{states.sensor.solaredge_equipment.attributes.reporters.list[0].name }}'
          unit_of_measurement: 'Name'

Not very informative, but ever so useful for other sensors attributes.

Rest_sensors also possible now, with format following:

- platform: rest
  resource: !secret se_equipment_resource
  value_template: '{{[0].name }}'
  name: 'SolarEdge Name'
  unit_of_measurement: 'Name'
  scan_interval: 900

all seems to be working fine:

will tweak and group. Cool.

Thanks again!

please let me ask another template question here:
i have this customization of a light.
if (attributes.rgb_color) return “RGB:” + attributes.rgb_color ; return null;

I want the RGB values to have a leading space, like: “RGB: 255, 93, 41” but the parser wont allow this. A trailing space before the : isnt allowed either…

47 isnt very clear to me here, so might you know the solution?

please help me again with another sensor:

Ive created a jsonrest sensor on my PhilipsHue, successfully, and it creates it in the frontend.
As with the solaredge, im creating template sensors for the individual devices is pulls (GETS) from the hub.

in dev tools this works, up to the number of the sensor/light after which nothing shows up in the atributeslist. What am i missing here? Cant it read a number as attribute?
up to the sensors all is working perfectly:

and then add 1:

nothing appearing…

What am i doing wrong?
Hope you can help,

From the templating docs.

If your template uses an entity_id that begins with a number (example: states.device_tracker.2008_gmc) you must use a bracket syntax to avoid errors caused by rendering the entity_id improperly. In the example given, the correct syntax for the device tracker would be: states.device_tracker[‘2008_gmc’]

So ...sensors['1'] should do it.

Thank you very much!


they work in the templating machine in dev,
but not in the sensors, apparently something must be changed for it to be a valid template. Though no error is shown:

- platform: jsonrest
  resource: !secret hue_resource
  method: GET
  name: Philips Hue Equipment
  scan_interval: 10

- platform: template
      friendly_name: 'Daylight Corridor'
      value_template: "{states.sensor.philips_hue_equipment.attributes.sensors['1'].state.daylight}"

all sensors show like this:


while my solar edges sensors work perfectly:

- platform: jsonrest
  resource: !secret se_equipment_list_resource
  method: GET
  name: SolarEdge Equipment
  scan_interval: 3600

- platform: template
      friendly_name: Name
      value_template: '{{states.sensor.solaredge_equipment.attributes.reporters.list[0].name }}'

Well, count the curly brackets in your first and in your second example. :slightly_smiling_face:

yes, already spotted and changed :wink: thanks!

finetuning as we speak…

HI @VDRainer

setting up Lovelace brings me back to this. sorry to bother you again.

this time Ive made a rest sensor, (previous was json-rest made with the custom component)

- platform: rest
  name: solaredge_overview
  scan_interval: 400
    - overview
  value_template: >
    {{ value_json.states }}
  resource: !secret se_overview_resource

sensor are templated out as follows:

  friendly_name: 'SolarEdge Life Energy Production'
  value_template: >
    {{ ( | float / 1000000) | round(2) }}
  unit_of_measurement: 'MWh'

and many of these for below attributes:

{'overview': {'lastUpdateTime': '2018-12-22 17:14:42', 'lifeTimeData': {'energy': 9529284.0}, 'lastYearData': {'energy': 4657129.0}, 'lastMonthData': {'energy': 34812.0}, 'lastDayData': {'energy': 2343.0}, 'currentPower': {'power': 0.0}, 'measuredBy': 'INVERTER'}, 'friendly_name': 'solaredge_overview', 'custom_ui_state_card': 'state-card-custom-ui', 'state_card_mode': 'badges'}

I want to write in these sensors in the state_attr() form, but, as earlier, can’t find my way…

    {{ state_attr('sensor.solaredge_overview','overview') }} has 

   {'lastUpdateTime': '2018-12-22 17:14:42', 'lifeTimeData': {'energy': 9529284.0}, 'lastYearData': {'energy': 4657129.0}, 'lastMonthData': {'energy': 34812.0}, 'lastDayData': {'energy': 2343.0}, 'currentPower': {'power': 0.0}, 'measuredBy': 'INVERTER'} 

as output,

the above sensor written in the form

    {{ (state_attr('sensor.solaredge_overview','' )| float / 1000000) | round(2) }}

makes no sense (0,0 because it floats a None)…
obviously I need to use the list again but don’t know how. Or isn’t this possible using this notation.

Please have a look once again? thx!