Headless install of OS image on Raspberry PI

Grab a copy of the raspberry pi image file from the mentor and drop it on your windows machine. This image was build from the following debian build repository:https://github.com/pyavitz/rpi-img-builder.

Grab balenaEtcher from here using your web browser and install it: https://github.com/balena-io/etcher/releases/download/v1.10.2/balenaEtcher-Portable-1.10.2.exe?d_id=6b847038-c52d-4e74-b2bd-637a8f4d3b2f&s_id=1671304640122

Put you SD card into your computer. If get pop up messages about disk needing to be formatted just cancle those messages.

Run the balenaEtcher application you grabbed above. Select from file and select the Raspberry pi image you just dropped on your laptop.

Select the target, being the SD drive.

Click on the flash button.

Once the image is written to the SD, eject the SD. Put the SD back into your laptop. You will get pop up messages about disk needing to be formatted, just cancle those messages.

One windows should pop up with a list of files on the SD card.

Use notepad to edit the file credentials.txt and update the following information:

# change false to true

ENABLE="true"

# Input the correct SSID and PASSKEY and then add US for COUNTRYCODE

SSID="CP_WIFI" # Service set identifier

PASSKEY="cyberpatriot" # Wifi password

COUNTRYCODE="US" # Your country code

# under change hostname change false to true and set HOSTNAME like shown with XX replaced

# with your assigned number

CHANGE="true"

HOSTNAME="ha-ctrlXX"

Save the file and then eject the SD card from your laptop. Insert the SD card in your raspberry pi and power it on. It’ll take a couple of minutes for the pi to boot.

Start a command prompt on your laptop kick off a ping command of the hostname you assigned to your Raspberry Pi controller, replacing XX with your assigned number:

ping ha-ctrlXX.local

This will fail if you pi as yet to boot. If it fails try it multiple time. After 5 minutes talk with the mentor.

Make sure you write down the IP address that was assigned to your pi as it might be required later.

Install Home Assistant

Grab a copy of putty from https://the.earth.li/~sgtatham/putty/latest/w64/putty.exe and put it on your laptop.

Run the putty executable you just downloaded and connect to host ha-ctrlXX.local (replace XX with your assigbed number) using ssh on port 22. You’ll be making an secure shell (ssh) connection with putty from your laptop to the HA controller. The Username is pi with password of 1234. This gives you a command prompt window on your pi. If ha-ctrlXX.local doesn’t work you can ssh to the IP you got from the ping above.

We’ll now need to run commands in the putty terminal window of the HA controller.

Make sure Debian is using legacy iptables as required by dockers

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy

sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy

Set the Locales which control your language and region of the world for your system

sudo menu-config

From the menu presented arrow down to access Locales then <enter>

Page Down and Arrow down or up to find en_US.UTF-8 UTF-8 and put the red cursor on this entry then hit the <space bar>. This should put an asterisk in under the red cursor.

If the asterisk appears then hit the <enter> key

Arrow down to en_US.UTF-8 and hit the <enter> key

Get out of menu-config

Arrow down to Quit and hit the <enter> key

At this point in a command window on your laptop you should be able to ping ha-ctrlXX, where XX is replaced by your assigned number.

Make sure system packages are up to date and install Home Assistant required packages

sudo apt-get update; sudo apt-get -y upgrade

# The following is one complete line to execute all at once.

sudo apt -y install jq libglib2.0-bin udisks2 network-manager network-manager-config-connectivity-debian netcat mosquitto-clients networkd-dispatcher ifmetric systemd-journal-remote

Install docker – first grab a key for docker

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# These 4 lines are all one command to set up the key and add the docker repository so we can pull docker package:

echo \

"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg]\

https://download.docker.com/linux/debian \

$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Make sure the list of available packages is updated then pull and install the appropriate docker packages

sudo apt-get update;sudo apt-get -y install docker-ce docker-ce-cli containerd.io

Pull the agent application required by home assistant.

#The next two lines are one command:

wget -cq --show-progress \

https://github.com/home-assistant/os-agent/releases/download/1.4.1/os-agent_1.4.1_linux_aarch64.deb

#XXXX https://github.com/home-assistant/os-agent/releases/download/1.2.2/os-agent_1.2.2_linux_aarch64.deb

Install the agent

sudo dpkg -i os-agent_1.4.1_linux_aarch64.deb

enable the dns service required by HA

sudo systemctl enable systemd-resolved.service

sudo systemctl start systemd-resolved.service

Set up a fake grub bootloader file so HA will install

sudo touch /etc/default/grub

echo '#!/bin/bash' | sudo tee /usr/bin/update-grub

echo 'echo got it' | sudo tee -a /usr/bin/update-grub

sudo chmod 755 /usr/bin/update-grub

enable GPIO pins so that normal user can control them

sudo apt install -y gpiod python3-libgpiod

echo 'KERNEL=="gpiochip0", MODE="0666"' | sudo tee -a /etc/udev/rules.d/99-perm.rules

echo 'KERNEL=="gpiochip1", MODE="0666"' | sudo tee -a /etc/udev/rules.d/99-perm.rules

Add some kernel arguments, some that are required by HA, some that make the system more stable.

#The four lines below are really a single line that are executed as one command :

sudo sed -i '/rootwait/ s/$/ systemd.unified_cgroup_hierarchy=false systemd.legacy_systemd_cgroup_controller=false usbcore.autosuspend=-1 usbcore.autosuspend=-1 clk_ignore_unused cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory apparmor=1 security=apparmor/' /boot/broadcom/cmdline.txt

At this point it would be a good idea to reboot and then connect back to your pi via putty using:

sudo shutdown -r now

From a command terminal on your laptop you could run a ping command to see when your machine is back up

ping -t ha-ctrlXX.local

Once you’ve logged back into the ssh command prompt via putty grab and install the HA supervisor package which

will install HA via the following:

wget -cq --show-progress https://github.com/home-assistant/supervised-installer/releases/latest/download/homeassistant-supervised.deb

sudo dpkg -i homeassistant-supervised.deb

A menu will pop up and you need to select the correct board type (raspberrypi3-64). This will indicate a reboot is required, but that’s not the case as we rebooted above.

At this point it’ll take a while for all the home assistant docker containers to download and be installed. In your pi command window you can do:

watch sudo netstat -lntp

Once you see services listening on ports 4357, 8123 and 40000 your system should be up and running. This will take a while, like 12 minutes or more, as the system is downloading all the docker containers required for home assistant. Once you see port 8123 is up and running you can actually move to the next step, as the web page presented will refresh once everything is up and running.

Use your web browser to connect with your smart house controller IP address using http on port 8123. Something like http://IPADDRESS:8123/. Alternatively you should be able to use http://ha-ctrlXX:8123/, where XX is your assigned number.

In the screen presented to the web browser you need to set up an account. Set the username to ha and the password to homeassistant and then click the “CREATE ACCOUNT” button.

On this next screen fill in the settings as you fell is appropriate. Alternatively you can use the DETECT link to automatically set the values. After configuring the values use the NEXT link to continue:

Click Next again to leave the analytics settings off, then click FINISH. You shoud now have access to the full home assistant interface.

Connect a smart switch

The Home Assistant controller applications communicates with other smart devices using integrations. To select the intergation that enables us to connect to the smart switch click on “Settings” in the menu down the left side of the web interface.

From the new menu in the center of the page select “Devices & Services”. All of the smart devices that have been discovered on your network will be displayed. The shelly1 device is the smare switch controlling the flashing light. Click the “CONFIGURE” button associated with the Discovered shelly1 device.

The pop up is to verify you want to configure this device, click “SUBMIT”.

The next creen shows an “Area” pull down. Click the triangle and select “Add a new area”.

Enter classroom and click “ADD”.

Click “FINISH”

You should see you now have a sheely1 entry that is no longer tagged as Discovered, which shows 1 device and 6 entities. The most important thing this added was a switch. On the left hand menu click on “Overview”.

You should now see a toggle switch entry for the shelly device. Flip the toggle to verify you can turn the ligh on and off. When your done leave the light off.

We can change the name of the switch so it’s something more meaningful Click on the switch name and it’ll bring up a pop up menu. Click the “SETTINGS” tab in this pop up. In the Name field enter “Red Light” and click “UPDATE”.

You’ve just competed your first integration of a smart device with your smart home controller.

Connect smart Plug

The switch we’re using is a TP-LINK Kasa HS103 smart switch. We need to add an intergation to access this switch. From the left hand menu select “Settings” and then “Devices & Services”

Click the “ADD INTEGRATION” button at the bottom right of the interface.

In the search field enter kas and then click on the tp-link integration.

Click the SUBMIT link.

The device demo should show up, so then click the SUBMIT link again.

Click the triangle on the Area field and select classroom.

The click the FINISH link.

This adds the tp-link intergation with one device. Click the “1 device” link. You should see a “Controls” area with a toggle switch to turn this plug on and off.

In the left hand menu select “Overview”.

You should see demo had been added here. You can use the toggle to turn the light plugged into the switch on and off. When done leave the light off.

Connect to FOSCAM IP camera

Select Settings off left hand menu and then “Devices & Services”

Select the “ADD INTEGRATION” button in the bottome right corner

Search for foscam in the popup

Click on Foscam and then fill in the following

Host: 192.168.0.5

Username: cp

Password: cyber!

RTSP port: 88

Click on “Submit” and you should get a Success message, then click on “FINISH”

On the screen showing integrations you should FOSCAM with a “1 entity” hyper link. Click on the link. This screen should show the associated camera entity

Click on the Camera icon and then the “INFO” tab and you should see the video stream from the camera

Click the x to close the camera stream

In the left hand menu select Overview. By default all new entities are added to the “Overview: screen

You can click the foscam-demo area to get the live camera stream again.

Setting up ESPHome to run on your laptop

This link https://esphome.io/guides/installing_esphome.html has the instructions for doing a manual install of ESPhome on Windows. Follow them and install python, wheel and esphome on your laptop.

Adding driver for USB to TTL device on laptop

Plug your USB to TTL device into one of the USB ports on your laptop. Bring up device manager app. You should see an unknown device. If you right click on the unknown device you should get an option to update driver, select it and then click on the option to automatically search for update driver. This should download and install the Silicon Labs CP2010x driver. Once the driver updates the TTL device will now show up under Ports (COM & LPT).

Build a doorbell camera with an ESP32-CAM micro controller

This portion of the exercise has you wire together components to make a doorbell camera. It uses an ESP32-CAM micro controller board enabling the device to work disconnected from the Smart House controller. When complete it should look something like this. That’s a lot of wires.

The components used are

Male to female wires 3 white 3 black or blue 1 red Female to female wires 1 black,white,gray,purple 1 white 1 orange or yellow 1 green Breadboard

EPS32-Cam micro controller oard with camera

USB to TTL interface board

Contact sensor

Touch sensor

Motion sensor

Wires

NOTE for wiring: Notice that black connector ends on the wires have a little box opening in them. It will make it easier to connect wires to the pins if these are oriented so that the box faces away from the box on any adjacently connected wires. If you scroll down and look at the pictures you should notice the boxes oriented the same way.

The ESP32-Cam board has an ESP micro controller with multiple general purpose input output (GPIO) pins to enable interfacing with other devices. A number of the GPIO pins are used directly on the board to connect a small camera. The following pinout provides labels for each pin looking at the front of the ESP32 controller. The pin actually stick out the back of the board.

You will be using 12 of the GPIO Pins for this project. You will use color coded wires to help ensure the correct connections are made.

We start by wiring the USB to TTL board to the micro controller:

With the micro controller board facing you as in the pinout picture above, you need to connect three wires on the right side of the ESP32 board and one on the left side of the ESP32 board. The wire colors are hard to see in the pictures here but the order: black, white, gray, purple and blue.

White wire to the bottom ground (GND) pin on the right side

Grey wire above white on Transmit Data pin (GPIO 1) on the right side

Purple wire above gray on Receive Data pin (GPIO 3) on the right side

Black wire to power pin (5V) , top pin on left hand side of board

The blue wire is not used.

Then you need to connect the other end of these 4 wires to the USB to TTL board.

Black to power (5V)

White to ground (GND)

Purple to Transmit Data (TXD)

Grey to Receive Data (RXD)

The blue wire is not used

On the ESP board you need to connect two pins that puts the board in flash mode. Flash mode allows you to update the existing software. This connection is temporary and will be removed once you go to program the board. These two pins are on the same side of the ESP board as the 3 wires we connected to the USB to TTL board.

White loop-back from GPIO 0 to GND to enable flash mode

The last wire on this side of the ESP board you need to connect is a black or blue wire to move power from the ESP board to the breadboard.

Black or blue wire from yellow 3.3v/5v pin on ESP board to the 2nd column 5th row of the breadboard.

Flip the ESP board over and add a white wire from ground pin of the ESP board to the breadboard.

White wire from ground (GND) pin on ESP board to the 1st column 5th row of the breadboard.

The next pin will provide signal to turn on a light.

Red wire from ESP board GPIO 12 pin to 5th column 1st row of the breadboard

On the breadboard you need to add a resistor that will be inline with an LED light. The resistor keeps the LED light from drawing too much power and burning out. Resistors are not directional so just plug either end into the locations indicated.

Resistor side one into 1st column 4th row, the other side to 4th column 4th row.

The LED light now goes on the breadboard. Power will be send from the ESP board over the red wire. It then needs to hit the positive pin on the LED. The longer pin is the positive side. The negative side will then connect to the resistor, which then connects to ground on the ESP board. This completes the light circuit.

LED light positive side to 5th column 3rd row, negative side to 4th column 3rd row.

You have a contract sensor with yellow wire ends. When the two sides of the contact sensor are together the circuit is closed, when they are separated the circuit is open. Connect this wire from the ESP board to the breadboard.

Yellow wire from ESP board GPIO 13 pin to breadboard 1st column 3rd row.

You have a touch button that has three pins. One sends a signal when it is touched, one provides this board power and one connects this board to ground. We start by connecting the green signal line.

Green wire from ESP board GPIO 15 pin to SIG pin on touch sensor.

You have a motion detector that has three pins. One sends a signal when motion is detect, one provides the motion detector power and one connects it to ground. We start by connecting the orange or yellow signal line.

Orange or yellow wire from ESP board GPIO 14 pin to SIG pin on touch sensor.

We need to provide power and ground to the touch and motion sensors. So we add 4 wires, two for the touch sensor and two for the motion sensor.

Two white wires in breadboard column 1 rows 1 and 2

the other end of one white wire to ground pin on the touch sensor

the other end of one white wire to ground pin on the motion sensor

Two black or blue wires in breadboard column 2 rows 1 and 2

the other end of one black or blue wire to vcc pin on the touch sensor

the other end of one black or blue wire to vcc pin on the motion sensor

At this point everything should be wired together.

Load the initial ESP32-Cam firmware

We start by verifying the USB board is detected on the laptop. So in the application search window of your laptop enter device and then bring up the “Device Manager”. Once it’s up look to see if you have “Ports (COM &LPT)” in the list. If it exist then click the > sign in front of Ports to shows you the existing devices. The end of the line should have COM# where # is a number. If Ports isn’t in the list then Ports should show up once you insert the USB to TTL device. Now plug your USB to TTL device into your laptop. If all goes well a device should show up under Ports in the device manager. If it doesn’t talk with the mentor.

If the COM port is detected on your laptop you can now disconnect one side of the flash enable white wire. This is the loop-back wire on the ESP board that connect GPIO 0 to GND. You do this with the USB to TTL still plugged into your laptop so the ESP board has power. Hold the ESP board on it’s edge so not to short the board out and disconnect one end of the wire.

Start notepad and create a file name my-esp.txt in your Documents directory with the following contents. You must replace the two instances of XX in the first three lines with your assigned number. You must also replace SSID with CP_WIFI and PASS_PHRASE with cyberpatriot

# Replace XX in esphome_name and camera_name with your assigned number

substitutions:

esphome_name: dteamXX-mc

camera_name: dteamXX-camera

esphome:

name: "${esphome_name}"

platform: ESP32

board: esp32cam

# Enable Home Assistant API

api:

encryption:

key: "Z4bi9B/TAJg+UbUTdi5gMQmNj7eVdA0MiT9N/FxQ9MA="

ota:

password: "ac218c0e977817a53a6a030f79bf9541"

# Update your WiFi information

wifi:

ssid: "SSID"

password: "PASS_PHRASE"

# Enable fallback hotspot (captive portal) in case wifi connection fails

ap:

ssid: "${esphome_name} hotspot"

password: "EE4ci2HjySQG"

captive_portal:

time:

- platform: homeassistant

# Enable Web server.

web_server:

port: 80

logger:

# Text sensors with general information.

text_sensor:

# Expose ESPHome version as sensor.

- platform: version

name: "${esphome_name} ESPhome ver"

# Expose WiFi information as sensors.

- platform: wifi_info

ip_address:

name: "${esphome_name} IP"

ssid:

name: "${esphome_name} SSID"

sensor:

# General

- platform: uptime

name: "${esphome_name} - Uptime Sensor"

- platform: wifi_signal

name: "${esphome_name} - WiFi Signal"

update_interval: 60s

Start a cmd command prompt on the windows machine and run:

esphome run Documents\my-esp.txt

The above command may hit a point where you will need to select to update the ESP via a COM port or Over the air. For the initial image you want to use the COM port. You enter the number in front of the COM port line that matches the COM port you saw in the “Device Manager” when you plugged in the USB to TTL board. Once you’ve done this you should see that the command is updating flash on the ESP32.

The above will end by indicating it is doing a hard reset via RTS pin, which it can’t do. There is a reset button on the back side of the ESP32 module that you need to push. Hold the ESP board via all the wires and push the reset button.

Button

When the ESP32 reboots it’ll print out a bunch of lines. Some that are in purple will indicate if the device connected to the WiFi you programmed in above. Assuming it connected to the WiFi you can verify it’s on the network by first bringing up another cmd command window and running: ping dteamXX-mc.local

With the XX replaced by your assigned number. If the ping doesn’t work talk with the mentor.

You should also be able to use your web browser to access http://dteamXX-mc.local, with the XX replaced by your assigned number.. The web browser should provide a screen like this:

Add ESP code to control the LED light on the breadboard

Assuming that’s all good let’s add some additional code to the my-esp.txt file to enable control of our LED. Use notepad to edit my-esp.txt and add the following to the bottom of the file:

## Global to store the on/off state of the light

globals:

- id: mylight

type: bool

restore_value: true

initial_value: 'true'

switch:

- platform: gpio

name: "${camera_name} flash"

pin: 4

#inverted: True

- platform: restart

name: "${esphome_name} - Restart"

id: restart_switch

## Switch to turn on/off the mylight.

- platform: gpio

id: mylight_switch

restore_mode: RESTORE_DEFAULT_OFF

# inverted: true

name: LightCTRL mylight

pin: GPIO12

## Switch to turn on/off mylight when

## one of our sensors turn on.

##

## It creates a "virtual" switch based

## on a global variable.

- platform: template

name: LightCTRL mylight Active

id: mylight_active

restore_state: false

turn_on_action:

- globals.set:

id: mylight

value: 'true'

turn_off_action:

- globals.set:

id: mylight

value: 'false'

lambda: |-

return id(mylight);

Save the above and then in a windows cmd prompt load it to you ESP via: esphome run Documents\my-esp.txt

If asked how to upload the firmware you want to select the over the air option this time.

Once it’s been updated you can refresh your web browser access to dteamXX-mc.local and you should see something like this:

LightCTRL mylight should allow you to turn the LED on and off.

LightCtrl mylight Active doesn’t do anything at this time. This switch allows you to disable the button and contact sensors once we’ve added the software for them.

The ESP32-Cam has a built in LED which can be turned on and off with the dteamXX-camera flash toggle.

Finally the dteamXX-mc – Restart gives a toggle to restart your ESP32 board if you so desire.

Add ESP code to enable contact sensor and button

If you can successfully turn the light on and off then add code to the text file to enable the contact sensor and push button. Add the following lines to the end of my-esp.txt:

## Binary sensors

binary_sensor:

# Contact state sensor.

- platform: gpio

id: contact

name: Contact State

pin:

# Connected to GPIO on the ESP-01S.

number: GPIO13

mode: INPUT_PULLUP

# inverted: true

filters:

# Small filter, to debounce the contact state change.

- delayed_on: 25ms

#- delayed_off: 25ms

# on close set longer delay so light doesn't go off immediately

- delayed_off: 3000ms

on_press:

# Only turn on the mylight when contact open.

then:

if:

condition:

- switch.is_on: mylight_active

then:

- logger.log: "Contact open turn on light"

- switch.turn_on: mylight_switch

on_release:

# On contact close, turn of the mylight.

# as long as button is off

then:

if:

condition:

- binary_sensor.is_off: button

then:

- logger.log: "Contact closed turn off light"

- switch.turn_off: mylight_switch

- platform: gpio

# Contact state sensor.

id: button

name: Button State

pin:

# Connected to GPIO on the ESP-01S.

number: GPIO15

mode: INPUT_PULLUP

filters:

# Small filter, to debounce the spurious events.

- delayed_on: 25ms

# delay to handle motion turning off before coming on again

- delayed_off: 25ms

on_press:

# Only turn on the mylight when motion detected.

then:

if:

condition:

- switch.is_on: mylight_active

then:

- logger.log: "Button pushed turn on light"

- switch.turn_on: mylight_switch

on_release:

# On contact close, turn of the mylight.

# as long as contact sensor is off

then:

if:

condition:

- binary_sensor.is_off: contact

then:

- logger.log: "Button pushed turn off light"

- switch.turn_off: mylight_switch

Save the above and then in a windows cmd prompt load it to you ESP via: esphome run Documents\my-esp.txt

If asked how to upload the firmware you want to select the over the air option.

Once the ESP32 firmware has been updated you can refresh your web browser access to dteamXX-mc.local and you should see something like this:

Notice the new Button and Contact State lines. Move the white magnet away from the contact sensor and then place it back by the contact sensor. As you do this watch the state for “Contact State” with the contact sensor and you should see the “State” for Contact sensor changing between NO and OFF. It should also turn the LED light on and off. The code to turn the LED off when the contact sensor closes includes a short delay. This is to give you time to turn on another light before the light goes off.

With the contact sensor in an OFF state touch your button and it should go to an ON state and the light should come on.

Now if you change the toggle “LightCTRL mylight Active” to off you will see that the button and contact sensors both still change their states, but the light no longer turns on. You might use a feature like this to disable a doorbell buzzer in the middle of the night. Make sure you set the “LightCTRL mylight Active” toggle back to the ON state and verify you can turn the LED on and off again with the button.

Add ESP code to enable the camera

The final step is to add the code to enable the camera. Add the following lines to my-esp.txt:

esp32_camera:

name: "${camera_name}"

external_clock:

pin: GPIO0

frequency: 20MHz

i2c_pins:

sda: GPIO26

scl: GPIO27

data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]

vsync_pin: GPIO25

href_pin: GPIO23

pixel_clock_pin: GPIO22

power_down_pin: GPIO32

# Image settings

max_framerate: 2 fps # default: 10 fps, max 60

idle_framerate: 0.2 fps # default: 0.1 fps - framerate for 'picture' in HA dashboard

resolution: 800x600 # default: 640x480 (VGA) - higher res requires more memory

jpeg_quality: 10 # 10 (best) to 63 (worst)

Save the above and then in a windows cmd prompt load it to you ESP via: esphome run Documents\my-esp.txt

If asked how to upload the firmware you want to select the over the air option.

Once it’s been updated you can refresh your web browser access to dteamXX-mc.local. No new items have been added but in the message area to the right it should periodically print a message indicating it “Got Image”. We will need to integrate this with Home Assistant to see the camera output.

Additional code is required to add the motion detection sensor. We’ll wait until everything else is up and running as the motion sensor will probably be very noisy with a room full of people.

Connect ESP32 to your Home Assistant instance

The ESP32 camera IOT device is up and running so now we need to connect it to HA. Connect to your HA interface through the web browser via the URL http://ha-ctrlXX.local:8123/, where XX is replaced by your assigned number.

Select the “Setting” link off the left had side Home Assistant menu.

Select “Device & Services”. Most likely you’ll have a Discovered device with the name you placed on your ESP device (dteamXX-mc where XX is your assigned number). As all the students are building the same device you could also see Discovered devices for other students.

Select the “CONFIGURE” button the the Discovered device with your assigned number.

It’ll ask if you want to add it, select “SUBMIT”.

At which point it’ll ask you for the “Encryption key” you placed on the device.

Enter Z4bi9B/TAJg+UbUTdi5gMQmNj7eVdA0MiT9N/FxQ9MA= and click “SUBMIT”

Click the triangle and select classroom for the area.

Finally click the “FINISH” link.

Now you will see the device in the list of devices and it is no longer labeled as Discovered.

Click on the 1_device link on your dteamXX-mc entry.

You have a Controls area where you can turn the lights associated with your doorbell deivce on and off. Try out the toggles.

You have a Sensors area where you can when the button is pushed or the contract sensor is opened. Make sure the state on these sensors change when you touch the button or separate the contact sensor.

You have a Configuration area where you can restart your ESP board. Don’t toggle this.

If you click the Overview option off the left hand menu you should see that all of these controls and sensors have been added to the main page. You also have a way to view the ESP camera stream.

Finalize the doorbell cam using an HA automation to capture a picture when the button is pushed

First we need to create a directory where the camera image can be saved

From the ssh shell on your home assistant controller run the following:

sudo mkdir -p /usr/share/hassio/homeassistant/www/images

Back to your Home Assistant Web interface we want to create an automation to capture the picture

Select “Settings” from the left hand menu

Click “Automations & Scenes”

Click the bottom right “CREATE AUTOMATION” button

Click “Start with an empty automation”

Click “ADD TRIGGER”

Find “State” in list and click on it

In the Entity field type “button” and click on “Button State”

In the “To (optional)” field enter: On

Click “ADD ACTION”

Click on “Call Service”

In Service field type: camera: t

Click on “Camera: Take Snapshot”

Under Targets Click on “Choose entity”

Click on dteamXX-camera where XX is your assigned number

In Filename field enter /config/www/images/doorbell-pic.jpg

At the bottom right click the “SAVE” button

In Name field enter capture-picture-on-button-push

Click the “SAVE” link

We need to have this automation fire off so an image gets saved.

Touch the button on the ESP doorbell camera you built.

From the ssh command window on you HA controller the following should list doorbell-pic.jpg if the automation worked:

ls -l /usr/share/hassio/homeassistant/www/images

You need this image for the next step to work.

We need to restart the HA application. Click “Developer Tools” off the left hand menu.

Click the “RESTART” link on right side of page.

Click RESTART on the pop up

Should see “Connection lost. Reconnecting” at bottom left of web interface.

Once device is back up this message should change to indicate things are coming back up.

Make a generic camera that uses just displays the picture captured above

Select the left hand menu item “Settings”

Select “Devices and Services”

Click the bottom right hand corner “ADD INTEGRATION” button

In the search field type: gen

Click on “Generic Camera”

In the “Still Image URL” field update the XX and enter: http://ha-ctrlXX.local:8123/local/images/doorbell-pic.jpg

Scroll down to the bottom of page and select “SUBMIT”

A picture should be displayed. At bottom of window check “This image looks good” and click “SUBMIT”

Click “FINISH”

See it work

On left hand menu click “Overview” and the new camera ha_ctrlXX_local should be added to the screen.

Click on “Media” in the left hand menu and then “Camera”

Click on the ha_ctrlXX_local camera

Push your button and see the new captured image. The capture is delayed so this product would still need more work.

That said you’re done.

If you like check out the left hand menu :Media then “Text to Speech” and Media then “Radio Browser”.