『瀚思彼岸』» 智能家居技术论坛

 找回密码
 立即注册
查看: 13476|回复: 41

[基础教程] HASS集成互联网天气

[复制链接]

2

主题

239

帖子

817

积分

高级会员

Rank: 4

积分
817
金钱
573
HASS币
20
发表于 2021-6-25 15:53:40 | 显示全部楼层 |阅读模式
本帖最后由 jack9603301 于 2021-6-27 23:04 编辑

在我们使用Home Assistant的过程中,往往希望获取天气数据,而互联网天气,成为了第一种选择,本文就告诉大家如何集成互联网天气,这次我们使用HeWeather

集成

按照如下命令安装:

cd /etc/hass
cd custom_components
git clone https://github.com/morestart/HeWeather

先在https://wx.jdcloud.com/market/datas/26/10610或者https://where.heweather.com申请appkey,然后在https://where.heweather.com找到你的城市代码,CN开头的字符串。

修改/etc/hass/configuration.yaml:

sensor:
  - platform: HeWeather
    city: "佛山"
    appkey: <appkey>    

    options:
      - fl
      - tmp
      - cond_txt
      - wind_spd
      - hum
      - pcpn
      - pres
      - vis
      - wind_sc
      - aqi
      - main
      - qlty
      - pm10
      - pm25
      - comf
      - cw
      - drsg
      - flu
      - sport
      - trav
      - uv
      - wind_dir
      - tmp_max
      - tmp_min
      - pop

使用以下命令重启hass:

systemctl restart hass

设置仪表盘

通过配置->lovelace仪表盘->添加仪表盘添加天气仪表盘,进入天气选项卡,使用如下仪表盘配置:

background: var(--background-image)
views:
  - title: 天气
    path: weather
    icon: mdi:weather-cloudy
    badges: []
    cards:
      - type: glance
        entities:
          - sensor.zhu_yao_wu_ran_wu
          - sensor.chu_xing_zhi_shu
          - sensor.tian_qi_zhuang_tai
          - sensor.gan_mou_zhi_shu
          - sensor.xi_che_zhi_shu
          - sensor.zi_wai_xian_zhi_shu
          - sensor.chuan_yi_zhi_shu
          - sensor.kong_qi_zhi_liang
          - sensor.shu_gua_du_zhi_shu
      - type: sensor
        entity: sensor.da_qi_ya
        graph: line
        detail: 2
      - type: sensor
        entity: sensor.feng_su
        graph: line
        detail: 2
      - type: gauge
        entity: sensor.jiang_shui_gai_lu
      - type: sensor
        entity: sensor.jiang_shui_liang
        graph: line
        detail: 2
      - type: sensor
        entity: sensor.jin_ri_zui_di_wen_du
        graph: line
        detail: 2
      - type: sensor
        entity: sensor.jin_ri_zui_gao_wen_du
        graph: line
        detail: 2
      - type: sensor
        entity: sensor.kong_qi_zhi_liang_zhi_shu
        graph: line
        detail: 2
      - type: sensor
        entity: sensor.neng_jian_du
        graph: line
        detail: 2
      - type: gauge
        entity: sensor.shi_shi_shi_wai_shi_du
      - type: sensor
        entity: sensor.shi_shi_shi_wai_wen_du
        graph: line
        detail: 2
      - type: sensor
        entity: sensor.shi_shi_ti_gan_wen_du
        graph: line
        detail: 2
      - type: sensor
        entity: sensor.pm10
        graph: line
        detail: 2
      - type: sensor
        entity: sensor.pm2_5
        graph: line
        detail: 2
title: 天气

天气仪表盘

配置NODERED

对于使用了NODE-RED和小爱对接的,可以导入以下仪表盘:

[
    {
        "id": "693cee39.d45af",
        "type": "tab",
        "label": "温度",
        "disabled": false,
        "info": ""
    },
    {
        "id": "f18452d2.92aec",
        "type": "server-state-changed",
        "z": "693cee39.d45af",
        "name": "湿度",
        "server": "3c87f99d.1fa9b6",
        "version": 3,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "sensor.shi_shi_shi_wai_shi_du",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 170,
        "y": 160,
        "wires": [
            [
                "1d1653b7.db4eec"
            ]
        ]
    },
    {
        "id": "8659849e.4aefe",
        "type": "server-state-changed",
        "z": "693cee39.d45af",
        "name": "温度",
        "server": "3c87f99d.1fa9b6",
        "version": 3,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "sensor.shi_shi_shi_wai_wen_du",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 170,
        "y": 240,
        "wires": [
            [
                "1d1653b7.db4eec"
            ]
        ]
    },
    {
        "id": "1d1653b7.db4eec",
        "type": "api-current-state",
        "z": "693cee39.d45af",
        "name": "查询温度",
        "server": "3c87f99d.1fa9b6",
        "version": 2,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "sensor.shi_shi_shi_wai_wen_du",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 420,
        "y": 200,
        "wires": [
            [
                "47d64f14.57fbe8"
            ]
        ]
    },
    {
        "id": "47d64f14.57fbe8",
        "type": "change",
        "z": "693cee39.d45af",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "temp",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 650,
        "y": 200,
        "wires": [
            [
                "82e1cc.a13f4638"
            ]
        ]
    },
    {
        "id": "82e1cc.a13f4638",
        "type": "api-current-state",
        "z": "693cee39.d45af",
        "name": "查询湿度",
        "server": "3c87f99d.1fa9b6",
        "version": 2,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "sensor.shi_shi_shi_wai_shi_du",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 860,
        "y": 200,
        "wires": [
            [
                "311016f7.c10e4a"
            ]
        ]
    },
    {
        "id": "311016f7.c10e4a",
        "type": "change",
        "z": "693cee39.d45af",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "humidity",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1090,
        "y": 200,
        "wires": [
            [
                "8fbfbf31.dc93d8"
            ]
        ]
    },
    {
        "id": "d49bc6b.0863cb8",
        "type": "template",
        "z": "693cee39.d45af",
        "name": "设置数据格式",
        "field": "payload",
        "fieldType": "msg",
        "format": "handlebars",
        "syntax": "mustache",
        "template": "#{{ temp }}#{{ humidity }}#1#{{ pm2.5 }}#{{ qiya }}#",
        "output": "str",
        "x": 440,
        "y": 460,
        "wires": [
            [
                "57608fc0.8cb2e"
            ]
        ]
    },
    {
        "id": "57608fc0.8cb2e",
        "type": "mqtt out",
        "z": "693cee39.d45af",
        "name": "上传数据",
        "topic": "temp004",
        "qos": "0",
        "retain": "false",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "dd5ff2b3.26398",
        "x": 740,
        "y": 460,
        "wires": []
    },
    {
        "id": "8544faf3.aa2478",
        "type": "server-state-changed",
        "z": "693cee39.d45af",
        "name": "PM2.5",
        "server": "3c87f99d.1fa9b6",
        "version": 3,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "sensor.pm2_5",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 170,
        "y": 340,
        "wires": [
            [
                "1d1653b7.db4eec"
            ]
        ]
    },
    {
        "id": "8fbfbf31.dc93d8",
        "type": "api-current-state",
        "z": "693cee39.d45af",
        "name": "查询PM2.5",
        "server": "3c87f99d.1fa9b6",
        "version": 2,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "sensor.pm2_5",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 430,
        "y": 340,
        "wires": [
            [
                "6bff3829.08cf5"
            ]
        ]
    },
    {
        "id": "6bff3829.08cf5",
        "type": "change",
        "z": "693cee39.d45af",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "pm2.5",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 660,
        "y": 340,
        "wires": [
            [
                "24f97475.de2e9c"
            ]
        ]
    },
    {
        "id": "24f97475.de2e9c",
        "type": "api-current-state",
        "z": "693cee39.d45af",
        "name": "查询气压",
        "server": "3c87f99d.1fa9b6",
        "version": 2,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "sensor.da_qi_ya",
        "state_type": "str",
        "blockInputOverrides": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 900,
        "y": 340,
        "wires": [
            [
                "be856cb.b3c469"
            ]
        ]
    },
    {
        "id": "be856cb.b3c469",
        "type": "change",
        "z": "693cee39.d45af",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "qiya",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1120,
        "y": 340,
        "wires": [
            [
                "d49bc6b.0863cb8"
            ]
        ]
    },
    {
        "id": "a030aed2.d9ba78",
        "type": "server-state-changed",
        "z": "693cee39.d45af",
        "name": "大气压",
        "server": "3c87f99d.1fa9b6",
        "version": 3,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "sensor.da_qi_ya",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": true,
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 170,
        "y": 440,
        "wires": [
            [
                "1d1653b7.db4eec"
            ]
        ]
    },
    {
        "id": "3c87f99d.1fa9b6",
        "type": "server",
        "name": "Home Assistant",
        "version": 1,
        "legacy": false,
        "addon": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true
    },
    {
        "id": "dd5ff2b3.26398",
        "type": "mqtt-broker",
        "name": "Remote MQTT",
        "broker": "bemfa.com",
        "port": "9501",
        "clientid": "7ca62f668da56fafbbafa04dbfe42a5f",
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "sessionExpiry": ""
    }
]

流程效果图:
流程图




回复

使用道具 举报

32

主题

2010

帖子

5130

积分

论坛元老

Rank: 8Rank: 8

积分
5130
金钱
3120
HASS币
50
QQ
发表于 2021-6-25 18:26:04 | 显示全部楼层
谢谢分享,学习一下
我不生产技术,我只是技术的搬运工。
回复

使用道具 举报

1

主题

189

帖子

1931

积分

金牌会员

Rank: 6Rank: 6

积分
1931
金钱
1742
HASS币
0
发表于 2021-6-25 23:13:44 | 显示全部楼层
值得关注
回复

使用道具 举报

0

主题

4

帖子

12

积分

新手上路

Rank: 1

积分
12
金钱
8
HASS币
0
发表于 2021-7-8 14:20:10 | 显示全部楼层
请问你的ha 版本是多少的,我的2021.6.6版本加载heweather插件报错,提示Platform error sensor.HeWeather - Integration 'HeWeather' not found.求答案
回复

使用道具 举报

2

主题

239

帖子

817

积分

高级会员

Rank: 4

积分
817
金钱
573
HASS币
20
 楼主| 发表于 2021-7-8 19:04:07 | 显示全部楼层
本帖最后由 jack9603301 于 2021-7-8 19:11 编辑
simplezhang 发表于 2021-7-8 14:20
请问你的ha 版本是多少的,我的2021.6.6版本加载heweather插件报错,提示Platform error sensor.HeWeather  ...

最新版本,你这个版本应该可以。可能是放置位置错了

/etc/hass/
├── automations.yaml
├── blueprints
│   ├── automation
│   └── script
├── configuration.yaml
├── conversation
├── custom_components
│   ├── HeWeather
├── deps
│   ├── bin
│   ├── include
│   ├── lib
│   └── share
├── groups.yaml
├── home-assistant_v2.db
├── home-assistant_v2.db-shm
├── home-assistant_v2.db-wal
├── known_devices.yaml
├── media
│   ├── media.md
│   ├── node-red.svg
│   ├── shot1.png
│   └── shot2.png
├── node_modules
├── panels
│   └── inkwavemap.html
├── scenes.yaml
├── scripts.yaml
├── secrets.yaml
├── shell_scripts
│   └── hpzbook-15-poweroff.sh
├── templates.yaml
├── tts
├── ui-lovelace.yaml
回复

使用道具 举报

28

主题

360

帖子

2031

积分

金牌会员

Rank: 6Rank: 6

积分
2031
金钱
1671
HASS币
0
发表于 2021-7-8 23:49:54 | 显示全部楼层
  git clone https://github.com/morestart/HeWeather 这个命令执行之后出现ents
-ash: cd: custom_components: No such file or directory
这个提示 去github项目把文件下载解压放置config\custom_components\HeWeather下重启ha
appkey也申请了 地址是北京(汉字) 重启ha之后无数据
回复

使用道具 举报

28

主题

360

帖子

2031

积分

金牌会员

Rank: 6Rank: 6

积分
2031
金钱
1671
HASS币
0
发表于 2021-7-8 23:51:38 | 显示全部楼层
  git clone https://github.com/morestart/HeWeather 这个命令执行之后出现ents
-ash: cd: custom_components: No such file or directory
这个提示 去github项目把文件下载解压放置config\custom_components\HeWeather下重启ha
appkey也申请了 地址是北京(汉字) 重启ha之后无数据
微信截图_20210708234827.png
回复

使用道具 举报

28

主题

360

帖子

2031

积分

金牌会员

Rank: 6Rank: 6

积分
2031
金钱
1671
HASS币
0
发表于 2021-7-8 23:52:45 | 显示全部楼层
项目中这句 在sensor文件夹下放入HeWeather.py文件,此版本文件支持0.63以上HA。这个文件夹在哪里
回复

使用道具 举报

2

主题

239

帖子

817

积分

高级会员

Rank: 4

积分
817
金钱
573
HASS币
20
 楼主| 发表于 2021-7-10 15:11:53 | 显示全部楼层
郑凯强 发表于 2021-7-8 23:52
项目中这句 在sensor文件夹下放入HeWeather.py文件,此版本文件支持0.63以上HA。这个文件夹在哪里 ...

在HASS配置文件夹内,一般安装了HACS就有这个文件夹了,如果没有,自己创建一个就行
回复

使用道具 举报

2

主题

239

帖子

817

积分

高级会员

Rank: 4

积分
817
金钱
573
HASS币
20
 楼主| 发表于 2021-7-10 15:13:04 | 显示全部楼层
郑凯强 发表于 2021-7-8 23:51
git clone https://github.com/morestart/HeWeather 这个命令执行之后出现ents
-ash: cd: custom_compone ...

你已经在custom_compone了,还cd肯定找不到阿
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-8 18:35 , Processed in 0.112249 second(s), 41 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表