本帖最后由 lidicn 于 2018-2-8 17:02 编辑
原理简介:
- 通过Scrapy sensor获取uid=4的用户的帖子数量【css_selectors选择器】
- binary_sensor.trend趋势传感器,用来检测帖子数量是否增加了
sensor:
- platform: scrape
resource: https://bbs.hassbian.com/home.php?mod=space&uid=4
name: new_topic
select: a[href="home.php?mod=space&uid=4&do=thread&view=me&type=thread&from=space"]
value_template: '{{ value.split(" ")[1] }}'
binary_sensor:
- platform: trend
sensors:
new_topic_increase:
entity_id: sensor.new_topic
automation:
- alias: "Newtopic"
trigger:
platform: state
entity_id: sensor.new_topic
condition:
- condition: state
entity_id: binary_sensor.new_topic_increase
state: 'on'
action:
- service: notify.notifypushbullet
data_template:
title: '大神有新帖子'
message: "大神有新帖子快去看看!"
- service: tts.baidu_say
data_template:
entity_id: media_player.vlc_player
message: >
"大神有新帖子快去看看!"
cache: false
- service: persistent_notification.create
data:
message: "https://bbs.hassbian.com/home.php?mod=space&uid=4&do=thread&view=me&type=thread&from=space"
title: "大神囧帅,他终于发新帖子了,快去看看!"[hide]
参考资料:
- https://home-assistant.io/components/sensor.scrape/
- https://home-assistant.io/components/binary_sensor.trend/
- http://www.w3school.com.cn/cssref/css_selectors.asp
- https://home-assistant.io/components/persistent_notification/
[/hide]
|