HASS和风天气

通过配置和风天气开发平台以及HASS中的和风天气集成,获取精准定位的天气情况

安装和风天气HASS集成

GitHub :https://github.com/c1pher-cn/heweather

GitHub页面自带流程故这里简述下

在HACS商店中搜索heweather,找到本插件并下载

配置和风天气

然后设置->设备与服务->添加集成->搜索heweather->选择本插件,同时建议使用JWT凭证,(API模式将在2027年废弃)。

Pasted image 20260606235005

将里面的公钥复制下来备用

注册和风天气并进入开发者平台

新建项目和凭证

凭证选择JWT并输入HASS中的凭据

Pasted image 20260606234547

然后就能在项目页面看到项目id和凭据id分别复制下来

Pasted image 20260606234950

再点击开发者页面的设置里面有API

Pasted image 20260606234957

将第一个页面填好后下一步

根据

国内的城市区域location、经纬度关系:

https://github.com/qwd/LocationList/blob/master/China-City-List-latest.csv

选择经纬度填进去

  1. 关注的自然灾害等级,1-6为从轻微到严重, 代表在灾害预警里你关注的灾害等级。

    “Standard”: “标准的”,

    “Minor”: “次要的”,

    “Moderate”: “中等的”,

    “Major”: “主要”,

    “Severe”: “严重”,

    “Extreme”: “极端”

    只显示标题即只在灾害预警text中透出灾害标题,显示标题+明细信息则会在text中透出全部信息(会比较长)

这样就可以看到实体了

一小时天气预警

在HASS的根目录修改configuration.yaml
加一行

1
template: !include templates.yaml

然后在根目录创建文件templates.yaml
填入

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# ==========================================
# 1. 一小时天气预警(触发型模板传感器)
# ==========================================
- sensor:
    - name: heweather_rain_warn
      unique_id: heweather_rain_warn
      state: >
        {# 依然读取实时中文,用来做状态的主分类判断 #}
        {% set weather_text = states('sensor.he_feng_tian_qi_heweather_text') %}
        
        {% if '雨' in weather_text or '雪' in weather_text or '雹' in weather_text %}
          下雨预警
        {% else %}
          关闭
        {% endif %}
      attributes:
        states: >
          {# 1. 获取当前和风天气的中文描述(例如:晴、多云、小雨) #}
          {% set weather_text = states('sensor.he_feng_tian_qi_heweather_text') %}
          
          {# 2. 完美复刻原作者的提示文字风格 #}
          {% if '雨' in weather_text or '雪' in weather_text or '雹' in weather_text %}
            接下来一小时会有{{ weather_text }},出门记得带伞
          {% else %}
            未来一小时,天气{{ weather_text }},没有降雨
          {% endif %}

然后设置-开发者工具-YAML-点击最上面的检查配置
如果是绿色代表成功点击右面的重启的第一个选项

然后就可以在设置-设备与服务-实体最下面看到heweather_rain_warn实体了

可以在首页卡片创建选择Markdown 卡片配置
输入

1
2
3
4
5
6
7

  <div style="display: flex; justify-content: space-between; align-items: flex-start;">
    <font color="#88" size="3">天气预警</font>
    <ha-icon icon="mdi:cloud-outline" style="color: #44739e;"></ha-icon>
  </div>
<font color="#88" size="5">{{ state_attr('sensor.heweather_rain_warn', 'states') }}</font>
 

灾害预警

添加单实体卡片添加和风天气里的警告实体,刚开始可能是英文就找warn三角图标的,后面可以自己改名

然后重点来了

卡片里面属性栏选择States才可以看到信息

Pasted image 20260607000012

天气卡片

在卡片里面找到天气预报选择和风天气然后自己选项配置一下

本博客已稳定运行
发表了86篇文章 · 总计80.83k字