Skip to content

Template error in Template Editor while it works fine as custom template sensor #71360

Closed
@smarthomejunkie

Description

@smarthomejunkie

The problem

I hope this is the right place to report this.

I use this code in a template sensor which works fine in that template sensor. However, when I use this code in the Developer Tools->Template Editor I get an error.

The code is:
{% set sensors = states.sensor
| selectattr('attributes.device_class', '==', 'battery')
| selectattr('attributes.state_class', '==', 'measurement')
| rejectattr('state', 'in', ['unavailable', 'unknown'])
| list %}

The error is:
UndefinedError: 'homeassistant.util.read_only_dict.ReadOnlyDict object' has no attribute 'device_class'

What version of Home Assistant Core has the issue?

Core 2022.5.0

What was the last working version of Home Assistant Core?

core-2022.4.6

What type of installation are you running?

Home Assistant Supervised

Integration causing the issue

No response

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

{% set sensors = states.sensor 
  | selectattr('attributes.device_class', '==', 'battery') 
  | selectattr('attributes.state_class', '==', 'measurement') 
  | rejectattr('state', 'in', ['unavailable', 'unknown'])
  | list %}

Anything in the logs that might be useful for us?

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions