Media that understands new manufacturing You can make it with Raspberry Pi—You can also do home automation

You can make it with Raspberry Pi

Manufacturing Lab

by Egawa

2018/01/19 09:00

Electronic device Raspberry Pi smart home Tweet share ▼

A serial project "It can be made with Raspberry Pi" that introduces examples of using "Raspberry Pi". In the 5th session, home appliances will be controlled using "Grove Pi +", "IFTTT" and "Mini Smart Socket" (hereinafter referred to as "smart plugs").

If you make too much noise at home, let's drop the breaker

This time, let's try to control home appliances using Raspberry Pi. I think I sometimes make a fool of myself at home. I'm sure it's not bad, but it will bother the people and neighbors who live with it. If you make too much noise, control the outlet with a Raspberry Pi, turn on a lot of household appliances that use a lot of electricity such as a hair dryer, and turn off the breaker. Home automation.

The system created this time is as shown in the image below. Read the sound sensor data with Raspberry Pi, and if it is judged to be noisy, send a trigger to "IFTTT". IFTTT is a service that can operate services on different Internets in cooperation with each other. It receives a trigger from Raspeye and requests the application "Smart Life" that can control smart home appliances to turn on the smart plug. Finally, Smart Life turns on the smart plug, the dryer starts and consumes power. A Wi-Fi environment is required to operate the smart plug.

Preparing a smart plug

The smart plug used this time is a smart plug made by Aitmexcn . It can be controlled with a smartphone app called Smart Life , and all settings are done with the smartphone app.

Launch the app with the smart plug plugged into an outlet to register as a user and add devices.

After selecting "Socket", press and hold the power button of the smart plug, and when the lamp blinks, tap "Confirm with flash".

You will be asked for the Wi-Fi password, so enter the password for the same network that your smartphone is connected to.

When the connection is completed, you can give a name to the smart plug, so give it an arbitrary name to distinguish it. I chose Raijin-01,02.

Now the smart plug is ready.

新しいものづくりがわかるメディア それ、ラズパイでつくれるよ——ホームオートメーションもできるよ

Preparing for IFTTT

IFTTT is an abbreviation of "IF This Then That", and it is a service that allows services to be linked with each other. This can also be set entirely with the smartphone app .

First, launch the app and search for "Webhooks" in the Search tab. Select “Documentation” in the upper right to get the key to use for the trigger. Let's record this. Webhooks is a service that can send information of one service to another service in real time.

Next, create your own IFTTT Applet in the My Applets tab. Select this to search for and select “Webhooks”. Select "Receive a web request" and set the Event Name to any name on the next screen. I named it "RAIJIN".

If you search for "smart life" in that, the above app will appear. Select "Turn on" to connect to the app. You can select the name of the smart plug you have set in the "Which device / group?" Part, so select the Raijin plug.

If the following is displayed, you are ready to go. Let's prepare Applet by the same operation for the prepared smart plug.

On the Documentation page of Webhooks, enter the event name set in the {event} part and tap "Test it" at the bottom of the screen to test the trigger. Make sure the smart plug is switched on.

I don't want to solder to make hard

This time, let's read the sensor data easily using the HAT called Grove Pi +. By using this, you don't have to look at the breadboard like the 3rd time , let alone the soldering work.

Preparation on the Raspberry Pi side

Prepare the following hardware.

Download the data required for Raspberry Pi to use Grove Pi +. I haven't attached the Grove Pi + to the Raspberry Pi yet. Open a terminal and enter the following command.

  $ cd / home / pi / Desktop $ sudo git clone https://github.com/DexterInd/GrovePi

I thought that the "pi" part could be any user name, but then I'm having a hard time getting an error in the next step. I had to re-install the OS, so I recommend running it as a pi user.

The painful command is as follows.

  $ cd /home/pi/Desktop/GrovePi/Script $ sudo chmod + x install.sh $ sudo ./install.sh

The official and various sites say it will restart automatically, but my Raspberry Pi kept running as if nothing had happened, so I restarted it manually.

  $ sudo reboot

Now the software is ready. Let's put Grove Pi + on it. Turn off the power when installing.

There are a lot of pins left as shown in the image. But that's fine.

After turning on the power and confirming that the green LED on the Grove Pi + is on, at the terminal,

  $ sudo i2cdetect –y 1

Enter, and if "04" is displayed as shown in the screenshot, it's OK.

Finally, connect the Grove module as follows and you're ready to go.

  Grove Sound Sensor – A0Grove LED – D2

Make it work with a Python script

Create a python script and run it as follows. The sound sensor outputs a larger value as the ambient sound is louder. In particular, it reacts strongly to a haha ​​voice and records the number of times the read value exceeds the threshold value in num. And when num becomes 3, send a trigger to IFTTT. Rewrite the EVENT and KEY parts according to your settings and save it as hotokenokaomosandomade.py. In my case, EVENT is "RAIJIN".

  from time import sleepimport grovepiimport requests # Maker Webhooks NameEVENT = "" # Maker Webhooks KeyKEY = "" # Connect the Grove Sound Sensor to analog port A0sound_sensor = 0grovepi.pinMode (sound_sensor, "INPUT") # Connect the Grove LED to digital port D2led = 2grovepi.pinMode (led, "OUTPUT") grovepi.digitalWrite (led, 0) # The thresholdthreshold_value = 400 # Setup Progressnum = 0hotoke = Truedef nidoarukotohasandoaru (): url = "https://maker.ifttt.com/trigger/ "+ EVENT +" /with/key/ "+ KEY requests.post (url = url) while True: try: # Read the sound levelsensor_value = grovepi.analogRead (sound_sensor) if num == 1: grovepi.digitalWrite (led, led, 1) print ("HOTOKE NO") if num == 2: grovepi.digitalWrite (led, hotoke) hotoke = not (hotoke) print ("KAO MO") if num> = 3: print ("SANDOMADE \ n \ r" ") grovepi.digitalWrite (led, 0) nidoarukotohasandoaru () breakif sensor_value> threshold_value: num + = 1print ("sensor_value =% d "% sensor_value) sleep (0.2) except KeyboardInterrupt: grovepi.digitalWrite (led, 0) break except IOError : print ("Erro"  r ")

Execute it from the terminal with the following command.

  $ python hotokenokaomosandomade.py

If you ignore the LED warning and continue to haha, the Buddha's face will be up to three times, the dryer will turn on and the breaker will trip. The breaker (ampere breaker) in my house is 20A, but it didn't trip at all with about 2 dryers. With the maximum kotatsu output, 700W range, 1000W toaster oven, and electric kettle, I was finally able to turn off the kotatsu breaker. Because of that, I have that kind of face in the video.

* Editor's note: If the breaker (ampere breaker) trips, the entire house will lose power. It may damage the HDD of a device with a built-in HDD such as a working personal computer or DVD recorder. The timers and clocks built into various home appliances may be reset, or the home appliances that were in operation may display an error. Be careful when actually dropping the breaker and when inserting the breaker.

This time, I used Raspberry Pi to control home appliances. It is difficult to turn off the breaker, so please try using it for daily life, such as applying it to lighting.

* In this corner, we are waiting for everyone's "It can be made with Raspberry Pi". Please apply from the inquiry form .

Reference link: Grove Pi + initial setting: https://www.dexterindustries.com/GrovePi/get-started-with-the-grovepi/setting-software/ Trigger to IFTTT: http://www.daipanman.com/ entry / 2017/07/07/07 1949 Cooperation between smart outlet and IFTTT: https://www.masamedia.top/archives/3343.html