tech explorers, welcome!

Tag: unihiker

UNIHIKER-PAL: open-source python home assistant simplified

PAL is a simplified version of my python home assistant that I’m running in the DFRobot UNIHIKER which I’m releasing as free open-source.

This is just a demonstration for voice-recognition command-triggering simplicity using python and hopefully will serve as a guide for your own assistant.

Current version: v0.1.0

Features

Current version includes the following:

  • Voice recognition: using open-source SpeechRecognition python library, returns an array of all the recognised audio strings.
  • Weather forecast: using World Meteorological Organization API data, provides today's weather and the forecast for the 3 coming days. Includes WMO weather icons.
  • Local temperature: reads local BMP-280 temperature sensor to provide a room temperature indicator.
  • IoT HTTP commands: basic workflow to control IoT smart home devices using HTTP commands. Currently turns ON and OFF a Shelly2.5 smart switch.
  • Power-save mode: controls brightness to lower power consumption.
  • Connection manager: regularly checks wifi and pings to the internet to restore connection when it's lost.
  • PAL voice samples: cloned voice of PAL from "The Mitchells vs. The Machines" using the AI voice model CoquiAI-TTS v2.
  • UNIHIKER buttons: button A enables a simple menu (this is thought to enable a more complex menu in the future).
  • Touchscreen controls: restore brightness (center), switch program (left) and close program (right), when touching different areas of the screen.

Installation

  1. Install dependencies for voice recognition:
    pip install SpeechRecognition
  2. Download the github repo:
    https://github.com/TheRoam/UNIHIKER-PAL
  3. Upload the files and folders to the UNIHIKER in /root/upload/PAL/
  4. Configure in the script the WIFI credentials, IoT devices, theme, etc.
  5. Run the python script PAL_v010.py from the Mind+ terminal or from the UNIHIKER touch interface.

If you enable Auto boot from the Service Toggle menu , the script will run every time the UNIHIKER is restarted.

https://www.unihiker.com/wiki/faq#Error:%20python3:%20can't%20open%20file…

Configuration

The code includes different configurable aspects:

Theme

Some theme configuration has been enabled by allowing to choose between different eyes as a background image.

Use the variables "eyesA" and "eyesB" specify one of the following values to change the background image expression of PAL:

  • "happy"
  • "angry"
  • "surprised"
  • "sad"

"eyesA" is used as the default background and "eyesB" will be used as a transition when voice recognition is activated and PAL is talking.

The default value for "eyesA" is "surprised" and it will change to "happy" when a command is recognized.

PAL voice

Use the sample audio file "PAL_full" below (also in the github repo in /mp3) as a reference audio for CoquiAI-TTS v2 voice cloning and produce your personalized voices:

https://huggingface.co/spaces/coqui/xtts

Customizable commands

Adding your own commands to PAL is simple using the "comandos" function.

Every audio recognized by SpeechRecognition is sent as a string to the "comandos" function, which then filters the content and triggers one or another matching command.

Just define all the possible strings that could be recognized to trigger your command (note that sometimes SpeechRecognition provides wrong or inaccurate transcriptions).

Then define the command that is triggered if the string is matched.

def comandos(msg):
    # LAMP ON
    if any(keyword in msg for keyword in ["turn on the lamp", "turn the lights on","turn the light on", "turn on the light", "turn on the lights"]):
        turnLAMP("on")
        os.system("aplay '/root/upload/PAL/mp3/Turn_ON_lights.wav'")

Activation keyword

You can customize the keywords or strings that will activate command functions. If any of the keywords in the list is recognized, the whole sentence is sent to the "comandos" function to find any specific command to be triggered.

For the case of PAL v0.1, these are the keywords that activate it (90% it's Paypal):

activate=[
    "hey pal",
    "hey PAL",
    "pal",
    "pall",
    "Pall",
    "hey Pall",
    "Paul",
    "hey Paul",
    "pol",
    "Pol",
    "hey Pol",
    "poll",
    "pause",
    "paypal",
    "PayPal",
    "hey paypal",
    "hey PayPal"
]

You can change this to any other sentence or name, so PAL is activated when you call it by these strings.

Location

The variable "CityID" is used by the WMO API to provide more accurate weather forecast for your location.

Choose one of the available locations from the official list:

https://worldweather.wmo.int/en/json/full_city_list.txt

IoT devices

At the moment, PAL v0.1.0 only includes compatibility with Shelly2.5 for demonstration purposes.

Use variables lampBrand, lampChannel and lampIP to suit your Shelly2.5 configuration.

This is just as an example to show how different devices could be configured. These variables should be used to change the particularities of the HTTP command that is sent to different IoT devices.

More devices will be added in future releases, like Shelly1, ShellyDimmer, Sonoff D1, etc.

Power save mode

Power saving reduces the brightness of the device in order to reduce the power consumption of the UNIHIKER. This is done using the system command "brightness".

Change "ps_mode" variable to enable ("1") or disable ("0") the power-save mode.

Room temperature

Change "room_temp" variable to enable ("1") or disable ("0") the local temperature reading module. This requires a BMP-280 sensor to be installed using the I2C connector.

Check this other post for details on sensor installation:

https://theroamingworkshop.cloud/b/en/2490/

Demo

Below are a few examples of queries and replies from PAL:

"Hey PAL, turn on the lights!"
"Hey PAL, turn the lights off"

Future releases (To-Do list)

I will be developing these features in my personal assistant, and will be updating the open-source release every now and then. Get in touch via github if you have special interest in any of them:

  • Advanced menu: allow configuration and manually triggering commands.
  • IoT devices: include all Shelly and Sonoff HTTP API commands.
  • Time query: requires cloning all number combinations...
  • Wikipedia/browser query: requires real-time voice generation...
  • Improved animations / themes.

Any thoughts, issues or improvements, I'll be happy to read them via github or Twitter!

🐦 @RoamingWorkshop

🌡UNIHIKER real-time temperature sensor set up in 2 minutes

I keep experimenting with the UNIHIKER board by DFRobot and it’s incredibly fast to make things work in it. Today I’ll show you how to set up on-screen real-time temperature display in two minutes using a BMP-280 module and zero programming.

Prerrequisites

Here's the trick. I was expecting you already had a few things working before starting the countdown:

  • Download and install Mind+, DFRobot's IDE for UNIHIKER.
    On Linux, it is a .deb file which does take a while to install:
    https://mindplus.cc/download-en.html
  • Solder a BMP-280 temperature and pressure module and connect it to the I2C cable. You might need to bend your pins slightly as the connector seems to be 1mm nano JST.

You're ready to go!

Set-up

  1. In Mind+, go to the Blocks editor and open the Extensions menu.
  2. Go to the pinpong tab and select the pinpong module (which enables interaction with the UNIHIKER pinout) and the BMP-280 module extension, for interaction with the temperature module.
  1. Go back to the Blocks editor and start building your code block. Just navigate through the different sections on the left hand side and drag all you need below the Python program start block:
    • pinpong - initialize board.
    • bmp280 - initialize module at standard address 0x76.
    • control - forever block (to introduce a while True loop).
    • unihiker - add objects to the display. I firstly add a filled rectangle object to clear previous text, then add a text object. Specify X,Y coordinates where every object will be displayed on the screen and its color.
    • bmp280 - read temperature property. Drag this inside the text field of the text object.
    • python - (optional) add a print to show the data on the terminal. I included all other sensor values.
    • control - add a wait object and wait for 1 second before next loop.
      All of it should look something like this (click to enlarge)

Launch

And that's all your program done, without any programming! Press RUN above and see how it loads and displays in your UNIHIKER screen. Touch the sensor with your finger to see how values change with the increase in temperature.

Wasn't that only 2 minutes? Let me know via Twitter ; )

🐦 @RoamingWorkshop

DFRobot case for UNIHIKER

The small and efficient form factor of the UNIHIKER makes it really easy to craft a case for it.

For my smart home asssistant I was looking for an android-like style, and the DFRobot logo is perfect for the UNIHIKER, making tribute to their developers.

Github Repo

I've released a github repository where I will be open-sourcing all the model files and people can contribute with their own, so feel free to create a pull request and share your designs!

https://github.com/TheRoam/DFRobot-UNIHIKER-case/

It includes a github page where models can be previewed:

https://theroam.github.io/DFRobot-UNIHIKER-case/

Unihiker_DFRcase_v1

This is my first release, used for testing and including all the basic features for my home assistant.

Files

https://github.com/TheRoam/DFRobot-UNIHIKER-case/tree/main/blender

Features

  • Top openings for text display through touch screen.
  • Side opening for USB-C connection.
  • Back opening for external sensor cabling.
  • Back extrusions for 40mm speaker placement.
  • Foot-like support for vertical standing.

Case parts

  1. Bottom piece acts as a casing.
  2. Internal support piece holds UNIHIKER board to the bottom piece using the screws on the board.
  3. Top piece acts as a cover and clips on bottom piece.
  4. Feet support enables vertical standing of the case.
  5. Antennas just to match the deisgn of the DFRobot logo.

Assembly

  1. Place the screws of the internal support piece and screw it to the UNIHIKER
  1. Place the UNIHIKER inside the bottom piece. If you're using external sensors, you can bring your cabling outside using the void at the back.
  1. Hold the board to the case using a pair of 2.5mm screws from the back of the bottom piece.
  1. Fit the top piece in place as it should just hold itself.
  1. Place the feet support and the antennas in place. You can glue these to make sure that they stay in place.

And that's your case crafted with a nice DFRobot android look!

Share your thoughts on Twitter!

🐦 @RoamingWorkshop