Selectattr and state_attr do not work on list of dicts in Evohome integration

First of all, I am using HA Core 2024.7.3 on Python 3.12.4 in a clean venv on Rocky Linux 9

I have a Honeywell Total Connect Comfort (EU) system running and use the build-in integration.

When I look up any of the climate entities in STATES tab on the Developers tools page (for instance climate.eetkamer), it shows me this list of attributes:

hvac_modes: off, heat
min_temp: 5
max_temp: 35
preset_modes: none, temporary, permanent
current_temperature: 22.6
temperature: 11
preset_mode: permanent
status: 
setpoints:
  this_sp_from: '2024-07-19T22:30:00+02:00'
  this_sp_temp: 16
  next_sp_from: '2024-07-20T08:00:00+02:00'
  next_sp_temp: 21
zone_id: '*******'
active_faults:
  - faultType: TempZoneActuatorLowBattery
    since: '2024-07-16T17:57:07'
setpoint_status:
  target_heat_temperature: 11
  setpoint_mode: PermanentOverride
temperature_status:
  temperature: 22.5
  is_available: true

friendly_name: Eetkamer
supported_features: 401

Now, when I go to the TEMPLATE tab and enter the following:

{{ states.climate | selectattr('attributes.friendly_name','eq','Eetkamer') | selectattr('attributes.temperature','defined') | list }}

it returns the climate entity as expected (manually formatted for readability):

[<template TemplateState(<state climate.eetkamer=off; 
	[
		hvac_modes=[
			<HVACMode.OFF: 'off'>, 
			<HVACMode.HEAT: 'heat'>
		],
		min_temp=5.0,
		max_temp=35.0,
		preset_modes=[
			'none', 
			'temporary', 
			'permanent'
		], 
		current_temperature=22.6, 
		temperature=11.0, 
		preset_mode=permanent, 
		status=
			setpoints=
				this_sp_from=2024-07-19T22:30:00+02:00, 
				this_sp_temp=16.0, 
				next_sp_from=2024-07-20T08:00:00+02:00, 
				next_sp_temp=21.0, 
		zone_id=*******, 
		active_faults=[
			{
				'faultType': 'TempZoneActuatorLowBattery', 
				'since': '2024-07-16T17:57:07'
			}
		], 
		setpoint_status=
			target_heat_temperature=11.0, 
			setpoint_mode=PermanentOverride, 
		temperature_status=
			temperature=22.5, 
			is_available=True, 
		friendly_name=Eetkamer, 
		supported_features=401

		@ 2024-07-19T20:37:53.646918+02:00>)
	]
>]

Now, instead of making sure temperature is defined, I want to select all the climate entities that have the attribute active_faults defined. However, the following template returns an empty list:

{{ states.climate | selectattr('attributes.friendly_name','eq','Eetkamer') | selectattr('attributes.active_faults','defined') | list }}

Specifying ANY other attribute returns correct data, (preset_modes works fine and even status.setpoints.this_sp_from returns the same data). Only when I specify active_faults it returns an empty list.

Similar for state_attr:

{{ state_attr(' climate.eetkamer','temperature') }}

Returns the expected value (11.0 in this example) but

{{ state_attr('climate.eetkamer','active_faults') }}

returns null

Can anybody help me out here? I need to create some sensors based on the active_faults attribute.

Thanx for your help!

just curious…

what do you get if you do

{{ states.climate.eetkamer.attributes.active_faults }}  

This returns the following error:

'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'active_faults'

However, {{ states.climate.eetkamer.attributes.temperature }} returns: 11

and {{ states.climate.eetkamer.attributes }} returns

{'hvac_modes': [<HVACMode.OFF: 'off'>, <HVACMode.HEAT: 'heat'>], 'min_temp': 5.0, 'max_temp': 35.0, 'preset_modes': ['none', 'temporary', 'permanent'], 'current_temperature': 23.1, 'temperature': 11.0, 'preset_mode': 'permanent', 'status': {'setpoints': {'this_sp_from': '2024-07-21T10:00:00+02:00', 'this_sp_temp': 21.0, 'next_sp_from': '2024-07-21T18:00:00+02:00', 'next_sp_temp': 21.0}, 'zone_id': '*******', 'active_faults': [{'faultType': 'TempZoneActuatorLowBattery', 'since': '2024-07-16T17:57:07'}], 'setpoint_status': {'target_heat_temperature': 11.0, 'setpoint_mode': 'PermanentOverride'}, 'temperature_status': {'temperature': 23.0, 'is_available': True}}, 'friendly_name': 'Eetkamer', 'supported_features': <ClimateEntityFeature.TARGET_TEMPERATURE|PRESET_MODE|TURN_OFF|TURN_ON: 401>}

which (somewhere halveway through) clearly shows 'active_faults':

So, I am completely mistified…

I opened an issue on github for this problem: Selectattr and state_attr do not work on list of dicts in Evohome integration · Issue #122305 · home-assistant/core · GitHub

Please try the following template and let us know what it reports.

{% set af = 'active_faults' %}
{% for k in states.climate.eetkamer.attributes.keys()
  if af in k -%}
{{ k }}, {{ k|count }}, {{ k == af }}, {{ k|trim == af }}
{% endfor %}

Ideally, it should report:

active_faults, 13, True, True

The result is an empty string

This:

{% for k in states.climate.eetkamer.attributes.keys() -%}
{{ k }}
{% endfor %}

Results in:

hvac_modes
min_temp
max_temp
preset_modes
current_temperature
temperature
preset_mode
status
friendly_name
supported_features

and

{{ states.climate.eetkamer.attributes.keys() }}

Results in:

dict_keys(['hvac_modes', 'min_temp', 'max_temp', 'preset_modes', 'current_temperature', 'temperature', 'preset_mode', 'status', 'friendly_name', 'supported_features'])

BUT

{{ states.climate.eetkamer.attributes }}

Results in:

{'hvac_modes': [<HVACMode.OFF: 'off'>, <HVACMode.HEAT: 'heat'>], 'min_temp': 5.0, 'max_temp': 35.0, 'preset_modes': ['none', 'temporary', 'permanent'], 'current_temperature': 22.7, 'temperature': 11.0, 'preset_mode': 'permanent', 'status': {'setpoints': {'this_sp_from': '2024-07-21T18:00:00+02:00', 'this_sp_temp': 21.0, 'next_sp_from': '2024-07-21T23:00:00+02:00', 'next_sp_temp': 16.0}, 'zone_id': '*******', 'active_faults': [{'faultType': 'TempZoneActuatorLowBattery', 'since': '2024-07-16T17:57:07'}], 'setpoint_status': {'target_heat_temperature': 11.0, 'setpoint_mode': 'PermanentOverride'}, 'temperature_status': {'temperature': 22.5, 'is_available': True}}, 'friendly_name': 'Eetkamer', 'supported_features': <ClimateEntityFeature.TARGET_TEMPERATURE|PRESET_MODE|TURN_OFF|TURN_ON: 401>}

Thanks for performing the test.

I now see that active_faults is within the status attribute.

{{ states.climate.eetkamer.attributes.status.active_faults | list }}
1 Like

OH WOW, I completely missed out on that indentation…

Thanx for pointing that out!

1 Like