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

 找回密码
 立即注册
楼主: anthonyhou

[进阶教程] 自定义传感器内容 | RSS | RESTful | 香港天文台【2020年3月】

  [复制链接]

0

主题

1

帖子

24

积分

新手上路

Rank: 1

积分
24
金钱
23
HASS币
0
发表于 2020-8-19 03:25:02 | 显示全部楼层
天文台更新了幾個數據集api
可以不用通過rss獲取了
樓主如果有興趣的話可以研究一下
Screenshot_20200819-032408.png
回复

使用道具 举报

1

主题

49

帖子

1106

积分

金牌会员

Rank: 6Rank: 6

积分
1106
金钱
1057
HASS币
0
发表于 2020-8-19 16:58:01 | 显示全部楼层
感謝樓主分享
回复

使用道具 举报

1

主题

49

帖子

1106

积分

金牌会员

Rank: 6Rank: 6

积分
1106
金钱
1057
HASS币
0
发表于 2020-8-20 13:55:56 | 显示全部楼层
本帖最后由 meditation 于 2020-8-20 14:20 编辑
  - platform: rest
    name: local_weather_fnd
    resource: https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=fnd&lang=tc
    scan_interval: 1200
    value_template: '{{ value_json.generalSituation }}'
    json_attributes:
      - generalSituation
      - weatherForecast

  - platform: template
    sensors:
      weather_forecast_0_date:
        friendly_name: "Tomorrow Day"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[0].forecastDate }}"
        unit_of_measurement: ''       
      weather_forecast_0_week:
        friendly_name: "Tomorrow Week"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[0].week }}"
        unit_of_measurement: ''     
      weather_forecast_0_weather:
        friendly_name: "Tomorrow Weather"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[0].forecastWeather }}"
        unit_of_measurement: ''     
      weather_forecast_0_max_temp:
        friendly_name: "Tomorrow Max Temperature"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[0].forecastMaxtemp.value }}"
        unit_of_measurement: '°C'
      weather_forecast_0_min_temp:
        friendly_name: "Tomorrow Min Temperature"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[0].forecastMintemp.value }}"
        unit_of_measurement: '°C'
      weather_forecast_0_max_rh:
        friendly_name: "Tomorrow Max Relative Humidity"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[0].forecastMaxrh.value }}"
        unit_of_measurement: '%'
      weather_forecast_0_min_rh:
        friendly_name: "Tomorrow Min Relative Humidity"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[0].forecastMinrh.value }}"
        unit_of_measurement: '%'   
      weather_forecast_1_date:
        friendly_name: "Nextday Day"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[1].forecastDate }}"
        unit_of_measurement: ''       
      weather_forecast_1_week:
        friendly_name: "Nextday Week"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[1].week }}"
        unit_of_measurement: ''     
      weather_forecast_1_weather:
        friendly_name: "Nextday Weather"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[1].forecastWeather }}"
        unit_of_measurement: ''     
      weather_forecast_1_max_temp:
        friendly_name: "Nextday Max Temperature"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[1].forecastMaxtemp.value }}"
        unit_of_measurement: '°C'
      weather_forecast_1_min_temp:
        friendly_name: "Nextday Min Temperature"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[1].forecastMintemp.value }}"
        unit_of_measurement: '°C'
      weather_forecast_1_max_rh:
        friendly_name: "Nextday Max Relative Humidity"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[1].forecastMaxrh.value }}"
        unit_of_measurement: '%'
      weather_forecast_1_min_rh:
        friendly_name: "Nextday Min Relative Humidity"
        value_template: "{{ state_attr('sensor.local_weather_fnd', 'weatherForecast')[1].forecastMinrh.value }}"
        unit_of_measurement: '%'

评分

参与人数 3金钱 +3 收起 理由
AngelHeart + 1 感謝樓主分享!
duxing0626 + 1 感谢楼主分享!
hung2k + 1 感谢楼主分享!

查看全部评分

回复

使用道具 举报

0

主题

23

帖子

182

积分

注册会员

Rank: 2

积分
182
金钱
159
HASS币
0
发表于 2020-8-20 14:03:23 | 显示全部楼层
对这个自定义传感器很感兴趣,希望可以有更多类似的功能
回复

使用道具 举报

0

主题

9

帖子

741

积分

高级会员

Rank: 4

积分
741
金钱
732
HASS币
0
发表于 2021-3-15 22:28:25 | 显示全部楼层
請教下 HA 2021.3 新增了天氣模板可以自定義天氣預報提供者
但香港天文台 api 預報的 json 跟 HA 所需的格式有點出入
有辦法通過修改後使用嗎?

天文台的 JSON 格式
[
  {
    "forecastDate": "20210316",
    "week": "星期二",
    "forecastWind": "東風3至4級。",
    "forecastWeather": "大致天晴。",
    "forecastMaxtemp": {
      "value": 27,
      "unit": "C"
    },
    "forecastMintemp": {
      "value": 20,
      "unit": "C"
    },
    "forecastMaxrh": {
      "value": 90,
      "unit": "percent"
    },
    "forecastMinrh": {
      "value": 65,
      "unit": "percent"
    },
    "ForecastIcon": 51
  },
  {
    "forecastDate": "20210317",
    "week": "星期三",
    "forecastWind": "東風3級。",
    "forecastWeather": "部分時間有陽光。早晚沿岸有薄霧。",
    "forecastMaxtemp": {
      "value": 26,
      "unit": "C"
    },
    "forecastMintemp": {
      "value": 21,
      "unit": "C"
    },
    "forecastMaxrh": {
      "value": 95,
      "unit": "percent"
    },
    "forecastMinrh": {
      "value": 75,
      "unit": "percent"
    },
    "ForecastIcon": 51
  }
]

HA 天氣預報的格式
[
  {
    "datetime": "2021-03-15T04:00:00+00:00",
    "precipitation": null,
    "pressure": 1016,
    "wind_speed": 3.82,
    "wind_bearing": 105,
    "condition": "cloudy",
    "temperature": 23.6,
    "templow": 20.3
  },
  {
    "datetime": "2021-03-16T04:00:00+00:00",
    "precipitation": null,
    "pressure": 1015,
    "wind_speed": 2.56,
    "wind_bearing": 97,
    "condition": "cloudy",
    "temperature": 25.6,
    "templow": 20.9
  }
]

回复

使用道具 举报

8

主题

149

帖子

2694

积分

金牌会员

Rank: 6Rank: 6

积分
2694
金钱
2540
HASS币
30
 楼主| 发表于 2021-3-16 16:29:37 | 显示全部楼层
hung2k 发表于 2021-3-15 22:28
請教下 HA 2021.3 新增了天氣模板可以自定義天氣預報提供者
但香港天文台 api 預報的 json 跟 HA 所需的格 ...

我觉得要通过自定义插件实现
回复

使用道具 举报

0

主题

9

帖子

741

积分

高级会员

Rank: 4

积分
741
金钱
732
HASS币
0
发表于 2021-3-16 22:28:32 | 显示全部楼层
anthonyhou 发表于 2021-3-16 16:29
我觉得要通过自定义插件实现

大神有空可以弄成插件嗎?
小白不懂python實在弄不了
回复

使用道具 举报

8

主题

149

帖子

2694

积分

金牌会员

Rank: 6Rank: 6

积分
2694
金钱
2540
HASS币
30
 楼主| 发表于 2021-3-20 20:28:38 | 显示全部楼层
hung2k 发表于 2021-3-16 22:28
大神有空可以弄成插件嗎?
小白不懂python實在弄不了

我也是小白,等我研究研究插件先
回复

使用道具 举报

0

主题

3

帖子

48

积分

新手上路

Rank: 1

积分
48
金钱
45
HASS币
0
发表于 2021-6-4 16:07:57 | 显示全部楼层

謝謝分享
回复

使用道具 举报

0

主题

44

帖子

325

积分

中级会员

Rank: 3Rank: 3

积分
325
金钱
281
HASS币
0
发表于 2021-9-27 18:13:17 | 显示全部楼层

請問這個是什麼用? 把它寫到"configuration.yaml"?
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-5-3 17:24 , Processed in 0.062612 second(s), 33 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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