Raspi IoT

Discourse Forum

Support and discussions on the Forum

Github Repo

Source code on the Github Repo

Hardware #

Software #

raspberry pi setup #

It is not necessary but recommended to perform the install on a new sd card image, that is how these scripts have been tested.

Image creation and ssh connection
  1. download an os from https://www.raspberrypi.org/software/operating-systems/#raspberry-pi-os-32-bit tested with 2021-05-07-raspios-buster-armhf-lite.img

  2. use the Raspberry pi Imager tool to write the image. The tool is available from https://www.raspberrypi.org/software/

  3. eject, then reinsert the sdcard, write a file on root named ssh without extensions Optional: Enable WiFi" Create a file called wpa_supplicant.conf on root

      country=US # Your 2-digit country code
      ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
  4. connect through ethernet, identify the ip from the router connect through ssh with pi and pw raspberry. In case the same raspberry pi was already known under a different host, make sure to delete it from ~/.ssh/known_hosts.

  1. download and run the get_raspi.sh with the following commands
    curl https://raw.githubusercontent.com/HomeSmartMesh/raspi/master/get_raspi.sh -o get_raspi.sh && sudo bash get_raspi.sh
Script Details

The get_raspi.sh script will run the following

  • apt-get update and apt-get upgrade with auto-confirmation -y option
  • install git if not available
  • clone the raspi_iot repo
  • run the raspi/setup.sh script
  1. the setup script will need to be relaunched every time the raspi reboots (2 times)
    cd raspi
    sudo bash setup.sh
Script Details

The raspi/setup.sh script will run the following

  • check if docker is available otherwise install it
  • check if docker-compose is available otherwise install it
  • check if openthread is available otherwise install it
  • if any or all of the services above were install a reboot will be performed before continuing, in which case the script has to be run again manually
  • when the script is run and all of the above services are availalble, the script will proceed with the last step of launching the setup_thread_services.sh

The setup_thread_services.sh script will perform the following

  • start the docker compose file that includes docker images for mosquitto, influx and grafana
    • the grafana container have the config and provisioning mapped from the raspi grafana directory
    • the grafana has porivioned the databse mqtt from http://localhost:8086
  • install the influx_mqtt which is an mqtt to influx python service, then creates an influx databse named mqtt
  • install the thread_tags udp-v6 to mqtt python service

Openthread Network Configuration #

  • discover the raspi ip address from the router (will be used to replace <raspi_ip>) then navigate on a browser on http://<raspi_ip>, the OT Border Router web GUI should appear. Use it to form a network e.g. (channel 18, panid 0x4412,…). Make sure that the same parameters are used in the thread sensor tag firmware.

  • the grafana dashboard SensorTag Compare should be accessible from http://<raspi_ip>:3000

Meta website #

What is it ? #

  • Hugo : a website as easy to customise as writing markdown
  • Menu : All webapps and websites can be organised in a hierarchical menu
  • Full screen : Each website is embedded on an iframe that can toggle to full screen mode or open in a new page

How does it work ? #

  • create a new file : homeassistant.md
  • call hugo server to test or hugo to generate the website (more details on using hugo)
  • this will already create a new menu entry
  • Fill it with the link to your webapp instance
  • weight : defines the order in the menu entry
  • title : The text that will appear on the menu entry
  • BookToC : Table Of Content not required so that the iframe can be wider
  • ...{< iframe... : call of the iframe html shortcode file that has been added in the layouts\shortcodes directory

Demo video #

Smart home 3D webapp #

Attempt to unify interfaces in one app. Result is quite a success though requires a beast GPU and quite some effort to arrange 3D details and camera positioning to get a nice user experiance out of it.

thread tags #

this python script listens to an ipv6 udp port and takes a text in the form of mqtt_topic{json_payload} then broadcasts the json_payload on the mqtt_topic of the configured mqtt broquer in the config.json file

usage with a thread sensor gag

Led Panel webapp #

mqtt2influx #

Features :

        "subscriptions":[   "lzig/living heat",
                            "+/bed weather",
                            "lzig/bedroom heat",
                            "+/balcony window left",
  • names : replace long topic names with friendly names
            "shellies/shellyplug-s-01E2B5/relay/0/power":"shelly dryer",
  • types : types enfrorcement : this is an influx design/limitation that it is not possible to change the type after creation, in case a float starts with a round number it locks the type. By using this feature the type is ensured to be correct from the first post.
            "energy"      :"int",
            "power"      :"float",
            "pressure"      :"float",
  • discard : make sure unwanted data from specific fields are excluded from the influx post although belonging to the wanted topics
  • log : a log file with a log level
  • last_seen fitering : mqtt allows persistance of values needed for displaying all sensor values for newly connected clients. This might have the side effect of re-injecting the same old values to the influx database in case of restart of the client. It is possible to avoid that by using this feature that filter posts which last_seen field, in case it exists, is fresh and not old.

Home heating app #

web heat control #

The control of the heating has a feedback that ensures the execution of the command. The green displayed numbers represent the time since the last status of the zigbee device. Once a slider is modified and a command is sent, a feedback shall be received within few seconds and the time since last message should drop to 0 mn

python heat windows monitor #

  1. adjust your mqtt configuration in config.json
  2. adjust the eurotronic heater topic and apertures (apertures are the contact sensors list)
        "living heat":{
            "topic":"lzig/living heat/set",
                "balcony door",
                "balcony window right",
                "balcony window left"
  1. add the contact sensors to the mqtt subscriptions as well
  2. run the script python raspi/heat.py

example eurotronic mqtt payload

zig/living heat {

docu references #

Bed Heating app #

Bed Heating hardware #

Roborock chat #

Hue Light control #

  • Controls all the Hue light bulbs from Aquara sensor switches using the HUE rest API
  • custom functions
    • Long press for minimal dimming
    • Toggle on of or Toggle dim states
Config example. Click for details...
                            "mzig/bed light button",
                            "mzig/bed nic button",
                            "mzig/living double switch",
                            "lzig/bedroom switch",
                            "lzig/volume white",
                            "lzig/office switch",
                            "lzig/hallway entrance switch",
                            "lzig/hallway living switch",
                            "lzig/hallway corridor switch"
        "actions"   :[],
        "publish" :true,
        "subscribe" :true
                "hallway entrance switch",
                "hallway living switch",
                "hallway corridor switch"
                "Entrance White 1",
                "Entrance White 2",
                "Entrance White 3"

Phantom Load cut #

  • Some home devices especially device clusters such as TV sets and surroundings or PC and surroundings do have a significant cumulated power usage when in a standby mode.
  • Who likes to pay money for non used electricity ?
  • Who likes to keep remembering each time and toggling switching on locations hard to access ?
  • This scrips js/pc_control comes to the rescue and does this for you in a smart way.

Features #

  • configurable standby power level. For example a TV set with sound system consumes 100 W to 200 W but when on standby, still ~ 11 W
  • a shelly socket provides a real time power usage through mqtt
  • if the device is in standby < 12 W for more than 5 min, the shelly device is ordered to cut the power resulting in 1 W for the shelly device power usage (wifi connection). Therefore a permanent 10 W is saved.
  • Low Motion sensors attached to the chair or to the remote control order the shelly to switch on again. False positive is not a problem and only costs 10W standby consumption for 5 more min before cutting again.
  • If the TV started really to be used and power is > 12 W, then the standby power cut system is not doing anything so that the user enjoys watching TV until the next TV switch off cycle.

Heat cut #

  • Hackaday page : Aquara and Eurotronics hand in hand to save energy

  • Opening a window without remembering to switch the heating off can cost a peak of heat that consists of the major power cost of the whole day !

  • The smart detection based on temperature drop is no reliable and only acts late sometimes when not necessary.

  • With a simple aquara contact switch the system is now reliable

  • Python service : py/heating

Home status #

  • Leaving home, in a hurry, no time to walk through the house or to start smartphone apps to know if the heating is forgotten in one room or if a window is left open in another.
  • With this script, you see the home status right next to the house door before leaving
  • Any window is open : The status light is blue
  • Any heater is active : The status is red
  • Both red and blue can be combined

How does this work. In a controlled environemnt where the wifi is reliable, there is no need for wifi status as it is always on. Therefore the led status disable function can be re-used for another purpose. This provide the nicest integration of led status including power supply, mqtt connection without even blocking the socket for other usage.

Below are the control URLs to turn led color on and off

json Config example. Click for details...

Roborock button #

As Roborock valetudo provides an mqtt interface, all it takes is this script py/hover to order cleaning of a room or a section with a click on an aquara zigbee button.

zigbee/graphview #

  • Github repo directory
  • js library used to generate SVG from graph
  • the js library is a port of the graphviz project
  • An alternative that is also configure in this project’s docker-compose file is to use Zigbee2Mqtt-Assistant which in addition to providing a nice devices listing and control also offers a graph view of the network

Gif Demo #

Features #

Safety warning #

  • Power Sockets have deadly voltage and should not be self altered
  • Usage of certified products such as Shelly or others is recommended for any high voltage product
  • hacking custom scripts to control equipment might improve safety in case you add power cut off to a lower power for each section and device, but might also alter your food if your fridge inadvertantly goes off due to a wrong configuration
    • reboot state
    • safety power too low
  • Any heat power control custom script must necessarily have another safe switch to fully cut the power when away or device is inattended.

FAQ - Discussion #

how does the Raspi-IoT framework compare to existing frameworks like home assistant or OpenHAB
Raspi-IoT is intended for developpers that prefer to stick to standard scripting like Python or Node.js and would like to use a minimalistic framework where everything can be debugged with standard tools, and also for sutdents and startups who would like to understand the underlaying techniques of home automation and IoT in order to create their own projects or products.