roc227 发表于 2023-5-9 01:00:20

如何读取某个实体属性中的数值

请教各位大神,我想调用和风天气中的次日最高/最低温度,但这个温度在实体中是以日期中的形式出现,有什么办法能调用这个数值
比如2023-05-09中的temperature: 19和templow: 6
这个日期还是每天都在变化

weather.localweather实体的属性如下temperature: 8
temperature_unit: °C
humidity: 37
pressure: 980
pressure_unit: hPa
wind_bearing: 南风
wind_speed: 5
wind_speed_unit: km/h
visibility: 0
visibility_unit: km
precipitation_unit: mm
forecast:
- datetime: '2023-05-09T00:53:22.559211'
    condition: sunny
    temperature: 19
    templow: 6
- datetime: '2023-05-10T00:53:22.559211'
    condition: cloudy
    temperature: 18
    templow: 5

gx19970920 发表于 2023-5-9 08:37:55

可以参考我写的这一个教程试一下
分享下将实体的属性独立成一个新实体的放
https://bbs.hassbian.com/thread-19884-1-1.html
(出处: 『瀚思彼岸』» 智能家居技术论坛)

shayulei 发表于 2023-5-9 08:49:28

在模板的yaml文件里写,下面是我从天气里提取的。
- sensor :
    - name: "Max temperature"
      unit_of_measurement: "°C"
      state: '{{state_attr("weather.sha_yu_lei_de_jia", "forecast").temperature}}'

    - name: "Low temperature"
      unit_of_measurement: "°C"
      state: '{{state_attr("weather.sha_yu_lei_de_jia", "forecast"). templow}}'

shayulei 发表于 2023-5-9 08:51:54

在configuration.yaml里写上template: !include templates.yaml,然后就是在同级目录下生成一个叫templates.yaml的文件,在文件里编辑,我感觉这样写清楚一些。当然也可以写在configuration.yaml里

bugensui 发表于 2023-5-9 11:17:16

shayulei 发表于 2023-5-9 08:51
在configuration.yaml里写上template: !include templates.yaml,然后就是在同级目录下生成一个叫templates ...

这样分开写的区别在哪里,有什么好处呢

zheng1112 发表于 2023-5-9 11:35:29

本帖最后由 zheng1112 于 2023-5-9 11:37 编辑

这个题我会。
{{ states.weather.localweather.attributes.forecast.templow }}~{{ states.weather.localweather.attributes.forecast.temperature }}°C


book123 发表于 2023-5-9 12:14:17

在esphome里面是这样:

# 室外空气质量-彩云天气
sensor:
- platform: homeassistant
    id: outside_aqi_caiyun
    entity_id: weather.wo_de_jia_nas12vm
    attribute: aqi
    internal: true

cjnt007 发表于 2023-5-9 13:44:56

zheng1112 发表于 2023-5-9 11:35
这个题我会。
{{ states.weather.localweather.attributes.forecast.templow }}~{{ states.weather.loca ...

6楼正解!
我是通过chatGPT查询也是同样的答案:lol

xiaoxihu 发表于 2023-5-9 14:36:26

这个真的实用,正需要啊

roc227 发表于 2023-5-10 00:07:43

shayulei 发表于 2023-5-9 08:49
在模板的yaml文件里写,下面是我从天气里提取的。
- sensor :
    - name: "Max temperature"


感谢感谢!稍微动了点,也能用了
页: [1] 2
查看完整版本: 如何读取某个实体属性中的数值