template学习
1、统计楼层开灯数量
{%- set ns = namespace(total_lights_on=0) %}
{%- set rooms = floor_areas('yi_lou') %}
{%- for room in rooms %}
{%- set entities = area_entities(room) %}
{%- for entity in entities %}
{%- if states[entity] is not none and states[entity].domain == 'light' and states[entity].state == 'on' %}
{%- set ns.total_lights_on = ns.total_lights_on + 1 %}
{%- endif %}
{%- endfor %}
{%- endfor %}
{{ ns.total_lights_on }}
2、遍历楼层实体
{%- set rooms = floor_areas('yi_lou') %}
{%- for room in rooms %}
Room: {{ room }}
{%- set entities = area_entities(room) %}
{%- for entity in entities %}
Entity: {{ entity }} - State: {{ states[entity].state if states[entity] is not none else 'unknown' }}
{%- endfor %}
{%- endfor %}
License:
CC BY 4.0