I’ve been struggling to find a way to split long templates to preserve readability and avoid long lines in Yaml. For example, I have this template sensor to count how many “actual lights” are on.
I’ve tried avoiding one-liners since they are not very readable:
value_template: "{{ states | selectattr('entity_id', 'in', state_attr('group.actual_lights', 'entity_id')) | selectattr('state', 'eq', 'on') | list | count }}"
However, now I am not sure what the best approach might be to split it. Like this?
value_template: >
{{ states |
selectattr('entity_id', 'in', state_attr('group.actual_lights',
'entity_id')) |
selectattr('state', 'eq', 'on') | list | count }}
Or perhaps like this?
value_template: >
{{ states
| selectattr('entity_id',
'in',
state_attr('group.actual_lights', 'entity_id'))
| selectattr('state', 'eq', 'on')
| list
| count }}
I would appreciate if anyone can shed some guidance on how they approach such cases. Perhaps a Jinja style guide they follow or some tips. Thanks.