0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ラズパイ 赤外線でエアコンの消し忘れを自動で消す、人がいる時にエアコンの暖房自動ONを実現 ステップ

Last updated at Posted at 2025-01-09

1.消し忘れ機能の設定。 午前1:00にエアコンを消す。 これは年中使えます。

sudo crontab -e

中身は以下 Indoor Corgiさんのサンプルを少しアレンジ
0 1 * * * cd /home/pi/ && /usr/local/bin/cgir send aircond_off > /tmp/crona.log 2>&1

2.11度未満ならエアコンの暖房をオンにする。
1)Indoor Corgiさんのサンプルを少しアレンジ。 heater_on.pyで保存&実行。
いけた。これは夏もいける。 夏になったら追加実装しよう。

#!/usr/bin/env python3

import subprocess
from cgsensor import BME280

bme280 = BME280(0x76)  # RPZ-IR-Sensorの基板上センサーを使う場合は0x77にする

# 測定成功
if bme280.forced():
  print('気温: {}°C'.format(bme280.temperature))  # 気温を画面に表示

  # 11度未満なら暖房ON
  if (bme280.temperature < 11):
    print('赤外線送信')
    subprocess.run(['cgir', 'send', 'heater_on'])

# 測定失敗
else:
  print('センサーが検出できませんでした')

3.MariaDbにテーブル作成。ルートユーザでログイン。

mysql -u root -p 

■DB作成、テーブル作成

use miyamodb
create table jinkan_kenchi (id INT NOT NULL PRIMARY KEY, kenchisw DECIMAL(1) unsigned,upd_datetime datetime default(CURRENT_TIMESTAMP));

■初期データ作成

insert into jinkan_kenchi values (1,0,default);
quit
0
1
0

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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?