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:

  • Create a Dummy hardware device
  • Create a “Lightwave RF” dimmer switch

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!

21 thoughts on “ESP8266 LED Lighting: Using QuinLED with Domoticz”

  1. For Domoticz on a Raspberry Pi I use WinSCP to connect. And the path to the LUA scrips is: /home/pi/domoticz/scripts/lua

  2. Excellent videos and instructions.

    However, I have my Domoticz installed on a Windows 10 machine and wondered if the runcommand (i.e.)…

    runcommand = “echo ” .. (Fadetimer) ..”” etc

    …LUA script for Domoticz is different for Windows 10.

    Thanks again…

    1. Ai, sadly I have no experience running it on Windows. Maybe a Raspberry Pi would be a good cheap option for you?

  3. Thanks for all your hard work.

    I just got my boards and put everything together. I’m trying to use COB lights that run at 16.5v. When connected to my desktop power supply they dim very well by just adjusting the voltage.

    My problem that is when using the dimmer at 1023 the max voltage I get is 12v which is the lowest amount of power to show any light.

    It seems to reach this 12v threshold at about 800.

    Is there a way to change the lowest level of dimming so that it will go higher?
    I am using the 2.6 board design with the resistors.

    1. I think you are facing a different problem. Most likely the MOSFETs you got are not 3.3v triggered but 5v. Using which link did you order them? Sometimes the Chinese suppliers decide to start sending a different model using the same link.

      You can test it by setting 3.3.v to the gate pin and then 5v to the gate pin of the MOSFET. If the light output changes and the light shines at the full intensity, that is your problem. Alternatively, you could try and set the on-board voltage regulator on the QuinLED module to a higher voltage. Most often the EPS8266 doesn’t immediately die at 4.5v or even 5v. It will definitely shorten the lifespan though if you run it like that for a long time so I don’t recommend that.

      Let us know!

  4. Thanks so much for sharing all your work. Your pcb and insctructions are very clear!
    It was quite easy to also use it on my openhab installation. Now I can controll the quinled with my amazon dash button or with the openhab app. wohoooo! 😉

    Thanks again for your great work.
    Sebastian

    1. That’s cool! If you wrote any code for that, would you mind sharing it in a reply? I’m sure other users also use OpenHAB!

      1. sure.

        in the item file:
        Switch LightKitchen “Kitchen” {tcp=”>[ON:10.0.0.76:43333:’Fadetimer=2500,LED1_target=1000′] >[OFF:10.0.0.76:43333:’Fadetimer=2500,LED1_target=0′]”}

        and in the tcp.cfg set the charset=ASCII

  5. Thx Quindor! Love your work.

    Has anyone gotten the QuinLED working with Home Assistant, or any pointers on how I can go about dong this ?

      1. Hi W4U,

        Did you ever get this working in Home assistant? I am having another look at this really would like to get a dimmer slider working.

        Thanks

  6. Please react: I facing some problems with my quinled icm the new version of domoticz. The command in my commandline works:echo Fadetimer=2500,LED1_target=1000 | nc -w 2 10.0.1.58 43333

    but with the given luascript icm a ‘ lightwave RF switch’ not.

  7. I figure it out. I t has to do with the change of lua fom version 5.2 to 5.3. In Lua 5.3 real integers are introduced. In Lua 5.2 the stringvalue in svalues was converted to integer, while in 5.3 it is converted to float.
    Change this rule in the script:
    DomValue = math.floor(otherdevices_svalues[DomDevice]);
    This returns an integer value instead of a float. It will solve the problem.

  8. Hi,

    I have a problem with the dimmer because the calculations performed by the script result in a comma LED1_Target = 198.0. Please tell me how to fix this problem?

    2020-11-25 02:34:37.731 Status: LUA: echo Fadetimer=1000,LED1_Target=198.0 | nc -w 1 192.168.71.27 43333

    1. Hi Paweł
      You need to modify one line of code in the script:
      instead of CalcValue = DomValue * 33; it should be CalcValue = DomValue * “33” | 0; this will display the integer variable LEDx_target.

Leave a Reply

Your email address will not be published. Required fields are marked *