Home Webapp
This
mobile first
webapp from the web/home-next directory is based on next.js, react, Material UI and MQTT.js. All of the features are running on a raspberry pi as a server with services from a deployed instance of this repo.- The Heat panel controls the temperature with
Eurotronics
Zigbee valves running on Zigbee2mqtt. The room humidity is also shown from nRF custom sensors - The sound panel controls sonos system to switch it on and off through
Tuya
smart sockets, and it controls the volume through node-sonos-http-api. The sockets can also be controlled with anAqara
button. - The power panel controls
Tuya
smart sockets and displays the power consumption. On and Off images are updated depending on the state. The PC socket is switched on with anAqara
button and switched off with an auto power off pc_control script. - The Ambient Panel is a Grafana dashboard that shows the last day charts of humidity, temperature and light from the nRF custom sensors
- The Energy panels is also a Grafana dashboard that shows cumulated energy for the last 24h or last 30d, combining energy measures from
Shelly plug s
wifi andTuya
zigbee sockets.
Hardware
- Thread
- See Thread SensorTag
- Zigbee
- Hue Light with Hue gateway
- Eurotronics thermostats with zigbee2mqtt
- Aquara sensors with Zigbee2mqtt
- WiFi
- ESP32 bed heater
- ESP32 neopixels led panel
- Shelly power control and monitor
- Roborock with valetudeo server : https://github.com/Hypfer/Valetudo
- Custom RF
- nRF52 sensors with nRF52 Mesh
- ESP32
- led panel : github esp32_iot rgb_led
- bed heating github esp32_iot bed_heater
Software
- Raspbian OS
- Base services
- Mosquitto : from mosquitto.org installed with a docker container
- influxDB : from influxdata.com installed with a docker container
- mqtt2influx : py/influx is a python script service that sends configured mqtt topics to influxdb
- Grafana : from grafana.com installed with a docker container and provisioned with a default datasource and dashboard
- x to mqtt
- Thread UDP to mqtt : thread_tags
- Zigbee2mqtt : https://www.zigbee2mqtt.io/
- nrf2mqtt : github nRF52_Mesh nrf_mesh
- miflora2mqtt : https://github.com/RaymondMouthaan/miflora-mqtt-daemon
- telegram bots2mqtt : js/telegraf based on https://github.com/telegraf/telegraf
- automation services
- Light control : py/hue
- Phantom Load cut : js/pc_control
- Heat cut : py/heating
- Home status : py/home_status
- Roborock button : py/hover
- user interface
- Led panel : js/leds_panel
- Bed heating : js/bed_heating
- Roborock Chat : js/telegraf/hover_poll.js
- others
- graphql sensors : experimental service, details in js/graphql
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.
- use the Raspberry pi Imager tool to write the image. The tool is available from https://www.raspberrypi.org/software/
- eject, then reinsert the sdcard, write a file on root named
ssh
without extensions Optional: Enable WiFi" Create a file calledwpa_supplicant.conf
on rootcountry=US # Your 2-digit country code ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev network={ ssid="YOUR_NETWORK_NAME" psk="YOUR_PASSWORD" key_mgmt=WPA-PSK }
- connect through ethernet, identify the ip from the router connect through ssh with
pi
and pwraspberry
. In case the same raspberry pi was already known under a different host, make sure to delete it from~/.ssh/known_hosts
.
- download and run the
get_raspi.sh
with the following commandscurl https://raw.githubusercontent.com/HomeSmartMesh/raspi/master/get_raspi.sh -o get_raspi.sh && sudo bash get_raspi.sh
- the setup script will need to be relaunched every time the raspi reboots (2 times)
cd raspi sudo bash setup.sh
The
setup_thread_services.sh
script will perform the following- start the docker compose file that includes docker images for
mosquitto
,influx
andgrafana
- the grafana container have the config and provisioning mapped from the raspi
grafana
directory - the grafana has porivioned the databse
mqtt
fromhttp://localhost:8086
- install the
influx_mqtt
which is an mqtt to influx python service, then creates an influx databse namedmqtt
- install the
thread_tags
udp-v6 to mqtt python service
- the grafana dashboard
SensorTag Compare
should be accessible fromhttp://raspi_ip:3000
Main Webapp
see Home Webapp above.
Meta website
< my_button href="https://github.com/HomeSmartMesh/raspi/tree/master/web/overview" text="website source code" >
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
- this will already create a new menu entry
- Fill it with the link to your webapp instance
weight
: defines the order in the menu entrytitle
: The text that will appear on the menu entryBookToC
: Table Of Content not required so that the iframe can be wider... iframe...
: call of theiframe
html shortcode file that has been added in thelayouts\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.
- Has it's own github repo : https://github.com/HomeSmartMesh/smart_home_3d_webapp
- Hackaday project : https://hackaday.io/project/169046-smart-home-3d-webapp
- Even a Hackaday Blog entry : https://hackaday.com/2019/12/29/the-smart-home-gains-an-extra-dimension/
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 fileusage with a thread sensor gag
tag sensors broadcast
Led Panel webapp
mqtt2influx
- repo directory : https://github.com/HomeSmartMesh/raspi/tree/master/py/influx
Features :
- easily deploy as a Linux service : https://github.com/HomeSmartMesh/raspi/blob/master/py/influx/influx_mqtt.service
subscriptions
: topics suscriptions list
"subscriptions":[ "lzig/living heat",
"+/bed weather",
"lzig/bedroom heat",
"+/balcony window left",
names
: replace long topic names with friendly names
"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.
"types":{
"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
"discard":[
"path",
"eurotronic_host_flags",
"occupancy"
log
: a log file with a log levellast_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 whichlast_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
- adjust your mqtt configuration in config.json
- adjust the eurotronic heater topic and apertures (apertures are the contact sensors list)
"heatings":{
"living heat":{
"topic":"lzig/living heat/set",
"Apertures":[
"balcony door",
"balcony window right",
"balcony window left"
]
}
}
- add the contact sensors to the mqtt subscriptions as well
- run the script
python raspi/heat.py
example eurotronic mqtt payload
zig/living heat {
"current_heating_setpoint":17,
"eurotronic_system_mode":1,
"local_temperature":18.49,
"occupied_heating_setpoint":21,
"unoccupied_heating_setpoint":16,
"eurotronic_error_status":0,
"pi_heating_demand":0,
"battery":100,
"linkquality":44
}
docu references
- on release working : https://codepen.io/mhartington/pen/HKGno
Bed Heating app
- web app : js/bed_heater
Bed Heating hardware
- ESP32 firmware : github esp32_iot bed_heater
- using a Shelly 1 pm : https://shelly.cloud/shelly-1pm-wifi-smart-relay-home-automation/
- A standard off the shelf bed heating matrass
- A Solid state relay
Roborock chat
- using the amazing node.js telegraf framework : https://github.com/telegraf/telegraf
- Roborock Chat : js/telegraf/hover_poll.js
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
<new_button href="https://github.com/HomeSmartMesh/raspi/tree/master/py/hue" text="hue ruler service (Github repo)" />
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
< new_button href="https://github.com/HomeSmartMesh/raspi/tree/master/py/home_status" text="home status service (Github repo)" >
- 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
< details title="json Config example. Click for details..." >
"status":{
"red":{
"on":"http://10.0.0.48/settings/?led_power_disable=false",
"off":"http://10.0.0.48/settings/?led_power_disable=true"
},
"blue":{
"on":"http://10.0.0.48/settings/?led_status_disable=false",
"off":"http://10.0.0.48/settings/?led_status_disable=true"
}
}
< /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
<icon_button href="https://github.com/HomeSmartMesh/raspi/tree/master/zigbee/graph_view" text="zigbee/graph_view" icon="github" />
- js library used to generate SVG from graph
<icon_button href="https://github.com/magjac/d3-graphviz" text="d3-graphviz" icon="github" />
- the js library is a port of the graphviz project
<icon_button href="https://graphviz.org/" text="graphviz" icon="github" />
- 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
<icon_button href="https://github.com/yllibed/Zigbee2MqttAssistant" text="Zigbee2MqttAssistant" icon="github" />
zigbee2mqtt
- bind usb device to a static name, failure to do so can result on occasional total failure where usb devices gets mixed and none of them can operate
- hints from stackexchange post
- get info with
udevadm info -a -p $(udevadm info -q path -n /dev/ttyUSB1)
- edit the file
sudo nano /etc/udev/rules.d/10-local.rules
- add
ACTION=="add", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="/dev/ttyUSB1"
udevtest /dev/ttyUSB1
references
Gif Demo
Features
- configurable ip, port and mqtt base name
- multiple hosts for those using mulitple zigbee2mqtt instances.
- svg pan zoom for simpleefficient viewing. graphs can be so huge that text gets tiny.
- red buttons for change graph layout algorithm. Depending on the network, some algos can be more convenient than others
- logging :
js/log.io/server.json
https://github.com/NarrativeScience/log.io - transport-browserconsole https://www.npmjs.com/package/winston-transport-browserconsole
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
- If you need support, want to ask a question or suggest a different answer, you can join the discussion on the github forum <icon_button text="Home Smart Mesh - Discussions" href="https://github.com/HomeSmartMesh/raspi/discussions" icon="github" />
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.