history_stats传感器平台通过历史数据库,提供其他组件或平台的快速历史统计
它可以在自定义时间段内跟踪组件处于特定状态的时间长短。
您可以追踪的例子:
- 你在这个星期多久在家
- 昨天灯光亮了多久
- 你今天看电视多久了
详细内容见 https://home-assistant.io/components/sensor.history_stats/
这里提供一个范本,统计今日观看电视的时间,大于5小时在晚上21点播报提示。
直接下载好存于package文件夹内即可。
sensor:- platform: history_statsname: Fine weather this weekentity_id: sensor.1hour_weatherstate: '晴'type: timestart: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}'end: '{{ now() }}'- platform: history_statsname: How long you watched TV todayentity_id: automation.1hour_popstate: 'on'type: timestart: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'end: '{{ now() }}'group:History_Statistics:name: "历史统计"view: yesicon: mdi:timetableentities:- sensor.how_long_you_watched_tv_today- sensor.fine_weather_this_week- group.history_statshistory_stats:- sensor.how_long_you_watched_tv_today- sensor.fine_weather_this_week- automation.send_tv_reporthomeassistant:customize:sensor.how_long_you_watched_tv_today:friendly_name: 统计今日看电视时间icon: mdi:television-classicsensor.fine_weather_this_week:friendly_name: 统计本周晴天时间icon: mdi:weather-sunnyautomation.send_tv_report:friendly_name: 播报今日看电视时长icon: mdi:television-classicautomation:- alias: Send TV reportinitial_state: truehide_entity: falsetrigger:platform: timeat: '21:00:00'condition:condition: numeric_stateentity_id: sensor.how_long_you_watched_tv_todayabove: 5action:- service: tts.baidu_saydata_template:entity_id: media_player.vlc_playermessage: >"晚上好!您今天看了{{states.sensor.how_long_you_watched_tv_today.state}}小时的电视,我建议您多运动!"
文档更新时间: 2017-09-10 04:23 作者:Tristan