template:
- sensor:
####################################################
# 灯光状态 #
####################################################
- unique_id: light_state
state: >
{% set lights = [
states.light.yi_lou_ke_ting,
states.light.yi_lou_fang_jian,
states.light.yi_lou_fan_ting,
states.light.ru_hu_zhao_ming,
states.light.yi_lou_chu_fang,
states.light.yi_lou_gong_wei,
states.light.yi_lou_ti_jian,
states.light.yi_lou_lou_ti,
states.light.da_men_zhao_ming,
states.light.er_lou_ti_tai,
states.light.er_lou_ke_ting,
states.light.er_lou_nan_fang,
states.light.er_lou_bei_fang,
states.light.er_lou_gong_wei,
states.light.er_lou_lou_ti,
states.light.er_lou_bei_yong,
states.light.san_lou_ti_tai,
states.light.san_lou_fang_jian,
states.light.san_lou_gong_wei,
states.light.san_lou_yang_tai,
states.light.lumi_acn01_71fb_light
] %}
{% set lights_on = lights | selectattr('state','eq','on') | list %}
{% set lights_name = lights | selectattr('state','eq','on') | map(attribute='name') | join(', ') %}
{% if (lights_on | length == 1) %}{{ lights_name }}点亮
{% elif (lights_on | length > 1) %}{{ lights_on | length }}盏灯点亮
{% else %} 全部关闭
{% endif %}
attributes:
friendly_name: "灯光状态"
####################################################
# 树莓派 #
####################################################
- unique_id: pi01_temperature
state: "{{ state_attr('sensor.rpi_monitor_raspberrypi_01', 'temp_cpu_c') }}"
attributes:
friendly_name: "CPU 温度"
unit_of_measurement: "°C"
- unique_id: pi02_temperature
state: "{{ state_attr('sensor.rpi_monitor_raspberrypi_02', 'temp_cpu_c') }}"
attributes:
friendly_name: "CPU 温度"
unit_of_measurement: "°C"
- unique_id: pi03_temperature
state: "{{ state_attr('sensor.rpi_monitor_raspberrypi_03', 'temp_cpu_c') }}"
attributes:
friendly_name: "CPU 温度"
unit_of_measurement: "°C"
- unique_id: pi04_temperature
state: "{{ state_attr('sensor.rpi_monitor_raspberrypi_04', 'temp_cpu_c') }}"
attributes:
friendly_name: "CPU 温度"
unit_of_measurement: "°C"
####################################################
# 涂鸦电表 #
####################################################
- unique_id: tuya01_dang_qian_dian_ya
state: "{{ state_attr('switch.zong_biao_kai_guan', 'voltage') }}"
attributes:
friendly_name: "当前电压"
unit_of_measurement: 'V'
- unique_id: tuya01_dang_qian_dian_liu
state: "{{ state_attr('switch.zong_biao_kai_guan', 'current') | float / 1000 | int(default='NaN') }}"
availability: "{{ state_attr('switch.zong_biao_kai_guan', 'current') not in ['unavailable', 'unknown', 'none'] }}"
attributes:
friendly_name: "当前电流"
unit_of_measurement: 'A'
- unique_id: tuya01_dang_qian_gong_lu
state: "{{ state_attr('switch.zong_biao_kai_guan', 'current_consumption') }}"
attributes:
friendly_name: "当前功率"
unit_of_measurement: 'W'
- unique_id: tuya01_zong_yong_dian_liang
state: "{{ states('sensor.zong_biao_dian_liang') | float / 100 | int(default='NaN') }}"
availability: "{{ states('sensor.zong_biao_dian_liang') not in ['unavailable', 'unknown', 'none'] }}"
attributes:
friendly_name: "总用电量"
unit_of_measurement: 'kWh'
####################################################
# 米家设备 #
####################################################
- unique_id: vacuum_model
state: "{{ state_attr('vacuum.viomi_v17_7e3e_robot_cleaner', 'model') }}"
attributes:
friendly_name: "机器型号"
- unique_id: vacuum_sweep_type
state: "{{ state_attr('vacuum.viomi_v17_7e3e_robot_cleaner', 'vacuum.sweep_type') }}"
attributes:
friendly_name: "扫地模式"
- unique_id: vacuum_fan_speed
state: "{{ state_attr('vacuum.viomi_v17_7e3e_robot_cleaner', 'fan_speed') }}"
attributes:
friendly_name: "风扇转速"
- unique_id: mijia_dang_qian_dian_ya
state: "{{ states('sensor.lxzn_cbcsmj_de47_voltage') | float / 10 | int(default='NaN') }}"
availability: "{{ states('sensor.lxzn_cbcsmj_de47_voltage') not in ['unavailable', 'unknown', 'none'] }}"
attributes:
friendly_name: "当前电压"
unit_of_measurement: 'V'
- unique_id: mijia_dang_qian_dian_liu
state: "{{ states('sensor.lxzn_cbcsmj_de47_electric_current') | float / 1000 | int(default='NaN') }}"
availability: "{{ states('sensor.lxzn_cbcsmj_de47_electric_current') not in ['unavailable', 'unknown', 'none'] }}"
attributes:
friendly_name: "当前电流"
unit_of_measurement: 'A'
- unique_id: mijia_dang_qian_gong_lu
state: >
{% if states('sensor.lxzn_cbcsmj_de47_voltage')|is_number and
states('sensor.lxzn_cbcsmj_de47_electric_current')|is_number
%}
{{( states('sensor.lxzn_cbcsmj_de47_voltage') | float(0) * states('sensor.lxzn_cbcsmj_de47_electric_current') | float /10000) | round(2) }}
{% else %}
{{ this.state }}
{% endif %}
attributes:
friendly_name: "当前功率"
unit_of_measurement: 'W'
####################################################
# 彩云天气 #
####################################################
- unique_id: weather_jia_forecast_hourly
state: "{{ state_attr('weather.jia', 'forecast_hourly') }}"
attributes:
friendly_name: "彩云天气实况"
- unique_id: weather_jia_forecast_minutely
state: "{{ state_attr('weather.jia', 'forecast_minutely') }}"
attributes:
friendly_name: "彩云天气预测"
- unique_id: weather_jia_hourly_cloudrate
state: "{{ state_attr('weather.jia', 'hourly_cloudrate')[0]['value'] }}"
attributes:
friendly_name: "彩云天气云量"
- unique_id: weather_jia_hourly_precipitation
state: "{{ state_attr('weather.jia', 'hourly_precipitation')[0]['value'] }}"
attributes:
friendly_name: "彩云天气降水"
####################################################
# 和风天气 #
####################################################
- unique_id: weather_tianqi_condition_cn
state: "{{ state_attr('weather.tian_qi', 'condition_cn') }}"
attributes:
friendly_name: "和风天气"
- unique_id: weather_tianqi_temperature
state: "{{ state_attr('weather.tian_qi', 'temperature') }}"
attributes:
friendly_name: "和风天气温度"
- unique_id: weather_tianqi_humidity
state: "{{ state_attr('weather.tian_qi', 'humidity') }}"
attributes:
friendly_name: "和风天气湿度"
- unique_id: weather_tianqi_forecast_minutely
state: "{{ state_attr('weather.tian_qi', 'forecast_minutely') }}"
attributes:
friendly_name: "和风天气实况"
- unique_id: weather_tianqi_forecast_hourly
state: "{{ state_attr('weather.tian_qi', 'forecast_hourly') }}"
attributes:
friendly_name: "和风天气预测"
- unique_id: weather_tianqi_hourly_forecast_cloudy
state: "{{ state_attr('weather.tian_qi', 'hourly_forecast')[0]['cloudy'] }}"
attributes:
friendly_name: "和风天气云量"
- unique_id: weather_tianqi_hourly_forecast_precipitation
state: "{{ state_attr('weather.tian_qi', 'hourly_forecast')[0]['precipitation'] }}"
attributes:
friendly_name: "和风天气降水"
- name: 一小时天气预警
state: '{% if ("雨" in states.weather.tian_qi.attributes.hourly_forecast[0].text) %}{{states.weather.tian_qi.attributes.hourly_forecast[0].datetime}}降雨概率为:{{states.weather.tian_qi.attributes.hourly_forecast[0].probable_precipitation}}%,可能{{states.weather.tian_qi.attributes.hourly_forecast[0].text}},请多加注意!{% else %}未来一小时无不良天气{% endif %}'
- name: 自然灾害预警最新一条
state: '{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].pubTime}}{% else %}当前无自然灾害预警信息{% endif %}'
attributes:
title: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].title}} {% else %}null{% endif %}"
text: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].text }} {% else %}null{% endif %}"
pubTime: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].pubTime}} {% else %}null{% endif %}"
startTime: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].startTime}} {% else %}null{% endif %}"
endTime: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].endTime}} {% else %}null{% endif %}"
sender: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].sender}} {% else %}null{% endif %}"
severity: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].severity}} {% else %}null{% endif %}"
severityColor: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].severityColor}} {% else %}null{% endif %}"
level: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].level}} {% else %}null{% endif %}"
typeName: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning[0].typeName}} {% else %}null{% endif %}"
all: "{% if (states.weather.tian_qi.attributes.warning) %}{{ states.weather.tian_qi.attributes.warning}} {% else %}null{% endif %}"