Home Assistant中显示最新油价信息

本文介绍如何在Home Assistant中安装并配置一个用于显示各地油价信息的自定义组件。该组件通过抓取指定网站的数据来获取最新的汽油价格,并能在Home Assistant的界面上直观展示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

说明:

本内容仅作为学习分享,原文链接(https://bbs.hassbian.com/thread-8088-1-1.html),如有侵权请联系删除!

本项目通过抓取http://www.qiyoujiage.com上的油价信息,显示在Home Assistant上

配置过程

1.下载项目

链接:https://github.com/aalavender/OilPrice

2.文件配置

下载解压后,如果Home Assistant的系统文件中,config目录下没有custom_components这个文件夹,那就新建那么一个文件夹

将下载解压后的custom_components目录的oilprice文件夹及里面的文件,拷贝到Home Assistant系统custom_components目录下

3.configuration.yaml配置

使用nodepad++或其他工具打开configuration.yaml

在里面添加以下代码

sensor:
  - platform: oilprice
    name: 最新油价
    region: guangxi

如下图所示:

4.重启系统

检查配置->重启系统

重启后,在概要中,去编辑仪表盘

选择Markdown,选择【显示代码编辑器】

复制以下代码粘贴

type: markdown
content: >
  <ha-icon icon="mdi:update"></ha-icon> {{ state_attr('sensor.zui_xin_you_jie',
  'update_time')}} 

  ##  <center>92#<ha-icon icon="mdi:gas-station"></ha-icon>  <font
  color=#ea4335> {{ state_attr('sensor.zui_xin_you_jie', '92')}} </font>&nbsp;
  &nbsp; &nbsp;  &nbsp;  &nbsp;  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  &nbsp;95# <ha-icon icon="mdi:gas-station"></ha-icon>  <font color=#fbbc05>  {{
  state_attr('sensor.zui_xin_you_jie', '95')}} </font> <p> 98# <ha-icon
  icon="mdi:gas-station"></ha-icon> <font color=#4285f4>  {{
  state_attr('sensor.zui_xin_you_jie', '98')}}</font>&nbsp;  &nbsp;  &nbsp; 
  &nbsp;  &nbsp;  &nbsp;  &nbsp; 0#柴油<ha-icon icon="mdi:gas-station"></ha-icon>
  <font color=#34a853>  {{ state_attr('sensor.zui_xin_you_jie', '0')}}
  </font></center> 

  - {{ states('sensor.zui_xin_you_jie') }} 

  - {{ state_attr('sensor.zui_xin_you_jie', 'tips')}}

就能看到效果了!

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值