Tag Archives: ESPHome

Using voice commands to control Home Assistant. Part 2

Today, we continue setting up voice control in Home Assistant. This time, we will need a small yet cheap device with a speaker and a microphone “on board.” Let’s assume all the initial settings I wrote about here have been applied.

Setting up and flashing firmware on the ATOM Echo

You will need a device which you can buy here and here, approximately, it only costs 13$.

Follow this link, and you will see the “CONNECT” button.

Connect the ATOM Echo to the computer using USB and click the “CONNECT” button.

If you haven’t downloaded the firmware for similar devices, you might not have the USB driver installed. A pop-up window will only show the standard COM-port.

Click “Cancel,” and you will see a pop-up window where you can install the USB driver.

Install the driver for CH342 devices. Only after you do so will the required port show up. Select it and click the “Connect” button.

Select “INSTALL VOICE ASSISTANT.”

The process of flashing the firmware will now start. Do not close the page while the firmware is flashing.

After the installation finishes, click “NEXT.”

You need to enter the credentials of your Wi-Fi network in the next step.

Click “ADD TO HOME ASSISTANT” to add the device. A new window should show up, advising you to add an ESPHome integration if you don’t have it yet.

After you add the device, you can choose a room or zone for the device.

The image below shows the ATOM Echo in the list of ESPhome devices.

In ESPHome, you need to “ADOPT” the ATOM Echo, after which you should update the firmware to the latest version.

You now have all the sensors and control elements in the integration. From the drop-down list, select the language model created earlier, click ATOM Echo button, and give a command to Home Assistant. Everything should work as intended.

Setting up the wake word

With the latest Home Assistant update, you can activate your “smart speaker” without physical intervention. It’s not difficult to do. Open the add-on store (or click the button below).

Install the openWakeWord add-on, and click “Start” afterward. The add-on doesn’t need setting up.

After installing the add-on, open the Integrations settings.

Go to voice assistants and click the one you want to edit.

In the pop-up window, select Wake word engine and the wake word from the list to the right. Click “Update.”

The last thing you should do is check if the wake word is on for the ATOM Echo. After you turn on “Use wake word,” your speaker will light up with a lilac color, which means it’s waiting for your voice command. Below in the drop-down list, you can select a voice assistant the device will use.

In future reviews, I will show how to make a custom wake word, so stay tuned. See you.

Setting up Lovelace UI on NSPanel

In one of my previous articles, I introduced you to a way to flash NSPanel for better compatibility with Home Assistant. We used ESPhome as a basis, which controlled the ESP32 controller. But we left the firmware of the device screen unchanged, which allowed us not to change the appearance. In turn, the screen with the microcontroller “communicated” with each other using the NSPanel Protocol.

I suppose that someone may not like the standard NSPanel interface. Perhaps you will not even be satisfied with the limited number of screens. Let me remind you that you can switch interface screens using swipes. There are only three of them.

That is why today, I offer you a way to change the NSPanel interface to an alternative one called NSPanel Lovelace UI.

Preparing and flashing NSPanel

I chose Tasmota as the main firmware in NSPanel Lovelace UI. Although it is possible to add an ESPHome component, I didn’t succeed with ESPHome and decided to configure Tasmota. That’s why I’ll tell you about this particular firmware.

So, let’s start with flashing Tasmota firmware to the ESP32 controller in NSPanel. If you, like me, have already installed ESPHome on this device, the easiest way is to “update” over the air (OTA). Go to the NSPanel web interface, select the previously downloaded firmware file from your computer at the bottom of the page and click “Update.” After about a minute, the device will reboot with the new Tasmota firmware.

upload firmware Esphome

If you still have the original “factory new” firmware, you will have to disassemble the NSPanel and download the Tasmota firmware using a USB device, sometimes called a TTL converter. I already told you how to do it in this article.

After flashing and rebooting the device, the microcontroller will not connect to your Wi-Fi because it does not know anything about it yet. It will create its own open Wi-Fi access point with the word Tasmota in the name. Then, connect your smartphone to the network and enter the address 192.168.4.1 in your browser, the temporary address of our NSPanel. Here you can choose your Wi-Fi network and save your password. Save the settings. After rebooting, the NSPanel will connect to your Wi-Fi. I highly recommend specifying a static address for our device in the router settings.

Configuring NSPanel with Tasmota firmware

The first thing to do is to specify a device template for Tasmota. To do this, go to the device’s IP address in the browser. In “Configuration,” click Configure Other and paste the following template code:

{"NAME":"NSPanel","GPIO":[0,0,0,0,3872,0,0,0,0,0,32,0,0,0,0,225,0,480,224,1,0,0,0,33,0,0,0,0,0,0,0,0,0,0,4736,0],"FLAG":0,"BASE":1,"CMND":"ADCParam 2,11200,10000,3950 | Sleep 0 | BuzzerPWM 1"}

Don’t forget to leave the “Activate” checkbox.

Download Berry Driver in Tasmota

  1. Download the autoexec.be file from the Berry Driver repository.
  2. In Tasmota, go to Consoles > Manage File System and download the previously specified file.
  3. Reboot your NSPanel.

Updating the Nextion screen firmware on NSPanel

Now let’s update the screen firmware. To do this, in Tasmota, go to Consoles > Console and, depending on the version, use one of the following commands:

EU Version: FlashNextion http://nspanel.pky.eu/lui-release.tft
US Version Portrait: FlashNextion http://nspanel.pky.eu/lui-us-p-release.tft
US Version Landscape: FlashNextion http://nspanel.pky.eu/lui-us-l-release.tft

Press “Enter.” The firmware download and screen flashing will start. Depending on the network speed, the process may take five minutes. Wait until the download is finished and reboot the device.

Setting up Home Assistant

Installing the AppDaemon plugin

The easiest way to install AppDaemon is through the Home Assistant Supervisor Add-on Store. It will connect automatically to your Home Assistant instance.

Adding the babel package to AppDaemon (optional)

To localize the interface (date in your language), add the babel package to your AppDaemon. In the AppDaemon settings tab, in the python packages field, enter the text “babel” and save the settings.

Installing Studio Code Server and Home Assistant Community Store

To configure the NSPanel Lovelace UI, you will need to edit the apps.yaml file. Editing yaml files will be more convenient in the Studio Code Server interface.

HACS is the Home Assistant community store that will allow you to easily update integrations and community automation through the Home Assistant web user interface. You will get notified about updates. You can install them by simply clicking a button. I already wrote about how to install HACS in my previous articles.

Install Lovelace AppDaemon Backend Application

  1. Click on the Home Assistant web interface on the left menu bar on HACS.
  2. Click “Automations” on the right panel.
  3. In the lower right corner, click “Explore & download repositories.”
  4. Type NSPanel and click NSPanel Lovelace UI Backend in the list that appears.
  5. In the bottom right corner of the panel, click “Download this repository with HACS.”
  6. Now a confirmation panel will appear. Click “Download” and wait for the download.
  7. You now installed The Backend Application, and HACS will notify you when updates are available.

Configure MQTT on Tasmota and in AppDaemon configuration

First, set up a connection to your MQTT server in Tasmota.

Please fill in the “Topic” field as it will be in the configuration. Change “Topic” to something unique for your device, you’ll need it later in the appdaemon/apps.yaml settings.

Now configure the MQTT connection in the AppDaemon configuration file. Please add your MQTT server configuration, user, and password to appdaemon.yaml. Then restart the AppDaemon container after adding the MQTT configuration. You will find this file here: config/appdaemon/appdeamon.yaml
secrets: /config/secrets.yaml

appdaemon:
  latitude: 52.0
  longitude: 4.0
  elevation: 2
  time_zone: Europe/Berlin
  plugins:
    HASS:
      type: hass
    MQTT:
      type: mqtt
      namespace: mqtt
      client_id: "appdaemon"
      client_host: 192.168.75.30
      client_port: 1883
      client_user: "mqttuser"
      client_password: "mqttpassword"
      client_topics: NONE
http:
  url: http://127.0.0.1:5050
admin:
api:
hadashboard:

Configure NSPanel in AppDaemon

Add the following minimum configuration to the apps.yaml file located in config/appdaemon/apps/apps.yaml

nspanel-1:
  module: nspanel-lovelace-ui
  class: NsPanelLovelaceUIManager
  config:
    panelRecvTopic: "tele/tasmota_your_mqtt_topic/RESULT"
    panelSendTopic: "cmnd/tasmota_your_mqtt_topic/CustomSend"

Specify tasmota_your_mqtt_topic according to the topic used in the Tasmota MQTT configuration.

If your settings and configuration are correct, you should see the following screens on NSPanel:

Getting acquainted with an example of a complete NSPanel Lovelace UI configuration

Below, under the spoiler, you will find the full text from my NSPanel configuration file. Also, look at the images of several interface screens of my particular configuration. You can see the screensaver screen with the weather in the header of this article.


That’s it for today. See you!

P.S.

After pressing the switch button, the relay response time of the device with Tasmota firmware became a little longer than it was with ESPhome. Perhaps the reason is that NSPanel is waiting for a command to turn on the relay from Home Assistant. At the same time, in ESPHome, all the “magic” happens only in the device without waiting for a response from Home Assistant.

I changed Tasmota on the NSPanel and installed ESPhome with the Lovelace UI component. You can find the ESPhome configuration file in my GitHub repository at this link. I changed Tasmota on the NSPanel and installed ESPhome with the Lovelace UI component. You can find the ESPhome configuration file in my GitHub repository at this link. Now the switches are working quite lively and, frankly speaking, it is more familiar to me to configure ESPhome.

Meeting the NSPanel switch and flashing ESPHome

Last year, the Chinese company Sonoff started crowdfunding, where they presented an interesting smart device. By the end of 2021, Sonoff introduced NSPanel. This device is a rectangular device with a colored touch display sized 3,5 inches and two physical buttons.

The touch display was also created by Sonoff, this is a Nextion model.

There are two versions of the NSPanel, and they differ only in size. One is for the US market, and the other one is for the EU countries. The power and logical parts of the devices are the same. As a “brain“, the company chose the Espressif ESP32-DOWD V3, which allowed working in Wi-Fi 4 802.11n/g/n networks. Bluetooth 4.2/5.x is only used when setting up the device.

Connecting NSPanel to the power grid

To set up and control the device you need to download the eWeLink app, it must be familiar with Sonoff devices owners. If you do not have an account yet, create it, or log onto your account. eWeLink lets you control connected devices from all around the world where the Internet connection is established.

So, to connect the NSPanel on the phone you need to turn on Bluetooth. After that, connect the device to the power grid.

Use safety precautions when working with high voltages!

In the eWeLink app press “add new device“. Then, you will see the device on the screen, tap on it to add it. Then, you may need to enter your Wi-Fi credentials. After connecting, the NSPanel most likely will ask you to update its firmware. Do it, because this update may contain bug fixes or performance improvements. The update may take a while.

The power part of the switch includes two relays that can withstand up to 16A of current. This means that you can connect two additional electric devices. It could be not only lighting devices but also, for example, a warm floor controller. Below is a switch connecting scheme.

Setting up the NSPanel in eWeLink

In the eWeLink application, you can switch one of the switch relays to thermostat mode, then the built-in thermal sensor can control the temperature in the room. For the thermostat, choose the heating or cooling mode depending on the device you want to connect (heater or cooler). Set the target temperature in the room and the device will turn off when it reaches the target temperature.

To reach the thermostat screen on the switch, swipe right on its screen. One more swipe will lead you to widgets. These are pictograms with which you can control other smart devices. This way you can control plugs or bulbs, and also their groups. In addition, you can create widgets to load a scene.

You need to create widgets in the eWeLink app. The max widget number is 8.

To control the device using voice assistants create the appropriate integration in the eWeLink app. In addition, Sonoff allows controlling the switch in a local network, which enables integrations into alternative smart home control systems. Enable the corresponding item in the device settings.

Getting ready to launch ESPHome

I think that this smart device is “smart” only when it can work independently of cloud services. NSPanel can work locally but sadly, its widgets don’t work without a network connection. Essentially, you can only control two relay devices through a local network.

Just as I stated above, the logical part of the switch is a Nextion display that is connected to the esp32 controller. Such a tandem gives us hope for the ability to easily load alternative firmware. And really, “tasmota” firmware already exists for our device, work on creating an NSPanel component for ESPhome is also in full swing.

Let’s look at the PCB of the logic unit. To take it out, lightly press the screwdriver on the groove in the center. Remember to turn off the power beforehand!

Now you need to unscrew two screws that hold the protective plate. After you carefully remove the plate, you will see the PCB with the esp32 controller microcircuit.

You will see 5 contacts in the lower corner. They are marked as 3V3, ESP_TX, ESP_RX, GND, and IO0. The last contact is a “zero” pin controller. To switch the controller to firmware mode, connect it to the neutral wire.

To flash the controller’s firmware, you will need a usb2uart (USB to TTL converter) adapter. Before you connect it to the computer, set the voltage to 3.3V, this is important!

Using Dupont wires, connect the adapter to the PCB: VCC – 3V3, GND – GND, RX – ESP_TX, TX – ESP_RX. Connect the IO0 pin on the PCB to the neutral wire on the contact pad (green wire on the picture)

Pay attention: If the Dupont wire contacts protrude beyond the contact holes on the board, they will touch the metal plate of the display. This can lead to a short circuit and both the USB adapter and NSPanel chips failure! To avoid this, disconnect the display cable and remove the PCB from the chassis.

Downloading ESPHome onto the NSPanel

Now you can confidently download the ESPHome firmware. Connect the USB adapter to the computer, and in the device manager, look what COM port it received. Now, in the ESPHome interface, you can create a new node. To be honest, downloading empty code onto esp32 and then working with the created node using Wi-Fi would be enough. To do this, select the firmware option of the ESP controller connected to the computer. Then, select the COM port in the popup. Downloading the firmware takes a few minutes. The contacts need to stay connected!

After the firmware is loaded, disconnect the wires and assemble the switch. After connecting the NSPanel to the network, you can use the switch just like a regular esp32 controller. Now let’s download an already prepared code.

After reboot, the switch will have a familiar interface. I want to warn you: There’s no official thermostat support, so I didn’t add it in the code. The thermostat, just like some widgets, could be added by JSON requests. The format which JSON should have can be read here. And here you can find another variant of the code, already bundled with some widgets and a thermostat. One thing, you will need to replace the device IDs with yours.

For an example of scene widgets, I added code that will turn off melodies on the built-in NSPanel booster (piezodynamic). You can add and load any scene with Home Assistant.

After the official release of NSPanel components for ESPHome, I plan to update the article, so check for updates. In addition, there is a way to fully change the interface and switch from the NSPanel Protocol, since onboard of the switch we have Nextion display and esp32, but that is a topic for another article.