Last active
November 2, 2017 02:20
-
-
Save willwhui/7cd33c82853fc0d9a44852c3724842c5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
在haas on Raspberry 上设置一个random sensor触发的alert及automation |
用automation来触发twitter
- alias: 'Random sensor trigger twitter'
trigger:
platform: state
entity_id: binary_sensor.random_change
to: "on"
action:
service: notify.twitter_wang3an
data:
message: A random value less than 50 triggered this.
像上面这样写,只触发一次就没动静了,为什么呢?
看日志:
Oct 27 18:41:55 raspberrypi hass[941]: 2017-10-27 18:41:55 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.random_1, old_state=<state sensor.random_1=84; icon=mdi:hanger, friendly_name=random 1 @ 2017-10-27T18:41:24.308602+08:00>, new_state=<state sensor.random_1=27; icon=mdi:hanger, friendly_name=random 1 @ 2017-10-27T18:41:55.307233+08:00>>
^---- 上面这句是说:random值变了
Oct 27 18:41:55 raspberrypi hass[941]: 2017-10-27 18:41:55 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=binary_sensor.random_change, old_state=<state binary_sensor.random_change=off; friendly_name=A random value less than 50 @ 2017-10-27T18:38:18.315139+08:00>, new_state=<state binary_sensor.random_change=on; friendly_name=A random value less than 50 @ 2017-10-27T18:41:55.316416+08:00>>
^---- 上面这句说:binary_sensor.random_change的值变成on了(符合预期)
Oct 27 18:41:55 raspberrypi hass[941]: 2017-10-27 18:41:55 INFO (MainThread) [homeassistant.components.automation] Executing Random sensor trigger twitter
^---- 上面这句说:执行automation中(符合预期)
Oct 27 18:41:55 raspberrypi hass[941]: 2017-10-27 18:41:55 INFO (MainThread) [homeassistant.core] Bus:Handling <Event logbook_entry[L]: entity_id=automation.random_sensor_trigger_twitter, name=Random sensor trigger twitter, domain=automation, message=has been triggered>
^---- 写日志文件
Oct 27 18:41:55 raspberrypi hass[941]: 2017-10-27 18:41:55 INFO (MainThread) [homeassistant.helpers.script] Script Random sensor trigger twitter: Running script
^---- 运行scrip中
Oct 27 18:41:55 raspberrypi hass[941]: 2017-10-27 18:41:55 INFO (MainThread) [homeassistant.helpers.script] Script Random sensor trigger twitter: Executing step call service
^---- 可以call service了(符合预期)
Oct 27 18:41:55 raspberrypi hass[941]: 2017-10-27 18:41:55 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service=twitter_wang3an, domain=notify, service_data=message=A random value less than 50 triggered this., service_call_id=1971673456-3>
^---- bus处理事件:调用service=twitter_wang3an(符合预期)
Oct 27 18:41:56 raspberrypi hass[941]: 2017-10-27 18:41:56 ERROR (Thread-5) [homeassistant.components.notify.twitter] Error 403: [{'message': 'Status is a duplicate.', 'code': 187}]
^---- 返回错误:Status is a duplicate。莫非是twitter防止灌水用的?
Oct 27 18:41:56 raspberrypi hass[941]: 2017-10-27 18:41:56 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1971673456-3>
^---- 调用结束
信息里面有一个:
Error 403: [{'message': 'Status is a duplicate.', 'code': 187}]
原来是twitter干的:防止重复发送
参见:https://twittercommunity.com/t/status-is-a-duplicate/16928
修改一下触发后发送的内容:
- alias: 'Random sensor trigger twitter'
trigger:
platform: state
entity_id: binary_sensor.random_change
to: "on"
action:
service: notify.twitter_wang3an
data:
message: A random value less than 50 triggered this.
小坑
- 你可以在alias的平级增加
id: 1508639450841
这样一行(数字任意,避免和现有id重复)
这样就可以在hass的前端的configuration模块中,被automation模块识别列出了
但是:
一旦你对任何一个automaiton模块进行修改和保存,那么automations.xml中的所有内容都会被重写。
功能虽正常,但注释全被销毁,语句顺序也发生一定的变化。
所以还是别这样搞了。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
action中的特殊service:场景(scene)
参见:https://home-assistant.io/components/scene/
不知道为什么要用'capture'这个单词,难道是美语俗语?
根据上下文的意思和实际用途,这句话是这个意思:
“你可以创建一些场景,将特定的实体(entities,虚拟的或者真实的设备)设定到指定的状态。
类似于”
例子:
调用规则:貌似也很简单?
例子: