Templating: list friendly_name of all unavailable lights

Hi!

I would like to list (separated by comma) the friendly_name of all lights that are unavailable.

I got this far but then I got stuck.

{{ states.light|selectattr('state','equalto','unavailable')|list|join('\n') }}

It returns the text below where I can see the friendly_name, but I do not know how to extract it.

<template state light.portable_2=unavailable; restored=True, supported_features=40, friendly_name=portable 2 @ 2020-05-11T22:57:59.805573+02:00>
<template state light.sovrum_sangbord_daniel=unavailable; friendly_name=sovrum (sängbord daniel), supported_features=33 @ 2020-05-11T22:57:30.971928+02:00>
<template state light.sovrum_sangbord_ninni=unavailable; friendly_name=sovrum (sängbord ninni), supported_features=33 @ 2020-05-12T19:51:07.774874+02:00>
<template state light.tradfri_bulb_8=unavailable; restored=True, supported_features=0 @ 2020-05-11T22:57:59.811603+02:00>
<template state light.tyra_fonster_3=unavailable; friendly_name=tyra (fönster), supported_features=33 @ 2020-05-11T22:57:30.968700+02:00>

Thanks!

{{ states.light|selectattr('state','eq','unavailable')|map(attribute='attributes.friendly_name')|list|join(', ') }}
1 Like

Thanks for your quick response. I played around with the ‘map’ but didn’t get it right. Are all the different options documented anywhere for me to read up on?

1 Like

Go to the Template Editor in the front end (on the Developer Tools page.) There are two links to documentation.

1 Like