Category Archives: Domoticz

Domoticz part 5: Grafana, InfluxDB, Telegraf – beautiful and easy graphs

Grafana is the answer to the nagging question we’be been asking ourselves over the years – how to quickly and nicely present our data gathered from devices. InfluxDB on the other hand is the database that is as easy and simple to use, thus making it an ideal candidate for this job.
Let me show you how to quickly and easily put our data from domoticz and other devices to InfluxDB and then using Grafana – display in much more useful way than default domoticz graphs do.

What will we need?


  • InfluxDB
  • Grafana
  • bash scripts


  • Raspberry Pi – 4B+
  • OPTION: Raspberry Pi A/B/B+ lub Zero (armv6)
  • OPTION: A different ARM based micro-computer (i.e.: OPi PC” rel=”noopener” target=”_blank”>Official Store – OrangePi PC using CPU H3/H2/H5) – they could be cheaper. It’s also entirely possible to use x86 computer with Debianem, but it’s going to eat way more than 4-6W when using ARM based. Here I used finally Orange Pi PC with latest armbian distribution, tested first on latest Raspberry Pi 2



Let’s download latest InfluxDB version (at the time of writting it was 1.0.2) – “Standalone Linux Binaries (ARM)”:

cd /tmp

Then we have to create user influxdb:

sudo adduser influxdb

Accept the questions with yes, add some data if you like, password.
Check if the user exists:

id influxdb

We should get similar, positive response:

uid=1001(influxdb) gid=1001(influxdb) grupy=1001(influxdb)

Now, let’s install from influxdb binary:

sudo tar xzf influxdb-1.0.2_linux_armhf.tar.gz 
cd influxdb-1.0.2-1
cp -R * /
sudo chown influxdb:influxdb -R /etc/influxdb
sudo chown influxdb:influxdb -R /var/log/influxdb
sudo mkdir -p /var/lib/influxdb
sudo chown influxdb:influxdb -R /var/lib/influxdb
sudo cp /usr/lib/influxdb/scripts/ /etc/init.d/influxdb
sudo chmod 755 /etc/init.d/influxdb
sudo cp /usr/lib/influxdb/scripts/influxdb.service /etc/systemd/system

All went well? Let’s start our InfluxDB:

/etc/init.d/influxdb start

It works! Let’s make sure it starts with the system, this time using a different tool:

sudo apt-get install rcconf

Run it, push space to get “*” at influxdb.


This time it’s a bit easier let’s use the ready package from Choose a package either for Raspberry Pi 2/3 (armv7) or for Raspberry Pi A/B/B+ lub Zero (armv6), and download it using wget. Here I’m using Raspberry Pi 2/3 package:

sudo apt-get install adduser libfontconfig
sudo dpkg -i grafana_3.1.1-1472506485_armhf.deb

This package tells us to add Grafana to start with the system in this way:

sudo /bin/systemctl daemon-reload
sudo /bin/systemctl enable grafana-server

Let’s start grafana:

sudo /bin/systemctl start grafana-server


Aktualne wersje InfluxDB zarządzamy poprzez linię komend (CLI):

pi@host:~$ influx 
Connected to http://localhost:8086 version 1.2.2
InfluxDB shell version: 1.2.2

Aby stworzyć bazę danych wystarczy:

> create DATABASE domoticz
> quit

Current InfluxDB ara managed by (CLI):

pi@host:~$ influx 
Connected to http://localhost:8086 version 1.2.2
InfluxDB shell version: 1.2.2

Creata database:

> create DATABASE domoticz
> quit

The older version of InfluxDB by default use the web interface – by using IP of our Raspberry at port 8083. Basic configuration allows unauthorized access via http. This is the interface:

InfluxDB: Interface
InfluxDB: Interface

so, let’s just choose “Create Database”, and name our first database “domoticz”:

InfluxDB: Creating domoticz database
InfluxDB: Creating domoticz database

That is it! Either with http interface or CLI – no need to create data, tables – we can simply add data to it.

Sending from domoticz to InfluxDB

Using Domoticz – use the menu and select “HTTP”:

HTTP push in Domoticz

We need to find data that is interesting and put it into Influxdb – so let’s choose atmospheric pressure:


So how does this work? First, we choose a variable – our data, that is already in Domoticz system – from menu “Device name”. Then – we need a number to identify – I use the same as the IDX number of the device in domoticz – so here it’s “1450”. Tick the “Activate connection”, at the right side and provide URL that will be our connection via http to write toInfluxdb: IP, port – this time it’s 8086, database name, username/password if used and precision.
Method is HTTP POST, authorization – let’s leave that for later.
The most important part is the “Data:” here we enter our InfluxDB variable, that we going to use later to create graphs, it’s value and time. Keeping things small and simple, we shall call it “device_1450“. Use tshark, if you’re curious how the URL’s work, what is the response (HTTP code 204 if it’s fine). That is it – data will be stored in “domoticz”, database, no need to create types, indexes, tables – quite new approach, eh?

Sending data from any device (not domoticz)

Since InfluxDB is so easy going, everybody is getting ideas. We talk via HTTP, meaning that we can put the data using simple tools i.e. using curl, a popular program present in each modern distribution.:

apt-get install curl

Here’s and example on how to use it:

curl -i -XPOST '' --data-binary "inwisp,host=wisp value=${speed_in}"
curl -i -XPOST '' --data-binary "ouwisp,host=wisp value=${speed_out}"

This very simple example uses SNMP (the old 32-bit counters) that queries the wireless interface to ISP, to show the “Internet speed”. curl is used here to send the data to database named “snmp”, the valiable is inwisp for Input and outwisp for Output, but to spice up things a bit – we use host (it’s optional), to be able to later group the devices. Then the value – which is the speed. We don’t put extra time value – we use the current system time.
The whole script – below (it’s much easier to use telegraf, but I still love the MRTG’s approach to collect data) is an 17 yeras old 17 bash script!. I used it via screen while starting the system same way as with the – Flightradar and SDR blog entry.

#This script reads the interface speed in bits (actually the number of bits tru interface) using old 32-bit counters
#Licencja: GPL v2
#1999-06-22/23 - Initial version to test the MRTG way of doing things
#2016-11-12 - Adopted to serve as simple example for Grafana blog entry, some changes to modernize and simplify it a bit using new bash functions

#Setting up the variables
#Number (index) of the monitred interface snmpwalka
#SNMP community name, by default it is "public"
#IP of the router that we want to monitor
#How often do we check?
#Maximum values that we expect - by default its 25/4. We need that to filter out counter resets and errors
#Glowna petla - czytamy wartosci czekamy zadany czas i czytamy je znowu - odejmujemy od siebie aby wyznaczyc predkosc (tam na dole petli)
while [ 1 -eq 1 ]
 octety_wtedy_in=$(snmpget -v1 -c $community $ip_rutera$numer_interfejsu | awk '{print $4}')
 octety_wtedy_out=$(snmpget -v1 -c $community $ip_rutera$numer_interfejsu | awk '{print $4}')
 sleep $co_ile_sekund
 octety_teraz_in=$(snmpget -v1 -c $community $ip_rutera$numer_interfejsu | awk '{print $4}')
 octety_teraz_out=$(snmpget -v1 -c $community $ip_rutera$numer_interfejsu | awk '{print $4}')

#Najpierw sprawdzamy czy czasem nie będziemy dzielić przez zero, oraz czy się licznik nie przepełnił... Jesli cos jest nie tak to wartosc na 1
 if [ $octety_wtedy_in -eq $octety_teraz_in ]

 if  [ $octety_wtedy_in -gt $octety_teraz_in ]

 if [ $octety_wtedy_out -eq $octety_teraz_out ]

 if  [ $octety_wtedy_out -gt $octety_teraz_out ]

 #Maly debug - wyswietlamy ile nam wyszlo
 echo Wtedy In: $octety_wtedy_in
 echo Wtedy Out: $octety_wtedy_out
 echo Teraz In: $octety_teraz_in
 echo Teraz Out: $octety_teraz_out

 #Liczymy roznice


 #Jeszcze raz sprawdzamy czy nie mamy zlego wyniku (poprzednie nie wylapia jednej sytuacji... no jakiej?) 
 if [ $roznica_in -lt 0 ]

 if [ $roznica_out -lt 0 ]

 if [ $roznica_in -gt $max_possible_in ]

 if [ $roznica_out -gt $max_possible_out ]
 #Mamy nasza predkosc
 #Czyscimy kosnsole aby usunac poprzednie wyniki
 echo "Prędkość IN: "${predkosc_in}"kbps"
 echo "Prędkość OUT: "${predkosc_out}"kbps"
 #Saving data in snmp database InfluxDB
 curl -i -XPOST '' --data-binary "inwisp,host=wisp value=${predkosc_in}"
 curl -i -XPOST '' --data-binary "ouwisp,host=wisp value=${predkosc_out}"

The stored data in snmp database should give you the following reply:

HTTP/1.1 204 No Content
Request-Id: a11318b7-a590-11e6-cea7-000000000000
X-Influxdb-Version: 0.11.0
Date: Sun, 13 Nov 2016 11:02:39 GMT

The other way to find out if we’re in the database is to use the Influxdb HTTP interface and issue from the menu – SHOW MEASUREMENTS:

Grafana – finally we’re getting to the beautiful graphs!

Grafana runs on port 3000, login and password admin/admin – now choose in left top corner – Data Sources. Add Source and type in – Type, URL, Access at proxy, user and password for the database:

Grafana: Add Data Source - InfluxDB
Grafana: Add Data Source – InfluxDB

If the data source is working – we can go to “Dashboard” and create our first :

Grafana: Add new Dashboard
Grafana: Add new Dashboard

Next – let’s add our first graph:

Grafana: Panel
Grafana: Panel

Now we see the default panel with single data series to plot/graph. It looks nice, but this is not our data yet:

Grafana: First Graph
Grafana: First Graph

Next step – select our database from the “Panel data source” – change from -Grafana- to SNMP. “A” – our data series should look like this:

Grafana: Add db, toggle edit mode
Grafana: Add db, toggle edit mode

Green line is gone, because we need to provide correct data – we do it in the same way – changing to the edit mode in the query “A” and fill in just like in exemple below. Next choose again SNMP “+ Data query” and fill in the “B” query – all changes are updated on the fly:

Grafana: example Internet speed series data entry
Grafana: example Internet speed series data entry

Go to “Axes” menu – here, select proper data type – “Unit”, “data rate” -> “kilobits/sec”. In the “General” name the Panel “Internet” and this is it. The floppy disc icon saves our new dashboard:

Grafana: first graph
Grafana: first graph

It’s time now to install aditional grafana puligns to get more of the graphs, gauges etc:


The last interesting piece of software is Telegraf. This a very feature-rich piece of monitoring software, that is able to gather data from aplication statues, interfaces, CPU, and runs also on Linux> Simple installation follows simple configuration.
First – create new databes in InfluxDB – “telegrafPI” but this time using command line:

pi@orangepipic-grafana:~$ influx
Visit to register for updates, InfluxDB server management, and monitoring.
Connected to http://localhost:8086 version 1.1.0
InfluxDB shell version: 1.1.0
> create database telegrafPI

Now let’s install telegraf:
We can either add repository:

deb jessie stable



or get appropriate pacakge from:

tar xvfz telegraf-1.1.2_linux_armhf.tar.gz

or even use

dpkg -i telegraf_1.1.1-1_armhf.deb

Configuration is dead simple telegraf pre-configures the file based on what we tell it to, then we should save it in:


So to get you started lets monitor CPU:

sudo mkdir -p /etc/telegraf
sudo telegraf --config telegraf.conf -input-filter cpu:mem -output-filter influxdb > /etc/telegraf/telegraf.conf/

Based that this is the same computer we monitor where influxdB is installed – of not – choose proper IP of the DB host.
In Grafana – after adding new database source, we’re using the following data series for plotting:

A: SELECT last("usage_idle") FROM "cpu" WHERE $timeFilter GROUP BY time(1m) fill(none)
B: SELECT last("usage_user") FROM "cpu" WHERE $timeFilter GROUP BY time(1m) fill(none)
C: SELECT last("usage_system") FROM "cpu" WHERE $timeFilter GROUP BY time(1m) fill(none)
D: SELECT last("usage_guest") FROM "cpu" WHERE $timeFilter GROUP BY time(1m) fill(none)
E: SELECT last("usage_irq") FROM "cpu" WHERE $timeFilter GROUP BY time(1m) fill(none)

To get the result below, tick the “Stacked” in Display tab:

Grafana + Telegraf: CPU Example
Grafana + Telegraf: CPU Example

Other projects

Grafana with InfluxDB is also used in the SMOG measurements..

Grafana versions 5.x and 6.x and missing PhantomJS

Have noticed that screenshot functionality is no longer working? There’s no PhantomJS bundled with Grafana for Rasbperry Pi (and armfh) – so you cannot save it to *.PNG.

What does the error look like:

Jun 10 19:12:01 grafana grafana-server[268]: 2019/07/10 19:12:01 [render.go:41 RenderToPng()] [E] Failed to render to png:
 fork/exec /var/lib/grafana/vendor/phantomjs/phantomjs: no such file or directory 


lvl=eror msg="executable not found" logger=rendering executable=/usr/share/grafana/tools/phantomjs/phantomjs
lvl=eror msg="Rendering failed - PhantomJS isn't included in arm build per default" logger=context userId=1 orgId=1 uname=admin error="PhantomJS executable not found"

You can also see:

Grafana Render Error
Grafana Render Error

To restore the screenshot functionality:
– download from latest version here we got the RPi version (select Download link or copy the link and use wget/curl on RPi)
– install:

sudo dpkg -i phantomjs_2.1.1_armhf.deb

– execute form console:

cd /usr/share/grafana/tools/phantomjs
sudo ln -s /usr/local/bin/phantomjs

This brings back the screenshots.

And this is it, go and create beautiful graphs!

Domoticz part 8 – Stable instance of Domoticz, 24/7/365 mode – high availability at home

As a result, a both fresh and advanced user finds himself in a situation where the system – ceases to work at all, or requires frequent restarts, or worse causes quick degradation of the main storage device – which is often (micro) SD card.

Is there a simple and effective solution to increase Domoticz’s availability on Raspberry Pi / Orange Pi?

Sure there is! But first – before you begin – make a copy of your (micro)SD working used in domoticz instance on your Raspberry Pi/Orange Pi.
CAUTION: We will perform operations that may lead to the loss of all data – so make sure you have a copy!

What will you need?


  • monit
  • rsync


  • harddrive either classic HDD or better SSD, small is OK from 32GB up to 128GB
  • heatsinks for Raspberry Pi/Orange Pi
  • USB 2.0 or 3.0 to SATA adapter – so we can connect the harddrive via USB port

Continue reading Domoticz part 8 – Stable instance of Domoticz, 24/7/365 mode – high availability at home

ESP8266 and SMOG part three: sensor protection, cloud upload

Last time we updated our simple SMOG sensor with display (OLED) and added BME 280 to verify the SMOG measurements – the environmental sensor – as we know that humidity over 70% can add up to the SMOG.
It’s time now to protect our sensor.
Continue reading ESP8266 and SMOG part three: sensor protection, cloud upload

Domoticz part. 7: Heating your house with Z-Wave

We do know how to install domoticz. But how easy is to control heating in your house/flat? After full season of testing radiator control – I can recommend a very interesting and useful heating control system that you can setup in your home or apartment. All just by means of adding radiator thermostats with Z-Wave radio.

Z-Wave - termostat grzejnikowy Danfoss
Z-Wave – termostat grzejnikowy Danfoss

What will you need?


  • Up to date Domoticz installed on PC

Continue reading Domoticz part. 7: Heating your house with Z-Wave

Domoticz part 6: Water/Rain/Snow/ sensor FC-37 using ESPEasy (digital)

Rain/Snow/Water detection system
Rain/Snow/Water detection system

We return today to the simple and quick solutions! The weather station or irrigation/sprinkler system – can’t operate without proper detection of rain, water or even snow. Let’s use the FC-37 sensor (also know as YL-38 or MH-RD, or just similar to the picture)

What will you need?

  • rain sensor type FC-37/MH-RD (rain drop/snow sensor) – must come with D0 pin, price around $0.50 to $1.50
  • ESPEasy working on ESP8266 from the previous entries

Installation and configuration

The sensor must be connected to the power supply + 3.3V (3V) and GND of the ESP8266 running ESPEasy. Next we connectthe D0 pin to the selected pin our ESPEasy – which is going to notify Domoticz using IP. Let’s use free GPIO-12 (pin D6 on the NodeMCU v2 board). This sensor also has an analog output – which allows for more advanced detection of rain, and we will deal with in the future.
Finally – we connect the rain sensor plate with  the sensor module that is connected to ESP8266:

New virtual switch
New virtual switch – for the rain or no rain information in domoticz

Check in the Devices section the IDX number – it’s 543 in this example:

Device IDX for rain sensor
Device IDX for rain sensor

Next – let’s configure via WWW interface our ESPEasy software – selecting the “Switch Input”, entering correct IDX and setting some options  – please do mind the “Inversed”, and of courser the correct value of IDX:

Config and setup
Config and setup

Let’s test our sensor! For this purpose you should set the sensor using Philips screwdriver just so that the green LED still does not glow when we apply only dry finger plate (blue cube with white “screw”):

Rain drop sensor

Rain drop sensor setupIf the sensor is correctly adjusted we should get the green LED to glow right after dropping some water on the sensor plate:

Of course, when the device is installed outside, the seonsor is protected – we need to re-set it so as not to react not to dew, but the rain or snow.
Domoticz should show us this swithc in the following way:
When there is no rain:

Rain stopped
Rain stopped

And when it rains:

It is raining
It is raining

That is it!

Domoticz part 3.1: ESP Easy on ESP8266 – remote and local OLED display with temperature, humidity, light – weather station

Previously we played around the SSD1306 OLED display as side display for Raspberry Pi. The author of ESP Easy – Richard ten Klooster ( – recently updated his project to include new sensors, so today we will update our DHT22 enabled remote sensor for Domoticz with display and light metering. Our weather station will get a remote display.

I’ve created such bundle of sensors to allow both temperature and humidity measurement small shack for chopped wood but also to light the way to it after dark via LED lamp. Also I was interested in stability of ESPEasy with DHT22, BH 1750 and OLED I2C display.

What will you need?

Software & Hardware

Let’s do it!

Connecting the display is very easy – event if you didn’t the previous example for Raspberry Pi. After logging in to ESP – ESPEasy – we choose the PINs that will work as I2C bus. This example uses the default: GPIO 4 & 5. Let’s connect our display to +3,3V, GND, and SDL & SCL to GPIO 4 & 5. The configuration is as follows:

ESP Easy - SSD1306
ESP Easy – SSD1306

Pay attention – this is how the sensor was called and the values that we defined – we need to enter them again just the same for the display for ESPEasy to get data and to display them correctly:

ESPEasy DHT22 - config
ESPEasy DHT22 – config

The first value is the address on the I2C bus – to find out if we have correct one go to Tools->I2C Scan, which gives you the address – and notice that example shows another – connected to the I2C bus sensor – Lux – BH1750.:

ESP Easy - Scan i2c
ESP Easy – Scan i2c

Out address is (hexadecimal): 0x3c!
If all is correct – we should see “ESPEasy” on the screen (upside down is still fine).

Next – we move to display configuration – direction, which line are used for displaying – but first let’s try to display some data from external source:

Remote and local display

ESPEasy allows you to display both local sensor dana or any other data via unprotected method – using just http URL.
What is possible – first we can turn on/off the display. In this example the IP address of ESP8266 running ESPEasy is We can turn off the display (i.e. it’s too bright in the night),off

Then to turn in on:,on

Clearing the display:,clear

Now, to us it in our project – we should use the curl to send data from Raspberry Pi:


An example:


Finally, we will use this function to display data from other sensor that our Raspberry Pi has data of – the opposite of what we usually use the ESP for!

But first – we should get the data from our already connected DHT22 and lux sensor. Let’s type the name of our sensor in Line 1. The Line 2 could hold the info about uptime – and time – we know that device is working and has proper communications with NTP.

Where to set NTP ? Go to NTP in Tools and choose your favourite NTP server – i.e.
We got time & uptime – that’s easy. Displaying variable takes more effort – we need to use the percentage as brackets (%). Take a peek at Wiki page for examples.
We’re ready to display the data from DHT22. It’s time to check what was it’s name in the configuration:

ESPEasy DHT22 - config
ESPEasy DHT22 – config

– and here it’s name is: AmicaTempHum. It’s a bit different we need “[ ]”, and the variables (we have two of them when talking to DHT 22) are separated by (#): [AmicaTempHum#Humidity]. This time the “%” is used to tell you that humidity is in % – so it’s supposed to be displayed.

The same approach should be used for temperature. Since by default we set 300 seconds of update time – we should get on the screen, after a while:

ESP8622 with SSD1306 (OLED) display working on ESPEasy
ESP8622 with SSD1306 (OLED) display working on ESPEasy

OPTIONAL: Since we can have quite a lot devices on I2C bus – let’s connect in paralel lux meter – BH1750. Meaning: VCC 3,3V to VCC, SDA & SCL to SDA & SCL finnaly GND to GND. Just like DHT22 it needs tiny amounts of power so the Amica NodeMCU can handle it safely. If we connected it properly we should get this info:

ESP8622 with SSD1306 (OLED) display, DHT22, BH1750 under ESPEasy
ESP8622 with SSD1306 (OLED) display, DHT22, BH1750 under ESPEasy

So, next photo show how much light I’m using here:

ESP8622 with SSD1306 (OLED) display, DHT22, BH1750 under ESPEasy

Beware – if you’re getting values like 54612 lux – the sensor is NOT working properly (check connections).

This is it – domoticz needs to be updated with new virtual Lux sensor (the virtuals for DHT22 have been added last time). So what to do with light intensity sensor ? Using the same approach as with the script for opening garage – we can turn on some LED lamps if it gets dark enough. Or use ‘Events’ in domoticzu if you like GUI approach.

But wait! People commenting this brought up interesting idea:

Displaying other values FROM domoticz on remote sensor

Looking at our example we see that Line 7 is empty. Originally I wanted to add the baraometer, but the shop canceled the order. I have other one on RPi – so why not use this data – atmospheric pressure cannot be that different, right? The BMP180 gives me temperature and pressure in hPa. I don’t care about the temperature, but the pressure is interesting. Since we already brought up the garage exampe  you might remember that a LUA script w domoticz can give you data and allows you to use it:

  • we need to get the pressure data
  • cut it (remove extra info)
  • display it on SSD1306 attached to ESP8266

The LUA script will use the round function – single digit, and will be launched every minute (or smarter – at any change then if with devicechanged) – so let’s use the time option.
In my system this sensor is named ‘TemperaturaCisnienie’ so remember the name of the script has to match it:


IP address needs to mathc you network and script goes to /home/pi/domoticz/scripts/lua:

function round(num, idp)
 local mult = 10^(idp or 0)
 return math.floor(num * mult + 0.5) / mult
commandArray = {}
commandArray['OpenURL']=',7,1,Baro:'..hektopaskale..'hPa '
return commandArray

NOTE: Newer version of ESP Easy (inscluding ESP Easy Mega), use “oled” instead of “oledcmd”, as it was noted by one of the commentators.

So after a while you will get pressure on the screen.

Another example from comments discussion:
I you have the termometer from previous example about attaching termometers to domoticz – corresponding script is here (remember about the name!)

local NazwaCzujnika="ZKominka"
commandArray = {}

if devicechanged[NazwaCzujnika] then
return commandArray

This time we only update on temperature CHANGE.