Linux Format

Build a smart home

Use ESPHome to feed a wide range of useful data to a smart home hub via a Raspberry Pi Pico W.

-

ESPHome was originally written to allow the ESP8266 and ESP32 devices to easily interact with Home Assistant. Using YAML syntax, the required options and configurat­ion can be written, then parsed and used to create source code, which is cross-compiled and uploaded to the devices. With the release of the 2022.11 version, developmen­tal support has been added for Raspberry Pi Pico W boards.

In this project we’re creating a program that enables us to read the temperatur­e from a DS18B20 sensor, report it to Home Assistant and flash the internal LED on the board via a switch in Home Assistant’s web GUI.

To begin, we need to set up Home Assistant and enable the ESPHome add-on. The easiest way to run the software is to install it on a microSD card, which is then inserted into a Raspberry Pi. If using this option, download the image from www.home-assistant.io/ installati­on, follow the instructio­ns in the build your own Wi-Fi router article (page 36), and select the custom image that has been downloaded. Alternativ­ely, use the generic x86-64 image and install it as a VM on your laptop or PC. Once installed and running, follow the onboarding instructio­ns to finish the installati­on: https://bit.ly/lxf298onbo­ard. Once done, use the My Add-On link (https://bit.ly/lxf298addo­n), which makes installati­on of the add-on a lot easier. Once you are logged into Home Assistant, select the option to install the add-on, start it at boot and enable the watchdog. Start the add-on and select the Open Web UI link.

Before creating your device, select the Secrets link and add these options, then save and close the file:

wifi_ssid: ADD_SSID wifi_password: ADD_PASSWORD

We will now create a new device and add some code to it. Click on New Device, then Continue and enter a name, which will be shown in the ESPHome dashboard. When asked to select the board type, click on Raspberry Pi Pico W and then select Next. Once created, select Skip and then click the Edit button on the new device. At the bottom of the file, add the following lines: dallas:

- pin: GPIO1 sensor:

# - platform: dallas

# address: ADD_HEXADDRESS # unit_of_measuremen­t: “°C”

# name: “Temperatur­e” output:

- platform: gpio pin: 32 id: ‘output_component1’ light:

- platform: binary name: “State LED” output: output_component1

Now save the file and click on the Install button. When asked, select manual download. Once the compilatio­n has completed, download the file and connect the Raspberry Pi Pico W to your PC or laptop with the Bootsel button pressed down. Copy the downloaded UF2 file to the new drive that has appeared on your device. When the file has copied and the device has rebooted, it connects to the Wi-Fi and then ESPHome. The device then shows as online and is available to be added to the Home Assistant dashboard. A notificati­on is displayed on the sidebar and by selecting this and using the API password from the file we edited earlier, it is added. Note the commented lines in the file – these need to be uncommente­d and the address replaced once the Logs option has been selected from ESPHome and the address found from this page. When the sensor’s address has been changed, the lines uncommente­d and the file saved again, click on Install and this time the Wirelessly option can be used.

Finally, from Home Assistant, navigate to the Settings > Devices & Services page and under the ESPHome option, select the name of your newly created device and then 1 Device. From this page, you can see the measured temperatur­e, and by toggling the switch, the on-board LED switches on and off.

 ?? ?? Use this circuit diagram to connect the temperatur­e sensor.
Use this circuit diagram to connect the temperatur­e sensor.
 ?? ?? The dashboard created by adding the integratio­n can be seen here. Temperatur­e informatio­n can now be used in automation­s and Home Assistant dashboards.
The dashboard created by adding the integratio­n can be seen here. Temperatur­e informatio­n can now be used in automation­s and Home Assistant dashboards.
 ?? ??

Newspapers in English

Newspapers from Australia