Domoticz: Lua script to create a view deported OLED with ESP Easy [Exclusive Guide]

2:32 pm February 24, 20178913

in tutorial previous , we saw how to create a display deported for server automation Jeedom using an OLED display configured with firmware ESP Easy . Impossible not to explain how to do the same thing with Domoticz ! It for to do with the constraints of the ESP Easy firmware, except to develop its own plugin ( everything is explained here ), we have to control the display directly using HTTP for Domoticz requests.

I will not repeat a tutorial on Lua scripts (unless you insist ;-)), there are already very good on the internet such as (in French). Nous avons juste besoin de faire quelques rappels rapides :

  • Les scripts Lua sont stockés dans le répertoire ~/domoticz/scripts/lua
  • Il existe trois types de script. Domoticz makes the difference from the file name.
    • script_device_NomDuDevice : the name of the device must be the same, so it is forbidden to use spaces and the accented or special characters (😥)
    • script_time_NomScript.lua : the script runs every minute. The script for 10 seconds to complete. In the past, he is arrested by Domoticz for not penalizing the other scripts and the system in general.
    • script_variable_NomVariable.lua : embarks on a change in the specified variable.
  • they must wear the lua extension

the full Wiki on Lua scripts is here .

for some reason which escapes me again (bug?), it seems not possible to edit the scripts present in the directory scripts from within the event handler. It will therefore have to create it on a text editor then upload the file to FTP or directly edit the script on the server Domoticz in SSH with nano. I opted for this solution in order not to encounter a problem encoding (UTF-8) and end of line characters. If you’re new to Linux, follow guide to learn all about SSH.

connect you to Domoticz in SSH (using putty on Windows, since the Terminal on Mac OS and Linux). Place you in the scripts directory.

tip. For Mac users, the tilde (~) is obtained with the key combination ALT + N . Thanks Steve!

open a new script called script_device_Exterieur . lua . Here, we will send the remote display the temperature of an external probe that works with the firmware MySensors .

Some elements of Lua language before starting

before launch us into the script, here are a few language elements that will help you for other scripts

helps to comment a line. For example

– this is a comment

print () allows you to display a message in the log (Log) accessible from the settings menu. “Example

print (“adds a message to the newspaper”)

string =” % 20″ to create a variable containing a string of characters, simply declare it and assign it a value. “For example

point =” %2E “

… String

… variable

assembles (also a variable containing a string) strings. For example

baseurlESP..’ OLED, 1, 3, Temp’… space

end of line unlike many languages (C++, Javascript…), there is no end of line character. So beware of the encoding of the file!

devicechanged [‘Device’]

allows to determine if a device for changed state or value. Useless in a _device script since it is precisely triggered when the Device changes.

if () then


the loop if in lua

otherdevices_svalues [‘Device’]

retrieves the value of the specified Device.

encode special characters with the ASCII code corresponding

so we’ll have to manage us even the encoding of special characters. Best is to create a variable for each character that will be used in the HTTP request sent to the ESP8266. Here are a few, you should find them all here .

On en profite également pour créer la base de l’URL qui est toujours identique. Simply change the IP address that corresponds to your ESP8266.

all for Domoticz Lua scripts must return a commandArray that contains the commands to run. We also display in the log that the script for run.

we need to send a series of HTTP requests to ESP Easy. To do this, we just need to add a command in the table commandArray for each HTTP request. First it clears the screen

now we update line by line screen. For example you wrote on line 3 and column 1, Temp: 19.5 * C. We assemble the string by replacing the spaces and special characters in the ASCII code.

the degree (°) does not work (or I have not yet found how to!).

Finally, we can force the lighting of the screen with the command oledcmd, we.

the script must return a commandArray array
and here is the script in its entirety that you just paste in the file.

save the script with CTRL + X then O (or Y if Raspbian is in English). As soon as the Device will be updated, the remote display will be updated also. If nothing happens, go to the log (Log) to check if there is an error in the script.

It must be possible but Blocky is a little curl (sorry blocked) to do that. Unlike Jeedom who knows how to encode the URL on the fly (replace spaces and special characters by their ASCII code), with Domoticz must do it yourself. This isn’t a problem in itself, but with Blocky, it may quickly become galley.

also a pinprick to remind how to wire and configure a (SSD1306) miniature monochrome OLED display.

here, I suggest you to add a button to turn the screen over a period of time (10 seconds here). It could be interesting to turn the display off or simply by ecology. We’ll put a refresh period very long, or at least higher than the refresh rate of the data sent by Domoticz. It is necessary to avoid that the display is reset by ESP Easy. ESP Easy does not to display the data (they are sent by Domoticz directly), the screen will become black simply.

the OLED display connects to the I2C bus. By default these are pins GPIO4 (SDA, D2 of the ESP8266) and GPIO5 (SCL, the EP8266 D1) that are used.

here is the result obtained with the proposed Lua script.

espeay esp easy domoticz script lua ssd1306 oled display deported dht22