LoginSignup
1
2

More than 3 years have passed since last update.

rpz-ir-sensorの温度、湿度、照度の状態をgooglehomeに喋らせる

Last updated at Posted at 2019-07-20

IMG_0605.JPG
上段のrpz-ir-sensorを使います。
まずはサンプルpgmインストール

$wget http://indoor.lolipop.jp/IndoorCorgiElec/RPZ-IR-Sensor/rpz-sensor.zip
$sudo pip3 install docopt
$unzip rpz-sensor.zip

次に @sikkim さんの作成したものを導入します。
https://qiita.com/sikkim/items/f03df7e2db13ea7f5a2b

シェルを作成します。
export VOICETEXT_SPEAKER=XXXX
で声を変えます。
2019/7/21 @sikkim さんに教えてもらいました。

BEAR 凶暴なクマ
HARUKA HIKARIよりも落ち着いた女性の声
SANTA 浮かれたサンタクロース
SHOW 「モヤモヤさまぁ~ず」のナレーター
TAKERU  落ち着いた男性の声

$sudo nano /opt/google_voice.sh
===内容

google_voice.sh
#!/bin/sh
export VOICETEXT_API_KEY=xxxxxxxxxxxxxxxxxxxx
export WIRELESS_IP=xxx.xxx.xxx.xxx
export GOOGLE_HOME_IP=xxx.xxx.xxx.xxx
export VOICETEXT_SPEAKER=SHOW
sudo service dbus start
sudo service avahi-daemon start
node /home/pi/google-home-voicetext/file-server.js &  node /home/pi/google-home-voicetext/api-server.js

実行権限を与えます。

$sudo chmod 755 /opt/google_voice.sh

systemdに登録します。

$sudo nano /etc/systemd/system/google_voice.service
内容

google_voice.service
[Unit]
Description = google voice service
After=network.target

[Service]
Type=simple
ExecStart=bin/sh /opt/google_voice.sh

[Install]
WantedBy=graphical.target

そして以下を実施

$sudo systemctl daemon-reload
$sudo systemctl startgoogle_voice
$sudo systemctl status google_voice
起動時に登録をするように設定
$sudo systemctl enable google_voice

【1】 温度、湿度の状態でgooglehomeに喋らせる

$nano /home/pi/rpz-sensor/python3/bme280i2c.py
で 以下を追加します。
設定については湿度は実際 ラズパイにrpz-sensorを直付けしている関係上、低く設定しています。
冷却FAN2台つけていますが。。。

      hikaku_ph = 28.00
      hikaku_pl = 15.00
      hikaku_hh = 63.00
      hikaku_hl = 40.00
      data_ph = {'text': '暑いで~す。'}
      data_pl = {'text': '寒いで~す。'}
      data_hh = {'text': 'じめじめしま~す。'}
      data_hl = {'text': '乾燥していま~す。'}
      if float(self.T) > float(hikaku_ph):
        response = requests.post('http://192.168.1.10:8080/google-home-voicetext',data=data_ph)
      if float(self.T) < float(hikaku_pl):
        response = requests.post('http://192.168.1.10:8080/google-home-voicetext',data=data_pl)
      if float(self.H) > float(hikaku_hh):
        response = requests.post('http://192.168.1.10:8080/google-home-voicetext',data=data_hh)
      if float(self.H) < float(hikaku_hl):
        response = requests.post('http://192.168.1.10:8080/google-home-voicetext',data=data_hl)

【2】 照度の状態でgooglehomeに喋らせる

$nano /home/pi/rpz-sensor/python3/tsl2572.py
で 以下を追加します。朝7時にcron設定するので以下としています。

      hikaku_akarui  = 40.00
      hikaku_mabushi = 50.00
      data_kurai   = {'text': 'どんよりした朝だよ。'}
      data_akarui  = {'text': '明るい朝だよ。'}
      data_mabushi = {'text': '眩しい朝だよ。'}
      if float(self.lux) < float(hikaku_akarui):
        response = requests.post('http://192.168.1.10:8080/google-home-voicetext',data=data_kurai)
      if float(self.lux) >= float(hikaku_akarui) and float(hikaku_mabushi) >= float(self.lux):
        response = requests.post('http://192.168.1.10:8080/google-home-voicetext',data=data_akarui)
      if float(self.lux) > float(hikaku_mabushi):
        response = requests.post('http://192.168.1.10:8080/google-home-voicetext',data=data_mabushi)

【3】その他

あとはCronですきな時間に動かします。

1
2
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2