個人pi3+腳本倉庫:https://github.com/cloudswave/pi3-script
快捷安裝
git clone https://github.com/cloudswave/pi3-script.git
cd ./pi3-script/homeassistant
chmod +x install.sh
./install.sh
安裝Home Assistant和VLC播放器
#Home Assistant 官方推薦使用 Python 虛擬環(huán)境安裝 Home Assistant 以避免影響生產(chǎn)環(huán)境蹭沛。
sudo apt-get install python3 python3-venv python3-pip
python3 -m venv homeassistant
cd homeassistant
source bin/activate
python3 -m pip install --upgrade homeassistant
hass --open-ui
#vlc播放器
sudo apt-get install vlc-nox
sudo usermod -a -G audio pi
配置
~/.homeassistant/configuration.yaml
:
# Weather prediction
sensor:
- platform: yr
name: weather
forecast: 24 #未來24小時天氣臂寝,可有手工按需修改
monitored_conditions:
- temperature #氣溫
- precipitation #雨量
- windSpeed #風(fēng)速
- pressure #氣壓
- windDirection #風(fēng)向
- humidity #濕度
# Text to speech
tts:
- platform: baidu
#app_id摊灭,api_key咆贬,secret_key從百度云上注冊得到
app_id: 11337674
api_key: XtR74Qq3EvCRQNiLT7fHGna1
secret_key: XMeYTwjGOI4k6hC8PkTqM9nRew3Ehszt
#speed:語速0-9(缺省5)
#pitch:語調(diào)0-9(缺省5)
volume: 15 #音量0-15(缺省5)
#person:聲音(0:女帚呼,1:男掏缎,3:百度合成煤杀,4:百度合成御毅,缺省0)
speed: 5
pitch: 5
volume: 15
person: 0
media_player :
- platform: vlc
name: vlc
~/.homeassistant/automations.yaml
:
- alias: weather_report
initial_state: true
trigger:
- platform: time
hours: 8
minutes: 30
seconds: 0
condition:
condition: numeric_state
entity_id: sensor.weather_temperature
above: 0 #判斷氣溫是否高于0°C
action:
- service: tts.baidu_say
data_template:
entity_id: media_player.vlc
message: "現(xiàn)在播報天氣信息。溫度怜珍,{{states('sensor.weather_temperature')}}°C, 濕度{{states('sensor.weather_humidity')}},風(fēng)速{{states('sensor.weather_wind_speed')}}, 氣壓{{states('sensor.weather_pressure')}}"
復(fù)制相關(guān)腳本
復(fù)制https://github.com/cloudswave/pi3-script/tree/master/homeassistant/custom_components下的腳本到~/.homeassistant/custom_components
下
重新加載配置文件或者重啟服務(wù):
image.png
測試是否播報:
image.png
參考
https://github.com/home-assistant/home-assistant
https://home-assistant.cc/installation/general/