本帖最后由 Yonsm 于 2018-2-4 22:11 编辑
最简单的版本是直接利用 HA 内置的 rest+template sensor:
1. 复制如下配置到你的 comfiguration.yaml 的 sensor: 下面;
2. 修改经纬度“120.000,30.000”为你的经纬度;
3. 可选:在customize.yaml 中把 sensor.outside 设置为 hidden: true,并且重新命名各项指标。
sensor:
- platform: rest
name: Outside
resource: http://api.caiyunapp.com/v2/UR8ASaplvIwavDfR/120.000,30.000/realtime.json
scan_interval: 1200
headers:
User-Agent: ColorfulCloudsPro/3.2.0 (iPhone; iOS 11.2.2; Scale/2.00)
value_template: >-
{% if value_json.status == 'ok' %}
有效
{% else %}
无效
{% endif %}
json_attributes:
- result
- platform: template
sensors:
outside_weather:
friendly_name: Outside Weather
value_template: >-
{% set skycon = states.sensor.outside.attributes.result.skycon %}
{% if skycon == 'CLEAR_DAY' %}
晴天
{% elif skycon == 'CLEAR_NIGHT' %}
晴夜
{% elif skycon == 'PARTLY_CLOUDY_DAY' %}
多云
{% elif skycon == 'PARTLY_CLOUDY_NIGHT' %}
多云
{% elif skycon == 'CLOUDY' %}
阴
{% elif skycon == 'RAIN' %}
雨
{% elif skycon == 'SNOW' %}
雪
{% elif skycon == 'WIND' %}
风
{% elif skycon == 'FOG' %}
雾
{% elif skycon == 'HAZE' %}
霾
{% elif skycon == 'SLEET' %}
冻雨
{% else %}
未知
{% endif %}
icon_template: >-
{% set skycon = states.sensor.outside.attributes.result.skycon %}
{% if skycon == 'CLEAR_DAY' %}
mdi:weather-sunny
{% elif skycon == 'CLEAR_NIGHT' %}
mdi:weather-night
{% elif skycon == 'PARTLY_CLOUDY_DAY' %}
mdi:weather-partlycloudy
{% elif skycon == 'PARTLY_CLOUDY_NIGHT' %}
mdi:weather-windy-variant
{% elif skycon == 'CLOUDY' %}
mdi:weather-cloudy
{% elif skycon == 'RAIN' %}
mdi:weather-rainy
{% elif skycon == 'SNOW' %}
mdi:weather-snowy
{% elif skycon == 'WIND' %}
mdi:weather-windy
{% elif skycon == 'FOG' %}
mdi:weather-fog
{% elif skycon == 'HAZE' %}
mdi:weather-hail
{% elif skycon == 'SLEET' %}
mdi:weather-snowy-rainy
{% else %}
mdi:help-circle-outline
{% endif %}
outside_temperature:
friendly_name: Outside Temperature
value_template: '{{ states.sensor.outside.attributes.result.temperature }}'
unit_of_measurement: °C
outside_humidity:
friendly_name: Outside Humidity
value_template: '{{ states.sensor.outside.attributes.result.humidity | multiply(100) | round(0) }}'
unit_of_measurement: '%'
outside_pm25:
friendly_name: Outside PM2.5
value_template: '{{ states.sensor.outside.attributes.result.pm25 | round(0) }}'
unit_of_measurement: ug/m3
outside_aqi:
friendly_name: Outside AQI
value_template: '{{ states.sensor.outside.attributes.result.aqi | round(0) }}'
rainfall_intensity:
friendly_name: Rainfall Intensity
value_template: '{{ states.sensor.outside.attributes.result.precipitation.local.intensity | round(2)}}'
|