个人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 虚拟环境安装 Home Assistant 以避免影响生产环境。
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 #风速
- pressure #气压
- windDirection #风向
- 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:语调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: "现在播报天气信息。温度,{{states('sensor.weather_temperature')}}°C, 湿度{{states('sensor.weather_humidity')}},风速{{states('sensor.weather_wind_speed')}}, 气压{{states('sensor.weather_pressure')}}"
复制相关脚本
复制https://github.com/cloudswave/pi3-script/tree/master/homeassistant/custom_components下的脚本到~/.homeassistant/custom_components
下
重新加载配置文件或者重启服务:
测试是否播报:
参考
https://github.com/home-assistant/home-assistant
https://home-assistant.cc/installation/general/