樹莓派 智能家居DIY的樂趣開始配置homeassistant

樹莓派 智能家居DIY的樂趣開始配置homeassistant

大家好經過之前對homeassistant的認識、再到安裝架設homeassistant系統,今天我筆者帶大家對homeassistant進行配置為了讓大家可以更上進度所以我一步步叫大家開始配置homeassistant。

昨天大家都知道了homeassistant的主要配置文件是configuration.yaml文件位於homeassistant安裝目錄下。

當我們第一次啟動homeassistant時,homeassistant會自動創建一個名為configuration.yaml默認的設置文件,這個configuration.yaml文件是用YAML寫的。YAML是"另一種標記語言"的外語縮寫,它是一種直觀的能夠被電腦識別的數據序列化格式,是一個可讀性高並且容易被人類閱讀,容易和腳本語言交互,用來表達資料序列的編程語言。不要被這種語言嚇到,其實很簡單的。YAML最基本的語法就是集合和鍵值對。在一個集合每個子項都以短橫線"-"開始,而鍵值對則有這樣的格式"鍵:值"。注意:縮進是YAML定義各項之間關係很重要的手段。縮進相同的項,他們擁有相同的層級。製表符在YAML語言中是不可以用於縮進的,通常兩層級間我們都採用縮進兩個空格來表達。下面我們舉個栗子一看就懂了。

樹莓派 智能家居DIY的樂趣開始配置homeassistant

介紹完YAML簡單的語法,我們就可以開始進行設置我們的homeassistant了。我們先進行基礎設置。通常homeassitant會根據你的IP地址自動判斷你的位置,然後根據定位自動選擇溫度單位和時區,你可以在configuration.yaml文件中對這些進行重設。

下面為大家展示的是使用經緯度來確定自己實際所在的位置(注意經緯度的格式)

樹莓派 智能家居DIY的樂趣開始配置homeassistant

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大家看到的界面是這樣的

樹莓派 智能家居DIY的樂趣開始配置homeassistant

我們今天以之前樹莓派刷機的鏡像系統安裝結果為準配置homeassistant,因為其自帶了samba服務,所以現在只需要在資源管理器中直接輸入homeassistant的IP地址就行如(\\192.168.3.52)回車然後輸入樹莓派的用戶名和密碼可以看到pi的主文件夾點擊進入就可以看到homeassistant文件點擊進入即可。

樹莓派 智能家居DIY的樂趣開始配置homeassistant

編輯configuration.yaml最好使用微軟出品的Visual Studio Code這個請自行下載很方便的,筆者沒有權限發佈連接,如果需要可以關注並私信我

樹莓派 智能家居DIY的樂趣開始配置homeassistant

配置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可以在頁面中完成,

進入配置-通用-重啟服務即可。

樹莓派 智能家居DIY的樂趣開始配置homeassistant

樹莓派 智能家居DIY的樂趣開始配置homeassistant

看到Home Assistant系統Web操作頁面頂端出現各種天氣信息顯示圖標,說明配置成功。

樹莓派 智能家居DIY的樂趣開始配置homeassistant

明天為大家帶來更加直觀的天氣狀態,先上圖,明天見

樹莓派 智能家居DIY的樂趣開始配置homeassistant


分享到:


相關文章: