{% if entities %}
{% for entity_id, state in entities %}
{{ entity_id }}
{% set s = state.get("state", "unknown") if state is mapping else state %}
{% if s == "on" %}
{{ s }}
{% elif s == "off" %}
{{ s }}
{% elif s == "unavailable" %}
{{ s }}
{% else %}
{{ s }}
{% endif %}
{% if state is mapping and state.get("last_changed") %}
{{ state.last_changed }}
{% else %}
—
{% endif %}
{% if state is mapping and state.get("attributes") %}
{% set attrs_json = state.attributes | tojson %}