树莓派 智能家居DIY的乐趣开始配置homeassistant
大家好经过之前对homeassistant的认识、再到安装架设homeassistant系统,今天我笔者带大家对homeassistant进行配置为了让大家可以更上进度所以我一步步叫大家开始配置homeassistant。
昨天大家都知道了homeassistant的主要配置文件是configuration.yaml文件位于homeassistant安装目录下。
当我们第一次启动homeassistant时,homeassistant会自动创建一个名为configuration.yaml默认的设置文件,这个configuration.yaml文件是用YAML写的。YAML是"另一种标记语言"的外语缩写,它是一种直观的能够被电脑识别的数据序列化格式,是一个可读性高并且容易被人类阅读,容易和脚本语言交互,用来表达资料序列的编程语言。不要被这种语言吓到,其实很简单的。YAML最基本的语法就是集合和键值对。在一个集合每个子项都以短横线"-"开始,而键值对则有这样的格式"键:值"。注意:缩进是YAML定义各项之间关系很重要的手段。缩进相同的项,他们拥有相同的层级。制表符在YAML语言中是不可以用于缩进的,通常两层级间我们都采用缩进两个空格来表达。下面我们举个栗子一看就懂了。
介绍完YAML简单的语法,我们就可以开始进行设置我们的homeassistant了。我们先进行基础设置。通常homeassitant会根据你的IP地址自动判断你的位置,然后根据定位自动选择温度单位和时区,你可以在configuration.yaml文件中对这些进行重设。
下面为大家展示的是使用经纬度来确定自己实际所在的位置(注意经纬度的格式)
Name可以自定义你的homeassistant系统的名称这个根据个人喜好命名。
Latitude、longitude经纬度如何查询,请自行搜索"经纬度"然后在地图中找到自己的位置并查看经纬度然后填写在上图位置。
Elevation海拔会影响天气和日出时间,其实就是你所在地区距离海平面的高度请自行查询。
我这里贴出一张configuration.yaml文件的中文注释方便大家了解
-----------------------------------
homeassistant:
# Name of the location where Home Assistant is running
# 智能家居系统的名字,显示在主界面顶部。
name: 我的智能豪宅
# Location required to calculate the time the sun rises and sets
# 下面填入纬度和经度,计算太阳升起和设定时间所需位置,越精确越好。
latitude: 36.85201
longitude: 116.225287
# Impacts weather/sunrise data (altitude above sea level in meters)
# 海拔高度用于修正天气参数和日出日落时间参数 (默认单位是:米)。
elevation: 31
# metric for Metric, imperial for Imperial
# 度量衡单位制式(metric)是公制,(imperial)是英制。
unit_system: metric
# Pick yours from here:
# 时区,默认北京时间。
time_zone: Asia/Shanghai
customize: !include customize.yaml
# 测试任何您更改的配置文件,在命令行中用hass --script check_config。这个脚本可以让你测试的变化而不需要重新启动家庭助理。
# Show links to resources in log and frontend
# 在网页界面的首页显示简介 (那一大段英文)不想看到的话,请在前面加上#号。
#introduction:
# Enables the frontend
# 是否使用默认的“首页”
frontend:
# Enables configuration UI
# 自定义配置UI
config:
http:
# Uncomment this to add a password (recommended!)
# 给系统网页的登录加上一个密码,先去掉下面这行的#号,然后把PASSWORD改成你想要的密码。
# api_password:
# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# base_url: example.duckdns.org:8123
# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
updater:
# Optional, allows Home Assistant developers to focus on popular components.
# 升级提示,当 HomeAssitant 有新版本发布的时候,“日出日落”图标会变成(Updater)字样
# include_used_components: true
# Discover some devices automatically
# 系统自动发现新的设备
discovery:
# Allows you to issue voice commands from the frontend in enabled browsers
# 启动浏览器的语音命令
conversation:
# Enables support for tracking state changes over time
# 在系统数据库中保存“历史数据”
history:
# View all events in a logbook
# 在logbook显示所有事件
logbook:
# receive from broadlink开启博联日志
logger:
default: critical
logs:
homeassistant.components.switch.broadlink: info
# Track the sun
# 太阳“跟踪器” 也就是“日出日落时间”
#sun:
panel_iframe:
#添加HA侧边面板
designicons:
# Text to speech
# 文字转换语音
tts:
- platform: google
# 播放器
media_player:
# - platform:
# host:
device_tracker:
- platform: xiaomi
host: 192.168.31.1
username: admin
password: '**************'#这个不用我说了吧,换成自己的
track_new_devices : 1
#If new discovered devices are tracked by default
#跟踪新设备的添加,默认true
interval_seconds : 12
#Seconds between each scan for new devices
#扫描每个设备的间隔
consider_home : 180
#Seconds to wait till marking someone as not home after not being seen.
#This parameter is most useful for households with Apple iOS devices that go into sleep mode while still at home to conserve battery life.
#iPhones will occasionally drop off the network and then re-appear.
#It helps prevent false alarms in presence detection when using IP scanners such as Nmap.
#Accepts various time representations, (E.g. the following all represents 3 minutes:180,0:03,0:03:00)
#在设定秒数之后追踪不到某个设备,设置为不在家
#这个参数对于那些在家时进入睡眠模式的苹果iOS设备非常有用,以节省电池寿命。
#iPhone偶尔会脱离网络,然后重新出现。在使用IP扫描器如Nmap进行检测时有助于防止误报。
#接受各种时间表示(例如,以下代表3分钟:180,0:03,0:03:00)
# 下面这个区域,用于自定义设备属性
switch: !include switchs.yaml
group: !include groups.yaml
automation: !include automations.yaml
sensor: !include sensors.yaml
--------------------------------
下面为大家配置最基本的天气插件先让homeassistant展示出它的威力:
第一次登陆到homeassistant大家看到的界面是这样的
我们今天以之前树莓派刷机的镜像系统安装结果为准配置homeassistant,因为其自带了samba服务,所以现在只需要在资源管理器中直接输入homeassistant的IP地址就行如(\\192.168.3.52)回车然后输入树莓派的用户名和密码可以看到pi的主文件夹点击进入就可以看到homeassistant文件点击进入即可。
编辑configuration.yaml最好使用微软出品的Visual Studio Code这个请自行下载很方便的,笔者没有权限发布连接,如果需要可以关注并私信我
配置homeassistant天气插件让homeassistant可以显示详细的天气信息
使用Visual Studio Code打开configuration.yaml文件找到sensor添加下面代码
# Weather prediction
sensor:
- platform: yr
name: Weather
forecast: 24 #未来24小时天气,可有手工按需修改
monitored_conditions:
- symbol
- temperature #气温
- precipitation #雨量
- windSpeed #风速
- pressure #气压
- windDirection #风向
- humidity #湿度
以上天气信息内容可按需取舍,亦可以访问Yr组件介绍页面选择加载更多天气信息内容。
保存配置文件,重新启动homeassistant可以在页面中完成,
进入配置-通用-重启服务即可。
看到Home Assistant系统Web操作页面顶端出现各种天气信息显示图标,说明配置成功。
明天为大家带来更加直观的天气状态,先上图,明天见
閱讀更多 一目魚 的文章