【スマートホーム】iRemocon Wi-FiでHome Assistant用に照度・温度・湿度を取得する
iRemocon Wi-Fiには、湿度・照度・温度のセンサーが付いている。
これらをHome Assistantに連携すると、「一定以下の湿度になったときにアラートをする」「空調を自動的に制御する」などが実施出来る。
今日は、その湿度・照度・温度を取得するスクリプトを紹介したい。
温度・照度・湿度取得用のスクリプトを書く
こんな感じ。
#!/bin/bash
PARAM=$1
HOME=`( echo \*se; sleep 1;) | telnet [iRemoconのIPアドレス] 51013 1> /tmp/telnet.temp.txt 2>/dev/null`
LUX=`cat /tmp/telnet.temp.txt | grep se | sed -e "s/se\;ok\;\(.*\)\;\(.*\);\(.*\)/\1/"`
HUM=`cat /tmp/telnet.temp.txt | grep se | sed -e "s/se\;ok\;\(.*\)\;\(.*\);\(.*\)/\2/"`
TEMP=`cat /tmp/telnet.temp.txt | grep se | sed -e "s/se\;ok\;\(.*\)\;\(.*\);\(.*\)/\3/"`
if [ $PARAM = "temp" ]; then
echo $TEMP
elif [ $PARAM = "hum" ]; then
echo $HUM
elif [ $PARAM = "lux" ]; then
echo $LUX
else
echo "NONE"
fi
Home Assistantは、たまにコマンドを直に打っても反応しなくなることがある。
そのため、一度/tmp/telnet.temp.txtにiRemocon Wi-Fiが出力する湿度・照度・温度の情報を出力し、そこからgrepとsedを用いて温度・照度・湿度それぞれを分解して取得するようにしている。
このファイルをhome.sh等で保存しておくと、次のコマンドで取得することが出来る。
湿度
home.sh temp
照度
home.sh lux
温度
home.sh temp
Home Assistantに設定を入れる
Home Assistantでは、これらをcommand line sensorとして扱う。
今回は上記のファイルを/share/home.shに保存したとしよう。次の設定をconfiguration.yamlに設定すると、センサーが自動的にHome Assistantに表示されるようになる。
sensor:
- platform: command_line
command: bash /share/home.sh temp
name: Home Temperature
unit_of_measurement: "°C"
- platform: command_line
command: bash /share/home.sh hum
name: Home Humidity
unit_of_measurement: "%"
- platform: command_line
command: bash /share/home.sh lux
name: Home Brightness
unit_of_measurement: "lx"
Home Assistantでの見え方
現在の温度だけではなく、その変化もきちんと見せてくれる。
温度

湿度

明るさ

custormize.yamlで名称を変更しているので、必ずしも上記の名称にはならないと思うが、このようにHome Assistantで照度・温度・湿度を取得することが出来た。
iRemocon Wi-Fi以外での取得
とはいえ、iRemocon Wi-Fiを所有していない場合にはどうすれば良いだろう。
個人的には、Xiaomi Smart Homeが安く販売されているので、目を付けている。
Xiaomi Mi Smart Home Sockets & Sensors, manage the whole house through a smartphone. Full specifications, user manuals, reviews from customers and video.
現在絶賛輸入中につき、到着し次第レビューをする予定。