62 lines
2.0 KiB
Markdown
62 lines
2.0 KiB
Markdown
# 前言
|
||
- 和风天气(heweather) HomeAssistant插件使用说明 https://www.bilibili.com/opus/687775477026259015
|
||
- HomeAssistant 和风天气插件的自动化分享 https://www.bilibili.com/read/cv18078640/
|
||
# 和风天气 Token
|
||
afdc8b37975043888ad47943ff25b980
|
||
|
||
|
||
# HA
|
||
在configuration.yaml中添加:
|
||
```YAML
|
||
template:
|
||
- trigger:
|
||
- platform: time_pattern
|
||
hours: "*"
|
||
action:
|
||
- service: weather.get_forecasts
|
||
data:
|
||
type: hourly
|
||
target:
|
||
entity_id: weather.he_feng_tian_qi
|
||
response_variable: hourly
|
||
sensor:
|
||
- name: "小时天气预警"
|
||
unique_id: weather_forecast_hourly
|
||
state: >
|
||
{% if hourly['weather.he_feng_tian_qi'].forecast[0].condition in ('sunny','cloudy','partlycloudy','windy') %}
|
||
off
|
||
{% else %}
|
||
on
|
||
{% endif %}
|
||
attributes:
|
||
states: >
|
||
{% if hourly['weather.he_feng_tian_qi'].forecast[0].condition in ('sunny','cloudy','partlycloudy','windy') %}
|
||
未来一小时,天气{{ hourly['weather.he_feng_tian_qi'].forecast[0].text }},没有降雨
|
||
{% else %}
|
||
接下来一小时会有{{ hourly['weather.he_feng_tian_qi'].forecast[0].text }},降水概率为 {{ hourly['weather.he_feng_tian_qi'].forecast[0].precipitation_probability }}%
|
||
{% endif %}
|
||
```
|
||
|
||
## 自动化
|
||
对应的自动化:
|
||
```yaml
|
||
alias: 一小时天气预警
|
||
description: ""
|
||
triggers:
|
||
- entity_id:
|
||
- sensor.xiao_shi_tian_qi_yu_jing
|
||
trigger: state
|
||
actions:
|
||
- device_id: 384bea520a0ee825ecb63fb71d19b2a1
|
||
domain: mobile_app
|
||
type: notify
|
||
message: "注意注意! 接下来的天气为{{state_attr('sensor.xiao_shi_tian_qi_yu_jing','states')}} "
|
||
title: 天气预警
|
||
- action: notify.send_message
|
||
metadata: {}
|
||
data:
|
||
message: "[\"注意注意! {{state_attr('sensor.xiao_shi_tian_qi_yu_jing','states')}}\"]"
|
||
target:
|
||
entity_id: notify.xiaomi_cn_799945688_l06a_play_text_a_5_1
|
||
initial_state: true
|
||
``` |