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

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

[经验分享] 使用apexcharts-card图形化直观展示天气变化趋势

  [复制链接]

5

主题

67

帖子

427

积分

中级会员

Rank: 3Rank: 3

积分
427
金钱
360
HASS币
0
发表于 2023-2-14 17:19:28 | 显示全部楼层
看看楼主的介绍,谢谢!
回复

使用道具 举报

0

主题

18

帖子

115

积分

注册会员

Rank: 2

积分
115
金钱
97
HASS币
0
发表于 2023-2-14 17:36:30 | 显示全部楼层
学习看看怎么搞得。
回复

使用道具 举报

0

主题

18

帖子

115

积分

注册会员

Rank: 2

积分
115
金钱
97
HASS币
0
发表于 2023-2-14 19:40:43 | 显示全部楼层
本帖最后由 hass_0205 于 2023-2-15 10:40 编辑
zebradam 发表于 2023-1-29 17:18
谢大佬,我赶紧去试试看

大佬,我照这个方法改了还不行啊.
改了之后的代码:
Screenshot 2023-02-15 103706.png

生成的实体:

生成的实体

生成的实体


添加卡片时的提示:

3.png










改了之后的代码

改了之后的代码
回复

使用道具 举报

1

主题

44

帖子

242

积分

中级会员

Rank: 3Rank: 3

积分
242
金钱
198
HASS币
0
发表于 2023-2-15 08:10:51 | 显示全部楼层
hass_0205 发表于 2023-2-14 19:40
大佬,我照这个方法改了还不行啊.
改了之后的代码:

我也是。。。代码检查是没问题了,但不能显示
回复

使用道具 举报

0

主题

5

帖子

38

积分

新手上路

Rank: 1

积分
38
金钱
33
HASS币
0
发表于 2023-2-15 10:04:38 | 显示全部楼层
大神666,看看怎么操作的
回复

使用道具 举报

0

主题

18

帖子

115

积分

注册会员

Rank: 2

积分
115
金钱
97
HASS币
0
发表于 2023-2-15 10:34:05 | 显示全部楼层
    - unique_id: temp_hi_1d #明天最高温度
      name: >-
        明天{% if states('sensor.temp_hi_1d')|int < states('sensor.temp_hi')|int %}↘{% else %}↗{% endif %}{{ (states('sensor.temp_hi_1d')|int - states('sensor.temp_hi')|int)|abs }}
      state: "{{ states.sensor.weather_daily.attributes.daily[1]['tempMax'] }}"
      unit_of_measurement: °C
    - unique_id: temp_lo_1d #明天最低温度
      name: >-
        明天{% if states('sensor.temp_lo_1d')|int < states('sensor.temp_lo')|int %}↘{% else %}↗{% endif %}{{ (states('sensor.temp_lo_1d')|int - states('sensor.temp_lo')|int)|abs }}
      state: "{{ states.sensor.weather_daily.attributes.daily[1]['tempMin'] }}"
      unit_of_measurement: °C
就是这两段代码出错了,希望大佬指点。


回复

使用道具 举报

3

主题

150

帖子

3590

积分

论坛元老

Rank: 8Rank: 8

积分
3590
金钱
3435
HASS币
30
 楼主| 发表于 2023-2-15 17:09:50 | 显示全部楼层
本帖最后由 zmg 于 2023-2-15 17:20 编辑
hass_0205 发表于 2023-2-15 10:34
就是这两段代码出错了,希望大佬指点。

我没遇到过这个错误,你改成下面这种格式试一下呢:
sensor:
  - platform: template
    sensors:
      temp_hi_1d:
        friendly_name: >-
          ................................
        value_template: "............"
        unit_of_measurement: °C
      temp_lo_1d:
        friendly_name: >-
          ................................
        value_template: "............"
        unit_of_measurement: °C


回复

使用道具 举报

0

主题

18

帖子

115

积分

注册会员

Rank: 2

积分
115
金钱
97
HASS币
0
发表于 2023-2-15 23:55:22 | 显示全部楼层
zmg 发表于 2023-2-15 17:09
我没遇到过这个错误,你改成下面这种格式试一下呢:[md]
```
sensor:

多谢大佬指点。终于可以了。最后的代码如下,供有遇到同样问题的朋友参考。
sensor:
  - platform: rest
    resource: https://devapi.qweather.com/v7/weather/now?location=经度,纬度&key=YOUR_API_KEY
    scan_interval: 1800 #半小时更新一次天气数据
    name: weather_now #实时天气
    value_template: "{{ value_json['now']['text'] }}"
    json_attributes:
      - updateTime
      - now
  - platform: rest
    resource: https://devapi.qweather.com/v7/weather/3d?location=经度,纬度&key=YOUR_API_KEY
    scan_interval: 7200 #二小时更新一次天气数据
    name: weather_daily #3天预报
    value_template: "{{ value_json['daily'][0]['textDay'] }}"
    json_attributes:
      - updateTime
      - daily
  - platform: template
    sensors:
      temp_hi_1d:
        friendly_name: >- #明天最高温度
          明天{% if states('sensor.temp_hi_1d')|int < states('sensor.temp_hi')|int %}↘{% else %}↗{% endif %}{{ (states('sensor.temp_hi_1d')|int - states('sensor.temp_hi')|int)|abs }}
        value_template: "{{ states.sensor.weather_daily.attributes.daily[1]['tempMax'] }}"
        unit_of_measurement: °C
      temp_lo_1d:
        friendly_name: >- #明天最低温度
          明天{% if states('sensor.temp_lo_1d')|int < states('sensor.temp_lo')|int %}↘{% else %}↗{% endif %}{{ (states('sensor.temp_lo_1d')|int - states('sensor.temp_lo')|int)|abs }}
        value_template: "{{ states.sensor.weather_daily.attributes.daily[1]['tempMin'] }}"
        unit_of_measurement: °C

      
template:
  - sensor:
    - name: current_temperature #当前温度
      icon: 'mdi:thermometer'
      state: "{{ states.sensor.weather_now.attributes.now['temp'] }}"
      unit_of_measurement: °C
    - name: current_feelslike #当前体感温度
      icon: 'mdi:temperature-celsius'
      state: "{{ states.sensor.weather_now.attributes.now['feelsLike'] }}"
      unit_of_measurement: °C
    - name: temp_hi # 今天最高温度
      state: "{{ states.sensor.weather_daily.attributes.daily[0]['tempMax'] }}"
      unit_of_measurement: °C
    - name: temp_lo # 今天最低温度
      state: "{{ states.sensor.weather_daily.attributes.daily[0]['tempMin'] }}"
      unit_of_measurement: °C

    - name: wind_1d #明天风力
      state: "{{ (( states.sensor.weather_daily.attributes.daily[1]['windSpeedDay'] |int *1000/3600/0.835) ** (1/1.5)) | round(1) }}"
      unit_of_measurement: Bf
      # 风速(米/秒)转蒲福风级:Bf = ( windSpeed(m/s) / 0.835 ) ^ (1/1.5)
      # 参见:https://baike.baidu.com/item/%E8%92%B2%E7%A6%8F%E9%A3%8E%E7%BA%A7/2763752




回复

使用道具 举报

0

主题

12

帖子

166

积分

注册会员

Rank: 2

积分
166
金钱
154
HASS币
0
发表于 2023-2-16 12:21:59 | 显示全部楼层
收藏学习。。。。。。。。。。。。。
回复

使用道具 举报

0

主题

5

帖子

128

积分

注册会员

Rank: 2

积分
128
金钱
123
HASS币
0
发表于 2023-2-18 08:26:04 | 显示全部楼层
谢谢楼主的分享,学习学习
回复

使用道具 举报

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

本版积分规则

Archiver|手机版|小黑屋|Hassbian

GMT+8, 2024-4-29 18:39 , Processed in 0.058570 second(s), 32 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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