Let's add to our room sensor - Part 5 - Movement detection

Home Automator
13 Jun 202433:20

Summary

TLDRIn this DIY Electronics tutorial, Pascal guides viewers through building an ESP-based motion sensor using a passive infrared (PIR) sensor. The project integrates with ESP Home to monitor movement and control lighting, distinguishing between movement and presence. The tutorial covers hardware setup, software requirements, and coding, with a focus on practical applications and future enhancements using millimeter wave sensors.

Takeaways

  • πŸ˜€ The tutorial is about building an ESP-based motion sensor package using ESP Home.
  • πŸ” The HC-SR501 PIR (Passive Infrared) sensor is recommended for its precision and reactivity in detecting motion.
  • πŸ› οΈ PIR sensors work by detecting changes in infrared radiation caused by body heat, commonly used in security and automatic lighting.
  • πŸ”¬ The difference between PIR and millimeter wave sensors is highlighted, with the latter providing more detailed presence detection.
  • πŸ’‘ PIR sensors are cost-effective and simple for basic occupancy detection like motion-activated lighting.
  • βš™οΈ The HC-SR501 has settings for repeat trigger and single trigger modes, along with sensitivity and time delay adjustments.
  • πŸ”© The assembly process involves connecting the PIR sensor to specific GPIO pins on the ESP board, with safety measures taken to avoid damage.
  • πŸ“ The code for the PIR sensor in ESP Home is simple and involves binary GPIO sensor states, with unique identifiers and device classes.
  • πŸ”„ The tutorial includes practical demonstrations of the sensor's functionality, including triggering the sensor and observing its effects on a light.
  • 🏠 Home Assistant integration is showcased, with the sensor's data feeding into Home Assistant for automation purposes.
  • πŸ€– Automation examples are provided, such as turning a light on when motion is detected and ensuring it only activates under certain light conditions.

Q & A

  • What is the main focus of the tutorial presented by Pascal?

    -The tutorial focuses on building an ESP-based motion sensor package using ESP Home, with the aim of monitoring movement to switch a light on and off using automation.

  • What is the difference between a passive infrared sensor (PIR) and a millimeter wave sensor in terms of occupancy detection?

    -A PIR sensor detects motion by measuring changes in infrared radiation caused by body heat and is cost-effective and simple for basic occupancy detection. A millimeter wave sensor, on the other hand, emits microwave pulses and analyzes the reflected signals to detect movement with more precision and can even detect the presence of a person when there is no movement.

  • Why would someone choose a PIR sensor over a millimeter wave sensor for a project?

    -One might choose a PIR sensor for its simplicity, cost-effectiveness, and quick response to significant changes in infrared radiation, making it suitable for applications like motion-activated lighting and security alarms.

  • What are the two states of a PIR sensor?

    -A PIR sensor has two states: it sends a high 5 volts signal when motion is detected and a low signal when motion is not detected.

  • What is the purpose of the repeat trigger and single trigger settings on a PIR sensor?

    -The repeat trigger setting allows the sensor to continuously detect motion and restart the delay timer with each motion, useful for tracking ongoing activity. The single trigger setting causes the sensor to trigger once and maintain the output state for a specified time, ignoring additional motion during this period.

  • How does the sensitivity potentiometer on a PIR sensor affect its performance?

    -The sensitivity potentiometer adjusts the range of detection. Turning it clockwise increases the range, while turning it anticlockwise decreases it.

  • What is the function of the time delay potentiometer on a PIR sensor?

    -The time delay potentiometer adjusts the duration for which the sensor maintains a high output signal after motion is detected. Increasing the setting with the potentiometer extends the delay, while decreasing it shortens the delay.

  • What are the three typical pin assignments for a PIR sensor?

    -The typical pin assignments for a PIR sensor are ground (GND), output/data (OUT or DATA), and VCC (power supply).

  • How does the tutorial demonstrate the integration of the PIR sensor with Home Assistant?

    -The tutorial demonstrates the integration by showing the sensor's data feed in Home Assistant, creating an automation that switches a light on when motion is detected, and using conditions to ensure the light only turns on under certain illuminance levels.

  • What is the purpose of the condition block in the automation created in the tutorial?

    -The condition block is used to ensure that the light only turns on when the illuminance level falls below a certain threshold, preventing the light from turning on in bright conditions where it might not be needed.

  • What is the next step in the tutorial series after adding the PIR sensor?

    -The next step in the tutorial series is to add a millimeter wave sensor for presence detection.

Outlines

00:00

πŸ˜€ Introduction to DIY Electronics with ESP Home

Pascal welcomes viewers to another tutorial on DIY Electronics with ESP Home. The series focuses on building an ESP-based sensor package, starting with a passive infrared (PIR) sensor. The tutorial is structured with chapters accessible through the video timeline or description. The goal is to add a PIR sensor to an ESP Home room sensor project to monitor movement and control lighting. Pascal emphasizes the value of the tutorial and encourages viewers to like, subscribe, and hit the notification bell. Hardware and software requirements are briefly mentioned, with a specific recommendation for the HC-SR501 PIR sensor. The tutorial also outlines the basics of infrared motion detection sensors, explaining their use in security and lighting applications.

05:04

πŸ” Understanding PIR Sensors vs. Millimeter Wave Sensors

This paragraph delves into the differences between passive infrared (PIR) sensors and millimeter wave sensors. PIR sensors detect general movement by measuring changes in infrared radiation caused by body heat, making them cost-effective for basic occupancy detection like motion-activated lighting and security alarms. In contrast, millimeter wave sensors use microwave pulses to analyze reflected signals, detecting even subtle movements with precision. They are suitable for advanced applications like movement detection in confined environments or areas with minimal movement. The paragraph also discusses the speed of detection and the factors influencing the choice between PIR and millimeter wave sensors, such as range, accuracy, cost, and power consumption. Pascal plans to use both types of sensors in the tutorial series, starting with the PIR sensor.

10:05

πŸ› οΈ Setting Up the PIR Sensor Hardware

Pascal demonstrates how to physically set up the PIR sensor, starting with checking the pin assignments (VCC, OUT, DATA, GROUND) and ensuring the correct order. He advises viewers to always check the pin order when working with different boards. The tutorial includes a step-by-step guide on connecting the sensor to the ESP Home system, using GPIO14 for the PIR sensor. Pascal also provides a full circuit diagram on his GitHub page for reference. The assembly process is detailed, including the use of a frame to mount the sensor and the necessary precautions to avoid damaging the components.

15:05

πŸ’» Coding the PIR Sensor for ESP Home

The paragraph covers the coding process for integrating the PIR sensor with ESP Home. Pascal explains that the code for the PIR sensor is similar to that of a capacitive touch sensor due to their binary nature. The code involves defining the sensor as a platform GPIO, using GPIO14, and setting an ID and name. A key difference is the addition of a device class as 'motion'. The tutorial also includes instructions for installing the sensor wirelessly and checking the logs to ensure the sensor is functioning correctly. The movement detection is tested, and the results are shown in the Home Assistant dashboard.

20:08

🏠 Integrating Movement Detection into Home Assistant

Pascal guides viewers through integrating the movement detection sensor into the Home Assistant dashboard. He demonstrates how to add the sensor to the dashboard and edit it to display 'movement detected' instead of 'not movement'. The tutorial also covers how to create a simple light card for controlling a light based on the sensor's input. The focus is on ensuring that the movement detection is accurately reflected in the Home Assistant interface, with the sensor's status clearly visible and functional.

25:10

πŸ€– Automating Light Control with Movement Detection

This paragraph introduces the concept of automating light control based on movement detection. Pascal explains how to create an automation in Home Assistant that triggers the light when movement is detected. He also discusses the importance of adding a condition to ensure the light only turns on in specific lighting conditions, using a light sensor to determine the ambient light level. The automation is tested, and a condition is added to trigger the light only when the light level falls below a certain threshold. The tutorial also covers creating a second automation to turn off the light after a set period.

30:11

πŸ”„ Addressing Automation Timing Issues and Future Plans

Pascal addresses a potential issue with the automation timing, where the light might not turn off as expected due to repeated triggering of the sensor. He mentions that there are ways to overcome this issue and promises to cover it in a future tutorial. The paragraph concludes with a reminder to like, subscribe, and support the channel through Patreon or Buy Me a Coffee. Pascal signs off, looking forward to the next tutorial where he plans to add presence detection using a millimeter wave sensor.

Mindmap

Keywords

πŸ’‘DIY Electronics

DIY Electronics refers to the practice of building or modifying electronic devices, circuits, or systems by oneself. In the context of this video, the host is guiding viewers through the process of creating a home automation project using ESP home and a PIR (Passive Infrared) sensor. This aligns with the theme of empowering individuals to engage in hands-on electronics projects.

πŸ’‘ESP Home

ESP Home is an open-source system for controlling ESP8266 and ESP32 based devices using Home Assistant. It plays a central role in this tutorial as the platform that enables the integration of the PIR sensor with home automation systems. The script mentions setting up and using ESP Home to manage the sensor data and control lighting based on motion detection.

πŸ’‘Passive Infrared Sensor (PIR)

A Passive Infrared Sensor, often abbreviated as PIR, is a type of motion sensor that detects movement by sensing changes in infrared radiation. In the video, the HC-SR501 PIR sensor is specifically recommended for building a motion detection system that can trigger actions like turning lights on and off. The script discusses the advantages of PIR sensors in security and lighting applications.

πŸ’‘Motion Detection

Motion detection is the process of identifying movement within a defined area. In the video, the PIR sensor is used for motion detection, which is crucial for automating tasks like lighting control. The script explains how the sensor detects changes in infrared radiation to determine if movement is occurring, thereby triggering the associated actions.

πŸ’‘Home Assistant

Home Assistant is an open-source home automation platform that can integrate various devices and services. In this video, Home Assistant is used to manage the data from the PIR sensor and control home lighting. The script demonstrates how to integrate the sensor with Home Assistant to create a responsive home automation system.

πŸ’‘Millimeter Wave Sensor

A millimeter wave sensor is a type of motion sensor that uses microwave pulses to detect changes in movement. The script contrasts PIR sensors with millimeter wave sensors, highlighting their different applications and capabilities. Millimeter wave sensors are mentioned as being more suitable for detailed presence detection and are planned for use in a future tutorial.

πŸ’‘Occupancy Detection

Occupancy detection refers to the identification of whether a space is currently being occupied. In the video, both PIR and millimeter wave sensors are discussed in the context of occupancy detection. The script explains how these sensors can be used for basic motion detection or more advanced presence detection, respectively.

πŸ’‘Illuminance Sensor

An illuminance sensor measures the amount of light in a given area, typically in lux. In the video, the script mentions using an illuminance sensor to determine the ambient light level, which can influence whether the motion-triggered lighting is activated. This adds a layer of intelligence to the automation, ensuring lights are only turned on when necessary.

πŸ’‘Automation

Automation in the context of this video refers to the process of setting up rules or triggers in Home Assistant to perform actions automatically, such as turning lights on or off based on sensor inputs. The script details how to create automations that respond to motion detection and light levels, enhancing the functionality of the home automation system.

πŸ’‘Device Simulator

A device simulator is a tool used to mimic the behavior of actual devices for testing or demonstration purposes. In the video, the script discusses using a device simulator to test the automation rules created in Home Assistant. This allows the host to demonstrate how the system would respond in real-world scenarios without needing physical devices.

Highlights

Introduction to a new tutorial series on building an ESP-based motion sensor package using ESP Home.

Explanation of the utility of a passive infrared (PIR) sensor in DIY electronics for motion detection.

Recommendation of the HC-SR501 PIR sensor for its precision and reactivity in motion detection.

Overview of the difference between passive infrared sensors and millimeter wave sensors for occupancy detection.

Description of how PIR sensors function using pyroelectric sensors to detect heat energy changes.

Advantages of PIR sensors in terms of cost-effectiveness and simplicity for basic occupancy detection.

Details on the capabilities of millimeter wave sensors for advanced applications like visitor presence monitoring.

Technical comparison between PIR and millimeter wave sensors in terms of detection speed and accuracy.

Practical setup instructions for the HC-SR501 PIR sensor, including pin assignments and settings.

Demonstration of assembling the PIR sensor with an ESP Home system for motion detection.

Code explanation for integrating the PIR sensor with ESP Home, highlighting similarities with capacitive touch sensors.

Tutorial on setting up automation in Home Assistant to control lighting based on PIR sensor input.

Use of conditional logic in automation to prevent lights from turning on during daylight hours.

Troubleshooting tips for ensuring the PIR sensor is correctly calibrated and functioning with Home Assistant.

Discussion on the limitations of PIR sensors and the upcoming tutorial on adding millimeter wave sensors for enhanced presence detection.

Final wrap-up summarizing the tutorial's achievements and previewing the next steps in the series.

Call-to-action for viewers to like, subscribe, and support the channel for more DIY electronics tutorials.

Transcripts

play00:00

hey there I'm Pascal and welcome to

play00:02

another UT tomator tutorial if this is

play00:05

your first time welcome to the wonderful

play00:07

world of DIY Electronics with ESP home

play00:11

in this series we are building an

play00:13

over-the-top ESP based groom sensor

play00:16

package using ESP home card to the

play00:19

series above here if you've seen any of

play00:22

my previous tutorial welcome back I know

play00:26

that your time is valuable so the

play00:29

tutorial say chapters which you can

play00:32

access from the video timeline or in the

play00:35

description if you want to skip to the

play00:37

me staff go straight to about the P

play00:41

sensor where I explain why we want to

play00:43

use a passive andrate sensor in today's

play00:47

tutorial we will continue to add to our

play00:50

room sensor by adding a p sensor to our

play00:54

ESP Home Room sensor project to monitor

play00:58

movement and to switch a light on and

play01:00

off using an

play01:03

automation with a little twist we'll

play01:06

also make the distinction between what

play01:08

is movement or what is

play01:15

resence if you like this tutorial please

play01:18

like subscribe hit the notification Bell

play01:22

this will enable the YouTube algorithm

play01:24

to present this tutorial to more people

play01:31

let's review our hardware and software

play01:33

requirements I'll leave links to some of

play01:36

the components on my ga page some of

play01:39

these may be Affiliated links and I will

play01:42

get back a percentage of the sales but

play01:45

it will not cost you a cent more thank

play01:49

you for supporting the channel for the

play01:51

hardware we will need a passive infate

play01:56

sensor there are various passive infate

play01:59

sensors but the specific one that I will

play02:01

recommend today for this tutorial is

play02:05

this one it's an HC

play02:08

sr501 P infrared sensor there are

play02:12

alternatives there are many P sensors

play02:17

however what I'm hearing is that they're

play02:19

not as precise and as reactive as the

play02:24

bigger one software wise we'll need home

play02:28

assistant and ESP home first let me

play02:31

outline what an infrared motion

play02:33

detection sensor is and the reason we

play02:36

would want to use

play02:41

one passive aneroid sensors or P for

play02:45

shorts are electronic sensors that

play02:47

measure infrared light radiating from

play02:51

objects in the field of view these

play02:53

motion sensors are commonly used in

play02:57

security alarms and automatic lighting

play03:00

applications they detect general

play03:02

movement but do not give information on

play03:05

who or what move for that purpose an

play03:08

Imaging IR sensor is required P sensors

play03:12

work by using a pair of pyro electric

play03:16

sensors to detect heat energy in the

play03:19

surrounding environment these two

play03:21

sensors sit beside each other and when

play03:24

the signal differential between the two

play03:26

sensor changes if a person enters the

play03:29

room for for example the sensor will

play03:31

engage that may mean it triggers an

play03:34

alarm notify authorities or maybe just

play03:37

turns on a light IR radiation focuses on

play03:42

each of the two pyro electric sensors

play03:45

using a series of lenses constructed in

play03:48

the sign sensors housing in addition to

play03:51

security and lighting applications P

play03:54

sensors are also used in more advanced

play03:57

applications such such as visitor

play04:00

presence monitoring in robotics in

play04:02

robotics for example a p sensor can be

play04:05

used for movement detection enabling

play04:08

robots to interact with their

play04:10

environment more effectively despite the

play04:13

sophisticated technology behind these

play04:15

senses they are relatively easy to use

play04:19

in Practical

play04:23

applications let's address the elephant

play04:26

in the room Motion versus presence and P

play04:29

versus millimet wave passive infrared

play04:33

sensors and millimet wave sensors are

play04:37

both used for occupancy detections but

play04:40

they function very differently and

play04:42

provide very different information P

play04:45

sensor primarily detects motion by

play04:48

measuring changes in infrared radiation

play04:51

caused by body heat they cost effective

play04:54

and simple to deploy making them

play04:56

suitable for basic occupancy detections

play04:59

such as motion activated lighting and

play05:03

Security Alarms however P sensors only

play05:07

detect general movement this and do not

play05:11

provide detailed information about what

play05:14

moved on the other end millimeter wave

play05:17

sensors emit microwave pulses that

play05:20

analyze the reflected signal to detect

play05:23

changes in movement and like P sensor

play05:26

millimeter wave sensors can be used for

play05:29

stat presence detection meaning they can

play05:32

detect the presence of a person even

play05:34

when there is no movement some can also

play05:38

detect multiple persons and provide

play05:41

information about the movement direction

play05:43

of each of these people this makes the

play05:45

millimet wave sensor more suitable for

play05:47

advanced application such as movement

play05:52

within a confined environment where are

play05:55

people going but also in the cases of

play05:58

tlets where we do not move move much

play06:00

office or study or a TV room where

play06:03

movement may not be evident and cannot

play06:06

be detected by a p sensor the speed of

play06:10

detection between passive infrared

play06:12

sensors of p and millimeter wave sensors

play06:16

can depend on various factors including

play06:18

the specific sensor model and their

play06:21

configuration P sensors are typically

play06:24

used for movement activated system or

play06:28

motion activated systems they're

play06:30

generally very quick to respond when

play06:33

there is a significant change in

play06:35

infrared radiation such as when a person

play06:38

enters a room on the other hand Millet

play06:42

wave sensors emit microwave pulses and

play06:44

analyzes the reflected signal to detect

play06:47

changes in movement they can detect even

play06:50

the most subtle movements with Precision

play06:54

which may require more complex signaling

play06:57

processing and could potentially produce

play07:00

a slight delay however in practical

play07:03

application both p and millimet wave

play07:05

sensors are fast enough to meet

play07:08

requirement for most use cases such as

play07:12

Lightning control security system and

play07:15

occupancy detection the choice between p

play07:18

and millimeter wave often depends more

play07:20

on factors like range accuracy cost

play07:24

power consumption than speed in summary

play07:27

both p and millimet wave s ens can be

play07:30

used for presence detection millimeter

play07:32

wave sensors provide a higher level of

play07:35

detail and accuracy whereas P detects

play07:39

broader movement and in my experience is

play07:41

faster at detecting someone walking into

play07:44

a room I want to make sure that you

play07:47

understand I will be using both I found

play07:50

that millimeter wave sensors are

play07:52

generally slower than its counterpart

play07:55

the P sensor today we are adding a p

play07:58

sensor we will add the millimet wave

play08:01

sensor to our room sensor package in the

play08:03

next tutorial in this

play08:09

series about the P sensor as you will

play08:12

see later the code for the P sensor is

play08:15

very simple you would even be forgiven

play08:18

for thinking it's a copy of the

play08:20

capacitive touch sensor P sensors only

play08:23

have two states these are sent out to

play08:26

the out or data pin motion is detected

play08:29

bringing us a high 5 volts motion is not

play08:32

detected bringing us a low however the P

play08:36

sensor has various onboard settings in

play08:39

addition to its spins the jumper has two

play08:42

settings repeat trigger in this mode

play08:46

every motion is detected and the delay

play08:48

timer is restarted if motion occurs

play08:51

again before the timer expires the

play08:54

condone resets this allows the sensor to

play08:57

repeatedly trigger as as long as there

play09:00

is continuous movement it's useful for

play09:03

scenarios where you want to track

play09:05

ongoing motion or activity or leave a

play09:08

light on while somebody is in the room

play09:10

single trigger when a motion is detected

play09:13

the output of the pr sensor turns High

play09:15

immediately it remains high for the

play09:18

duration set by the potential meter a

play09:20

knob that adjusts the Sensi the

play09:22

sensitivity and time delay during this

play09:25

period any additional motion is not

play09:28

processed and the timer does not res

play09:32

essentially it trigger once and

play09:34

maintains the output State for the

play09:36

specified time in our project initially

play09:39

we'll use the repeat trigger once we

play09:43

introduce a millimeter wave we'll use

play09:46

the single trigger and I'll explain why

play09:48

at that time there are also two

play09:50

potential meters sensitivity adjustment

play09:53

potential meter clockwise will increase

play09:56

the range and anticlockwise will

play09:58

decrease the range of Sensi sensitivity

play10:02

the time delay adjustment potential

play10:04

meter clockwise increases the delay and

play10:08

anticlockwise decreases the delay the

play10:11

pin assignments are as follows ground

play10:15

out or

play10:17

data and VCC some boards are different

play10:21

please check by unclipping the plastic

play10:24

Dome I usually start with the following

play10:27

settings single trigger over here

play10:30

minimum on the time and halfway on the

play10:34

sensitivity potential meter you can tune

play10:36

it from here and decide how you're going

play10:38

to set it

play10:42

up so here is a typical infrared uh

play10:47

infrared sensor or a passive infrared

play10:51

sensor the first thing that I'd like to

play10:53

show you is that you can clip

play10:56

off the um the plastic on

play11:01

top and the first thing that you that we

play11:04

need to check is the three pins and the

play11:07

order is VCC out of data and ground now

play11:13

these are not necessarily always in the

play11:15

same order I would advise you to check

play11:19

every

play11:20

time and then we are going to put it

play11:25

back and I am going to turn it on its

play11:28

side

play11:30

here is the uh trigger setting I usually

play11:36

put it in multiple

play11:39

trigger when I am testing and

play11:44

building then after that you've got the

play11:48

um sensitivity potential meter which is

play11:52

halfway and the timer which is at

play11:57

minimum you can tun it from from here

play12:00

you can chin it in whichever way you

play12:02

feel comfortable with uh some need need

play12:06

quite a bit of chining others work

play12:08

straight out of the

play12:13

box as usual because it's a binary

play12:17

sensor we can use almost any free GPI

play12:22

pins but we will use gp14 for the P

play12:26

sensor I remind you that we are using

play12:29

the following pins already gp26 for the

play12:33

dht22 gp21 for the i2c

play12:39

SDA gpio 22 for the

play12:44

i2c and gpio 12 for the capacitive touch

play12:49

sensor I will also attach a full circuit

play12:53

diagram on my giab page for this

play12:56

tutorial

play13:02

how about we put all of this together

play13:04

first I'd like to introduce you to a

play13:08

little frame that I've built um for this

play13:11

purpose um basically it's a um

play13:17

three uh a three dupon uh

play13:21

plug that goes directly

play13:25

into the

play13:29

P like this and then I just have the M

play13:35

dupon plugs on the other side first

play13:38

thing that we're going to do though is

play13:39

we are going to switch

play13:41

off the

play13:44

um the sensor package so that we don't

play13:47

blow

play13:49

anything so we're going to open again to

play13:51

make sure which one is our um our VCC

play13:56

and the VCC is set on the purple

play14:00

and that's all I need to know so we are

play14:03

going to plug this into VCC the purple

play14:08

oh that was a gray okay so we are going

play14:11

for the purple into the

play14:12

VCC if it doesn't mind there we are then

play14:17

the middle one is the gray and that's

play14:19

the data and the

play14:25

data the

play14:27

DAT is going into

play14:30

[Music]

play14:31

gpio4 and

play14:33

gpio4 is a one right after gpio

play14:38

12 so it comes or it should be coming

play14:43

from over here I apologize for hiding

play14:47

some of it and obviously the last one is

play14:50

the blue and that is

play14:53

ground assuming again that we can put it

play14:57

into the G

play15:00

uh come on a few moments

play15:05

later okay so it is now into the ground

play15:09

so to recap gray is

play15:13

on

play15:16

gp14 Blue is into

play15:19

the negative or the ground and uh purple

play15:25

is the

play15:27

positive we we will now use a little bit

play15:32

of tech as you can see I've put some

play15:34

here which I will put over here and I am

play15:38

going to mount the p over

play15:44

here and stick

play15:47

there and switch on the

play15:53

package flashes once and it should be

play15:57

online and it is

play16:00

so basically we are

play16:03

finished with the assembling and we can

play16:06

move on to some

play16:12

code I remind you that all of the code

play16:14

is available on my GitHub page for this

play16:17

tutorial the link is in the description

play16:20

first things first we've decided that we

play16:23

were going to use

play16:24

gpio4 now you will be forgiven for

play16:28

thinking that the code that I'm about to

play16:30

paste is very similar to the capacitive

play16:33

touch sensor and that's because both use

play16:36

a binary gpio sensor there are some

play16:39

differences and I will be pointing them

play16:41

out to you so let me go ahead make a

play16:44

little bit of

play16:46

space um there we've made a little bit

play16:50

of space I'm going to paste the code and

play16:53

sort out this tabing there and there we

play16:57

are we've got the passive infrared

play16:59

sensor code I am going to center it in

play17:01

the screen so that we can all see it

play17:04

properly and as per the capactive touch

play17:07

sensor it's platform gpio then we are

play17:11

using gpio

play17:13

14 and we are declaring an ID for it

play17:17

then its name is movement the difference

play17:20

here is we are defining a device class

play17:24

as motion something we never did for the

play17:28

capacitive touch light switch or touch

play17:31

sensor next thing we need to do is to

play17:35

save it and we are going to install it

play17:38

wirelessly as usual and I am going to

play17:41

just point out that whilst it

play17:44

uploads and we'll just have to wait for

play17:46

a second there you will see that the

play17:49

light the blue light

play17:51

flashes and that's because it's going

play17:54

into a safe mode and it is uploading and

play17:56

it is indicating that it is uploading

play18:00

when it is finished which is

play18:04

shortly there we are uh we are waiting

play18:07

now for the

play18:13

logs and it least yeah you saw it flash

play18:16

a couple of times it should have stopped

play18:17

flashing and that was it connecting back

play18:20

to the Wi-Fi and here we are it has

play18:24

started the logs movement sending State

play18:27

off which is a default uh sign sign for

play18:32

movement it hasn't picked up anything

play18:35

now let's see if I can trigger

play18:37

it and there you are it's picked up the

play18:40

state on and it has switched light on

play18:45

and that's because this is the first

play18:48

time of the first time that I record

play18:50

this piece okay so I will see you in the

play18:55

uh web server section in a second

play19:03

so we are here at the web server and uh

play19:06

we going to click on visit it's going to

play19:09

ask us for the username and password and

play19:13

we know this because we've set it

play19:16

up and apparently I can't spell admin

play19:19

and my password okay and I'm going to

play19:22

sign in and here we are and we are

play19:25

specifically looking at movement in the

play19:28

middle of

play19:29

there and what I'm going to do is I'm

play19:31

just going to bring my hand on within

play19:34

its uh its

play19:37

range yes there it is and uh it picked

play19:41

up the movement that's what I wanted and

play19:43

it takes

play19:44

about uh 10 seconds to actually go off

play19:48

and there we are okay so we are very

play19:51

happy that's working we are going to go

play19:53

straight into home assistant

play19:59

so let's go into home assistant and the

play20:02

first thing we want to check is that we

play20:04

are getting the feed of the device

play20:08

through to home assistant so we are

play20:10

going to go to ESB home on home

play20:14

assistant and uh we are going to look at

play20:17

the sensor and movement currently is

play20:21

clear let me pass my hand and yes it's

play20:24

detected and it should go off

play20:32

shortly there we are and if I pass again

play20:35

it should see movement great so that's

play20:41

working so now we're going to go all the

play20:43

way to the dashboard if the dashboard is

play20:46

a bit different to what you've seen in

play20:49

the past uh I have cleaned it up and all

play20:52

I did is add the light and the light

play20:55

just switches the light on as you can

play20:57

see and and switches the light

play21:00

off uh it is a very simple card because

play21:04

card sorry because it is the light card

play21:09

uh let me show you where you're going to

play21:10

find

play21:11

that you're going to add a card and if

play21:15

you go a little bit down you will find

play21:18

the light card and that's the card that

play21:20

I add it it's very straight forward you

play21:23

point it to the uh light and that's that

play21:27

okay but right now that's not what we

play21:29

are interested in right now we

play21:31

interested in having a feedback to see

play21:36

if the movement is detected or not so I

play21:40

am going to hit edit on our ESP Home

play21:42

Room sensor card I going to go right at

play21:45

the bottom and

play21:48

move and uh ESB home movement sensor let

play21:52

me try that again es oh sorry movement

play21:57

move

play21:59

there it is ESP home movement yes that's

play22:03

the one that we're looking for I am

play22:05

going to drag it all the way up because

play22:08

I like movement at the top I'm also

play22:11

going to go and edit it and all I'm

play22:13

going to do is

play22:16

move not not

play22:18

movement movement I'm going to save that

play22:22

and we and we're going to save the

play22:25

dashboard and we now have the movement

play22:28

inside of room assistant and let me show

play22:31

you detected oh eco2 detected what

play22:35

happened you see I break things from

play22:37

time to time too uh so I'm going to go

play22:40

and edit this where is oh I see what

play22:44

happened okay that's fine we just going

play22:46

to go EC

play22:48

o 2 and there it is and we're just going

play22:51

to save it I I must have missed clicked

play22:55

something somewhere uh it's clear and I

play22:58

put hand it's detected

play23:00

and pretty much that's it we are

play23:03

finished with the dashboard and uh yes

play23:06

the temperature right here inside the

play23:08

room is 18.8 De and as a matter of

play23:12

interest um it's uh 16Β° outside for us

play23:17

in Africa it's cold so I will see you

play23:21

and let's do an

play23:25

automation now that we have the uh

play23:28

sensor working we can start with the

play23:31

Automation and all we're going to do is

play23:34

to switch our light on and off and we'll

play23:40

be using the simulator we built in the

play23:42

last tutorial in this series for the

play23:44

demonstration that really you can use

play23:47

any Smart Switch the automation yl will

play23:51

be on my K on my G page link as usual in

play23:56

the description

play23:58

what we're going to do is when movement

play24:00

is

play24:01

detected we are going to take the uh ESP

play24:06

room sensor Movement we and we're going

play24:08

to set the simulators light from off to

play24:13

on um after that we will do the inverse

play24:17

of that in a separate automation now we

play24:20

could do both of them in the same

play24:22

automation but I don't want to overly

play24:25

comp overly complicate things so let's

play24:29

go to automations and uh we go to

play24:33

settings automations and scenes create

play24:36

new automations and oddly enough you're

play24:38

going to see motion activated light

play24:41

however motion activated light only does

play24:44

motion activate activation of the light

play24:48

we want to do one step further and I

play24:50

will show you what I'm talking about in

play24:52

a second so we're going to create a

play24:55

brand new automation the trigger is is

play24:58

going to be our

play25:01

device which is as we know the room

play25:05

sensor and we are going to choose ESP

play25:09

room sensor movement started detecting

play25:12

motion so there we are saying H we are

play25:15

detecting motion to check if it works

play25:18

it's pretty simple I'm going to put my

play25:19

hand in front of it and it's been

play25:22

triggered there are no and if we going

play25:25

to go to then do and we are actually

play25:27

going to put

play25:31

a building block and you will see why

play25:33

later right now though all I'm going to

play25:37

do is take an

play25:40

action and I am going to put the device

play25:43

in yome device simulator turn on ESP

play25:47

home device simulator simulated light no

play25:51

flashing no none of that okay so what is

play25:56

this if for if you've got a 2,000 wat

play26:00

light outside that you want to trigger

play26:03

with an infrared do you want that light

play26:07

to come on in broad daylight in fact it

play26:10

wouldn't even make it Dent even at 2,000

play26:14

wats you don't so what we're going to do

play26:17

is we are going to add a condition and

play26:19

the condition is

play26:21

device and we're going to go to the room

play26:25

sensor and we are going to go to

play26:29

elins below and um I have a little table

play26:34

here um which I will put into my G up

play26:38

page for this tutorial but uh the

play26:41

recommended values out door is generally

play26:44

about 10,000 laks indoor near window

play26:49

about 1,000 laks in office we need about

play26:53

500 laks in the home about 150 laks now

play26:58

now I can tell you right now that the

play27:00

board is receiving 258 laks so what we

play27:06

are going to do is if we fall below 150

play27:09

LS uh

play27:11

lxs uh we are going to trigger the light

play27:14

otherwise we don't now you're going to

play27:16

tell me how you're going to show this

play27:19

I'm going to show this to you in a

play27:21

second so the new automation is going to

play27:24

be called ESP home

play27:29

move

play27:30

M

play27:34

detected okay save

play27:37

now is this going to trigger the light

play27:41

so let's check let's put my hand

play27:46

through and movement has been detected

play27:49

and the simulator light hasn't come on

play27:53

what have I done wrong is it triggering

play27:56

at all

play28:02

is below 100 oh obviously one come

play28:09

on we are above 150

play28:13

laks so it can't come on so let me

play28:16

switch off my uh main light that lights

play28:20

me up and lights the board

play28:23

up here we are and I need to wait for

play28:26

about 30 seconds

play28:28

for the illuminant sensor to update

play28:31

there we are and we are currently at

play28:34

44.2 laks so if I put my in front of the

play28:38

sensor right now it should

play28:40

trigger and yes it does so we are now

play28:45

with a light that works and it takes

play28:47

about 30 seconds to switch it off a few

play28:50

moments

play28:52

later it's a long 30 seconds because it

play28:55

won't switch off I will have to do it

play28:59

manually okay we haven't done the switch

play29:03

off part yet all right so we are going

play29:06

to go back and we are going to open a

play29:10

new

play29:12

automation when when the trigger of a

play29:17

device in particular the room sensor and

play29:23

when movement is STO detecting motion

play29:28

right then do we do not need in this

play29:32

case a building block we'll just switch

play29:34

it

play29:37

off okay and we're going to paste the

play29:41

device it's ESP device simulator and

play29:44

turn on the

play29:46

ASP device simulator we want to actually

play29:50

turn it

play29:51

off there we

play29:54

are to make it wait for a minute which I

play29:58

like to do one minute or two what you

play30:00

would do is you would add here 01 we're

play30:04

not going to do that because we are

play30:06

going to waste time if we do that and

play30:11

I'm going to save it and call

play30:14

it ESP

play30:18

home

play30:21

movement not

play30:28

and we're going to save this and let's

play30:30

trigger it

play30:32

again and we are going to trigger it

play30:37

again and it should switch off shortly

play30:40

about 30

play30:43

seconds there we are and it has been

play30:48

triggered okay let me put the light back

play30:53

on and uh

play31:00

and uh one thing that we need to note is

play31:03

that each time the sensor is triggered

play31:05

the time it gets

play31:06

reset um so if the timer if the uh if

play31:14

it's retriggered again inside of Home

play31:16

assistant it will just increase the time

play31:19

as time goes by now as I

play31:23

said about 60 seconds before you switch

play31:26

off the light

play31:28

uh there is also another problem that

play31:32

exists I'm going to switch on the light

play31:33

for you and we are going to wait about

play31:36

30

play31:37

seconds and it's been

play31:40

triggered so I switch on the light and

play31:43

my automation switches it off I will

play31:47

show you how to overcome that in either

play31:51

the next tutorial or possibly the next

play31:54

tutorial or One A little later there are

play31:57

ways is around that and I will show you

play32:00

how to do that uh right now I think this

play32:04

tutorial has been long enough and we are

play32:07

coming to a close so here we so I'll see

play32:13

you in the wrap

play32:17

up now that we have movement detection

play32:20

to switch light on and

play32:22

off we can add presence detection using

play32:26

a Mim wave sensor this is coming in the

play32:30

next tutorial in the series little

play32:32

reminder please like subscribe and smash

play32:36

that notification button so you never

play32:39

miss a video if you want to support the

play32:41

channel a little more I am on patreon

play32:44

and buy me coffee links are in the

play32:47

description this was Pascal I'm signing

play32:51

off and see you in the next tutorial

play32:56

[Music]

play32:58

n

play33:00

[Music]

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
DIY ElectronicsESP HomeMotion SensorSmart HomeAutomationTutorialsInfrared SensorHome SecurityLight ControlPresence Detection