I have an existing binary sensor created from a template (old format, I know ).
binary_sensor:
- platform: template
sensors:
sensor_fault:
friendly_name: "Sensor Fault"
value_template: >-
{{ states.sensor
| selectattr('attributes.unit_of_measurement', 'defined')
| selectattr('attributes.unit_of_measurement', '==', '°C')
| selectattr('attributes.sensor_type', 'defined')
| selectattr('attributes.sensor_type', '==', 'LYWSDCGQ')
| selectattr('attributes.last_median_of', '<', 5)
| list | count > 0 }}
This returns true when at least one of the sensors last_median_of
value of less than 5.
What I would like to do is extract the friendly names of the sensors that failed the test, into an attribute. I just cannot get the template right to return just the friendly name. Is it possible?
I can return a list of the failed sensors by just removing the count > 0
but I cannot work out how to extract the friendly name.
[<template TemplateState(<state sensor.mi_t_4c65a8d8de98=19.4; state_class=measurement, sensor_type=LYWSDCGQ, mac_address=4C:65:A8:D8:DE:98, median=19.4, mean=19.4, last_median_of=1, rssi=-88, firmware=Xiaomi (MiBeacon V2), last_packet_id=99, battery_level=13, uuid=4C:65:A8:D8:DE:98, unit_of_measurement=°C, device_class=temperature, friendly_name=Catherine Room Temp @ 2022-10-02T13:52:54.202433+01:00>)>]