Can't get separate list items in a template

HI,

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?

Cheers,
Marius

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
      sensors:
        solaredge_equipment_name:
          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: '{{ value_json.equipment.reporters.list[0].name }}'
  name: 'SolarEdge Name'
  unit_of_measurement: 'Name'
  scan_interval: 900

all seems to be working fine:

51
will tweak and group. Cool.

Thanks again!
Marius

please let me ask another template question here:
i have this customization of a light.
light.dining_corner:
extra_data_template:
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
http://jinja.pocoo.org/docs/dev/templates/#whitespace-control isnt very clear to me here, so might you know the solution?

@VDRainer
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,
Marius

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.

BIngo!
Thank you very much!


Cheers,
Marius

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
  sensors:
    philips_hue_sensor_1_daylight:
      friendly_name: 'Daylight Corridor'
      value_template: "{states.sensor.philips_hue_equipment.attributes.sensors['1'].state.daylight}"

all sensors show like this:

36

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
  sensors:
    solaredge_equipment_name:
      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
  json_attributes:
    - overview
  value_template: >
    {{ value_json.states }}
  resource: !secret se_overview_resource

sensor are templated out as follows:

solaredge_lifetime_energy:
  friendly_name: 'SolarEdge Life Energy Production'
  value_template: >
    {{ (states.sensor.solaredge_overview.attributes.overview.lifeTimeData.energy | 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','overview.lifeTimeData.energy' )| 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!