本帖最后由 aktifin 于 2019-3-1 09:57 编辑
以前一直用和风天气,最近Hass升级后老版本的不能用了,用了其他版本的和风天气一直觉得没有原来的数据全面,在论坛上看到了Yousm大神的内置rest版彩云天气(https://bbs.hassbian.com/forum.php?mod=viewthread&tid=2697),深受启发,这两天查阅了官方文档(https://home-assistant.io/components/sensor.rest/)和L大各种应用rest的帖子,终于实现了
无插件、可自定义的内置rest版和风天气
暂时我只获取了几个我需要的天气数据,理论上只要是天气json文件里的数据,在下面的template里都能添加进去,喜欢和风天气的大家尽情发挥吧
sensor文件代码如下:
- platform: rest
name: TodayWeather
resource: https去掉我://free-api.heweather.com/s6/weather?location=你的城市拼音&key=你的和风天气apikey
value_template: '{{ value_json["HeWeather6"][0]["now"]["cond_txt"].title() }}'
scan_interval: 1800 #半小时更新一次天气数据
json_attributes:
- HeWeather6
- platform: template
sensors:
today_weather:
friendly_name: Today Weather
value_template: '{{ states.sensor.TodayWeather.attributes.HeWeather6[0]["now"]["cond_txt"] }}'
today_temperature_now:
friendly_name: Today Temperature Now
value_template: '{{ states.sensor.TodayWeather.attributes.HeWeather6[0]["now"]["tmp"] }}'
unit_of_measurement: °C
today_temperature_max:
friendly_name: Today Temperature Max
value_template: '{{ states.sensor.TodayWeather.attributes.HeWeather6[0]["daily_forecast"][0]["tmp_max"] }}'
unit_of_measurement: °C
today_temperature_min:
friendly_name: Today Temperature Min
value_template: '{{ states.sensor.TodayWeather.attributes.HeWeather6[0]["daily_forecast"][0]["tmp_min"] }}'
unit_of_measurement: °C
today_humidity:
friendly_name: Today Humidity
value_template: '{{ states.sensor.TodayWeather.attributes.HeWeather6[0]["now"]["hum"] }}'
unit_of_measurement: '%'
today_rainfall_probability:
friendly_name: Today Rainfall Probability
value_template: '{{ states.sensor.TodayWeather.attributes.HeWeather6[0]["now"]["pcpn"] | round(0)}}'
unit_of_measurement: '%'
最后,将得到的天气数据自定义添加到了HADashboard里
|