本帖最后由 wwek 于 2018-6-26 23:02 编辑
# [url=https://www.home-assistant.io/components/sensor.template/]https://www.home-assistant.io/components/sensor.template/[/url]
# [url=https://www.home-assistant.io/components/rest_command/]https://www.home-assistant.io/components/rest_command/[/url]
# [url=https://open-doc.dingtalk.com/docs/doc.htm?spm=a219a.7629140.0.0.karFPe&treeId=257&articleId=105735&docType=1]https://open-doc.dingtalk.com/do ... Id=105735&docType=1[/url]
sensor:
- platform: template
sensors:
wwek_caiyun_1hour:
friendly_name: "1小时下雨预测"
value_template: >
"{{states('sensor.caiyun_minutely_description')}},
一小时内百分之{{states('sensor.caiyun_minutely_probability_1')}}的可能会下
{% if states.sensor.caiyun_minutely_precipitation.state | float < 0.9 %}
小雨
{% elif states.sensor.caiyun_minutely_precipitation.state | float < 2.87 %}
中雨
{% elif states.sensor.caiyun_minutely_precipitation.state | float > 2.87 %}
大雨
{% endif %}"
rest_command:
dingding_wwek_caiyun_1hour:
method: POST
url: 'https://oapi.dingtalk.com/robot/send?access_token=你的钉钉token'
headers:
content-type: application/json
# AUTH-TOKEN: !secret: token
payload: >
{"msgtype": "text",
"text": {"content": {{states.sensor.wwek_caiyun_1hour.state}}},
"at": {"atMobiles": ["1825718XXXX"],"isAtAll": false}
}
说明
1. 要发送的消息,最好是做个模板传感器,这样好调试,也不容易出错
2. payload我调了好久,按照我的方式写就可以成功, 按照最小化配置进行调试3. 钉钉建普通群,可以先拉2个人建群,然后再踢出去, 新增加webhook机器人, 这个token就是这个机器人的token。具体的看钉钉官方文档
再来一个用 data_template 方式的
rest_command:
dingding_wwek_text:
method: POST
url: 'https://oapi.dingtalk.com/robot/send?access_token=你的钉钉token'
headers:
content-type: application/json
payload: '{{ payload }}'
automation:
#高温预警
- alias: w_alert35
initial_state: true
trigger:
- platform: time
hours: 22
minutes: 10
seconds: 0
condition:
condition: numeric_state
entity_id: sensor.caiyun_day1_temperature_max
above: 34
action:
- service: rest_command.dingding_wwek_text
data_template:
payload: >
{"msgtype": "text",
"text": {"content": "{%- if states('sensor.caiyun_day1_temperature_max') | float >34 and
states('sensor.caiyun_day1_temperature_max') | float <36 -%}
明天将会出现35°C以上高温,其中最高温度将达到{{states('sensor.caiyun_day1_temperature_max')}}°C,
天气热,请注意防暑降温;户外工作或活动时,要避免长时间在阳光下曝晒,同时采取防晒措施。
{%- elif states('sensor.caiyun_day1_temperature_max') | float >36 and
states('sensor.caiyun_day1_temperature_max') | float <39 -%}
明天将会出现37°C以上高温,其中最高温度将达到{{states('sensor.caiyun_day1_temperature_max')}}°C,
天气炎热,容易中暑,请注意(尤其是老弱病人)防暑降温;应尽量避免在强烈阳光下进行户外工作或活动。
{%- elif states('sensor.caiyun_day1_temperature_max') | float >39 -%}
明天将会出现40°C以上高温,其中最高温度将达到{{states('sensor.caiyun_day1_temperature_max')}}°C,
天气酷热,极易中暑,请注意(尤其是老弱病人和儿童)因中暑引发其他疾病的防护措施。
{%- endif %}"},
"at": {"atMobiles": ["1825718XXXX"],"isAtAll": false}
}
ps: 麻烦版主移动下帖子到自动化区
|