本帖最后由 lidicn 于 2017-7-15 19:55 编辑
history_stats传感器平台通过历史数据库,提供其他组件或平台的快速历史统计 它可以在自定义时间段内跟踪组件处于特定状态的时间长短。 您可以追踪的例子: - 你在这个星期多久在家
- 昨天灯光亮了多久
- 你今天看电视多久了
详细内容见https://home-assistant.io/components/sensor.history_stats/
这里提供一个范本,统计今日观看电视的时间,大于5小时在晚上21点播报提示。
直接下载好存于package文件夹内即可。
sensor:
- platform: history_stats
name: Fine weather this week
entity_id: sensor.1hour_weather
state: '晴'
type: time
start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}'
end: '{{ now() }}'
- platform: history_stats
name: How long you watched TV today
entity_id: automation.1hour_pop
state: 'on'
type: time
start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
end: '{{ now() }}'
group:
History_Statistics:
name: "历史统计"
view: yes
icon: mdi:timetable
entities:
- sensor.how_long_you_watched_tv_today
- sensor.fine_weather_this_week
- group.history_stats
history_stats:
- sensor.how_long_you_watched_tv_today
- sensor.fine_weather_this_week
- automation.send_tv_report
homeassistant:
customize:
sensor.how_long_you_watched_tv_today:
friendly_name: 统计今日看电视时间
icon: mdi:television-classic
sensor.fine_weather_this_week:
friendly_name: 统计本周晴天时间
icon: mdi:weather-sunny
automation.send_tv_report:
friendly_name: 播报今日看电视时长
icon: mdi:television-classic
automation:
- alias: Send TV report
initial_state: true
hide_entity: false
trigger:
platform: time
at: '21:00:00'
condition:
condition: numeric_state
entity_id: sensor.how_long_you_watched_tv_today
above: 5
action:
- service: tts.baidu_say
data_template:
entity_id: media_player.vlc_player
message: >
"晚上好!您今天看了{{states.sensor.how_long_you_watched_tv_today.state}}小时的电视,我建议您多运动!"
|