Site icon Intermittent Technology

ESP8266 LED Lighting: Using QuinLED with Domoticz

Today we’re going to take a look at using QuinLED with Domoticz. First I’ll take you along while we install Domoticz on a Fedora 25 Server and then we configure it work with QuinLED.

This post is part of a series

The index for this series can be found here. 

The Tutorial Videos!

Yes, you read that correctly, I’ve made 2 videos!

The first video is about installing Domoticz itself, we go through downloading the newest source code from the GitHub and then compile it and make it run automatically during startup of the machine.

 

The second video is about configuring Domoticz to be able to talk to QuinLED. For this part you need to have a Domoticz server running (Like we configured in part 1) and also have a QuinLED ready that has the correct code running and is connected to your WiFi (With the IP known).

 

Text to go with the video

This will not be a writen tutorial also, if you’d rather read this in written form, please take a look at my original article I have about this here.

During the video I copy & paste a lot of lines of code. Those are going to follow below. Keeping this post close-by should allow you to follow along with the video and basically replicate what I’m doing!

Part 1 – Installing Domoticz on Fedora 25 Server

Start with installing a Fedora 25 Server Edition (virtual) machine. During the install, you don’t need to select any packages or roles, just leave it a bare system. While it’s installing you have to set the root password and you also need to create a user, give that user administrator privileges too.

Once the installer is done and you’ve logged into your new system, enter the following command to install all the packages we need:

sudo dnf install gcc-c++ cmake curl boost-devel zlib-devel openssl-devel libcurl-devel libusb-devel libstdc++-devel libstdc++-static git joe dstat htop python3-devel libtool python-pthreading boost-python3 boost-python3-devel boost-static 

 

Once that is installed we need to open up some firewall ports:

sudo firewall-cmd --add-port=8080/tcp --permanent
sudo firewall-cmd --add-port=4433/tcp --permanent
sudo systemctl restart firewalld

 

Then we need to create a user which we will use to run the Domoticz software:

sudo useradd domoticz
sudo passwd domoticz

 

Next, let’s go to the install directory and download the software from GitHub:

cd /opt
sudo git clone https://github.com/domoticz/domoticz.git
chown -R domoticz:domoticz /opt/domoticz

 

After that, let’s become the Domoticz user and compile the program:

su domoticz
cd /opt/domoticz
cmake CMakeLists.txt 
make -j4

 

After compiling is done (it takes a while) let’s try to do a test start:

./domoticz.sh

 

After testing the connection (http://IP.IP.IP.IP:8080), you can stop Domoticz by hitting “ctrl-c” in the terminal window.

If that is all working correctly we need to create a startup script:

exit
sudo joe /etc/systemd/system/domoticz.service

 

Insert the following code, to save hit “ctrl-k”:

[Unit]
       Description=domoticz_service
[Service]
       User=domoticz
       Group=domoticz
       ExecStart=/opt/domoticz/domoticz -www 8080 -sslwww 4433
       WorkingDirectory=/opt/domoticz
       #give the right to open privileged ports
       ExecStartPre=setcap 'cap_net_bind_service=+ep' /opt/domoticz/domoticz
       Restart=on-failure
       RestartSec=1m
       #StandardOutput=null
[Install]
       WantedBy=multi-user.target 

 

Then we need to let the system know we made a new startup script and have the system start it:

sudo systemctl daemon-reload
sudo systemctl enable domoticz.service
sudo systemctl start domoticz.service

 

And that’s it! Domoticz should be running and reachable using http://IP.IP.IP.IP:8080 and/or https://IP.IP.IP.IP:4433 !

Part 2: Configuring QuinLED in Domoticz

As I mentioned above for this part you need to have Domoticz up and running and you need a QuinLED module which is connected to a LED light, WiFi and you know the IP.

The first step is testing using command-line if you can control the module. From the freshly installed machine, execute the following command:

echo Fadetimer=2500,LED1_target=5 | nc -w 2 IP.IP.IP.IP 43333

 

Once you have that working we can move on to Domoticz. For this part it’s best to follow along with the video, in short we’re going to take these steps:

Once you have that configured, you can go back to the command line and create a script file in the following directory: /opt/domoticz/scripts/lua

There you need to create a file called:

script_device_DOMOTICZSWITCHNAME.lua

 

Inside that file, paste the following code:

commandArray = {}


DomDevice = 'DEVICE-NAME'


IP = 'IP.IP.IP.IP'
Port = '43333'


LEDtarget = 'LEDx_Target='
Fadetimer = 'Fadetimer='
Waittime = '1'
FadeTime1 = '5000'


 if devicechanged[DomDevice] then
   if(devicechanged[DomDevice]=='Off') then DomValue = 0;
   print ("Turning off " .. DomDevice);
   runcommand = "echo " .. (Fadetimer) .."" .. (FadeTime1) .. "," .. (LEDtarget)
 .. "0  | nc -w " .. (Waittime) .. " " .. (IP) .. " " .. (Port) .. " ";
   print (runcommand);
   os.execute(runcommand);
 return commandArray
   else
    DomValue = (otherdevices_svalues[DomDevice]);
   end
   CalcValue = DomValue * 33;
   print ("Value received from Domoticz was " .. (DomValue) .." ");
   print ("Calculated value for ESP is " .. (CalcValue) .." ");	
   print ("Dimming "  .. (DomDevice) .. " to " .. (CalcValue) .. " ");
   runcommand = "echo " .. (Fadetimer) .."" .. (FadeTime1) .. "," .. (LEDtarget)
 .. "" .. (CalcValue) .. " | nc -w " .. (Waittime) .. " " .. (IP) .. " " .. (Por
t) .. " ";
   print (runcommand);
   os.execute(runcommand);
 end
return commandArray

Make sure that while copy & pasting no lines get truncated (Like I had in the video)!

Fill in the details for the “DomDevice” , “IP” and “LEDtarget” fields.

Ending remarks

And that’s it, you’re done, you now should have a fully functioning QuinLED module within Domoticz. To expand to expand, you can create a second switch and configure it with it’s own batch file to use the second channel! And before you know it, you’ll be thinking of more places where you can add LED strips/lights! 😉

If you have a question, please leave a comment here or at one of the YouTube videos and consider subscribing to my YouTube channel and giving the videos a like, that helps me out a lot!

Exit mobile version