Espeasy led dimming

Everything about esp8266 and more.
Post Reply
User avatar
thecosmicgate
Posts: 250
Joined: Monday 06 April 2015 14:37
Target OS: Linux
Domoticz version: newest
Location: The Netherlands / Hoeven
Contact:

Espeasy led dimming

Post by thecosmicgate » Saturday 25 November 2017 18:14

At the moment I got Espeasy running with a led strip . But the dimming is only possible using the HTTP URL code. But if possible I want to use the slider from domoticz to set between 0 - 100% . I looked at the script used by Quindor with his led solution but I can't get to work.
Is there some other solution for this ?

Thnx a lot

Sent from my SM-G935F using Tapatalk

It's nice to be important, but it's more important to be nice
Scooter ;)

MikeF
Posts: 192
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: UK
Contact:

Re: Espeasy led dimming

Post by MikeF » Monday 15 January 2018 0:14

Try this:

Code: Select all

-- LED dimmer script script using ESPEasy

commandArray = {}
DomDevice = 'ESP_dimmer';
IP = 'xxxx';
PIN = "xx";
if devicechanged[DomDevice] then
   if(devicechanged[DomDevice]=='Off') then
		print ("OFF dim = "..uservariables['dimmer']);
		CalcValue = 0;
   	else if(devicechanged[DomDevice]=='On') then
   		DomValue = uservariables['dimmer'];
        print ("ON dim = "..uservariables['dimmer']);
        CalcValue = DomValue;
    else
    	print("Other");
        DomValue = otherdevices_svalues[DomDevice];
        CalcValue = math.floor(DomValue / 100 * 1023);
        commandArray['Variable:dimmer'] = tostring(CalcValue);
        print ("dim Level = "..uservariables['dimmer']);
   	end
   	end
   	runcommand = "curl 'http://" .. IP .. "/control?cmd=PWM,"  ..PIN.. "," .. CalcValue .. "'";
   	os.execute(runcommand);
	print("PWM value= "..CalcValue);
end
return commandArray
Save this as a lua script (e.g., script_device_dimmer.lua) - change the x's to the IP address and GPIO pin number of your ESPeasy.
Set up a dummy device in Domoticz (initially as a switch, then change it to a dimmer) called 'ESP_dimmer', and a user variable called 'dimmer' (this will store and restore the dimmer value when you switch off / on).
You should then be able to control your LED from the slider of your Domoticz device.

robatbentley
Posts: 19
Joined: Saturday 18 March 2017 22:24
Target OS: Raspberry Pi
Domoticz version: 3.8889
Location: Newcastle/UK
Contact:

Re: Espeasy led dimming

Post by robatbentley » Wednesday 28 March 2018 17:54

Sorry for being a bit dumb here, but what is actually loaded onto the 8266 (in my case an E12)? Is it an instance of ESPEasy or some LUA code?
I also tried using Quindors solution, got it working but stopped working some months later. Fixed the problem in the code loaded onto the 8266 but failed again more recently and don't have the coding skills to debug it all over again. ...so looking for a more resilent solution.

Sure I've missed some key element of this solution, but think I've managed all the rest of it.
My config...

Filename: script_device_LampDimmer.lua
...with PIN = "04"; (for GPI04 or pin D2)
Domoticz user variable called dimmer (string)
ESPEasy device "Switch" connected to Domoticz Idx. ...and controller to Domoticz.

Anything I've missed? ...as not seeing any PWM on pin D2 (GPI04) using scope.

robatbentley
Posts: 19
Joined: Saturday 18 March 2017 22:24
Target OS: Raspberry Pi
Domoticz version: 3.8889
Location: Newcastle/UK
Contact:

Re: Espeasy led dimming

Post by robatbentley » Wednesday 28 March 2018 22:43

Been playing around with this solution and beginning to understand it a bit more. ...and looks like my problems is that I don't have curl installed as just setting the cmd http into a browser produces PWM wave form on my scope. Do a bit more tomorrow and get back to this forum.

MikeF
Posts: 192
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: UK
Contact:

Re: Espeasy led dimming

Post by MikeF » Wednesday 28 March 2018 23:44

If you're getting a PWM waveform (on pin 4) suggests that you've got ESPeasy running on your E12, and it's acting on the http command correctly (see the GPIO section of ESPeasy command reference here: https://www.letscontrolit.com/wiki/index.php/GPIO).

The lua example I posted uses curl to send the http command; I'm running Domoticz on a Raspberry Pi - got no experience of using Domoticz (or curl) on Windows, I'm afraid.

robatbentley
Posts: 19
Joined: Saturday 18 March 2017 22:24
Target OS: Raspberry Pi
Domoticz version: 3.8889
Location: Newcastle/UK
Contact:

Re: Espeasy led dimming

Post by robatbentley » Thursday 29 March 2018 14:48

Thanks Mike.

Made some progress and have installed curl on my windows 10 (64bit).
The curl commands (via cmd window) work fine now. i.e. The scope shows the PWM changing as requested.
However, the next stumbling block seems to be the "os.execute(runcommand);" as it just doesn't seem to be doing anything at all. i.e. Scope does not see any changes to PWM when selecting dimming settings from Domoticz switch device. No errors in the Domoticz log.

Does os.execute need any special installations of config to be used?
Any suggestions would be really useful.

robatbentley
Posts: 19
Joined: Saturday 18 March 2017 22:24
Target OS: Raspberry Pi
Domoticz version: 3.8889
Location: Newcastle/UK
Contact:

Re: Espeasy led dimming

Post by robatbentley » Friday 30 March 2018 19:13

Mike,
Sounds like I may have to move into the R-Pi solution to get this working. Do you mind letting me know what your setup is...?
Not sure what OS to consider for this R-Pi, Domoticz, curl, os-execute etc system. Linux, Ubunto or Raspbian...?
Thanks, Rob

madrian
Posts: 239
Joined: Saturday 27 August 2016 1:18
Target OS: -
Domoticz version:
Contact:

Re: Espeasy led dimming

Post by madrian » Friday 30 March 2018 21:17

Create a dummy slider, name it "LED".

In /domoticz/scripts/lua/ put:

script_device_LED.lua

Code: Select all

commandArray = {}
vals = {8,8,9,16,25,36,49,64,81,100,121,144,169,196,225,256,289,324,361,400,441,484,529,576,625,676,729,841,900,961,1023,1023}

DomDevice = 'LED'

IP = '192.168.1.73'
Port = '43333'

LEDtarget = 'LED1_target='
Fadetimer = 'Fadetimer='
FadeTime1 = '2000'
 if devicechanged[DomDevice] then
   print("dev " .. devicechanged[DomDevice]);

   if(devicechanged[DomDevice]=='Off') then 
      DomValue = 0;
      print ("Turning off " .. DomDevice);
      runcommand = "echo " .. (Fadetimer) .."" .. (FadeTime1) .. "," .. (LEDtarget) .. "0  | socat - TCP:" .. (IP) .. ":" .. (Port) .. " ";
      print (runcommand);
     os.execute(runcommand);
    return commandArray
   else
      DomValue = (otherdevices_svalues[DomDevice]);
   end

   CalcValue = vals[DomValue+1];
   print ("Value received from Domoticz was " .. (DomValue) .." ");
   print ("Calculated value for ESP is " .. (CalcValue) .." ");
   if(CalcValue<0) then CalcValue=0; end
   print ("Dimming "  .. (DomDevice) .. " to " .. (CalcValue) .. " ");
   runcommand = "echo " .. (Fadetimer) .."" .. (FadeTime1) .. "," .. (LEDtarget) .. "" .. (CalcValue) .. " | socat - TCP:" .. (IP) .. ":" .. (Port) .. " ";
   print (runcommand);
  os.execute(runcommand);
 end

return commandArray
Check if you have "socat" installed. It's better than anything, because it's not freezing Domoticz while sending the command.

User avatar
ledfreak3d
Posts: 79
Joined: Sunday 01 November 2015 16:30
Target OS: Linux
Domoticz version: 3.8025
Location: Hoorn
Contact:

Re: Espeasy led dimming

Post by ledfreak3d » Wednesday 16 May 2018 9:49

i use this one just uses one scripts for all the easyesp lights



local lights = {
['Aqua Dimmer R/W'] = {ip = '192.168.1.91', pin = '4', rgb = false},
['Aqua Dimmer B/W'] = {ip = '192.168.1.91', pin = '12', rgb = false},
['Keuken-Warm'] = {ip = '192.168.1.40', pin = '5', rgb = false},
['Keuken-Wit'] = {ip = '192.168.1.40', pin = '14', rgb = false},
['Blokhut'] = {ip = '192.168.1.58', pin = '14', rgb = false},
['Lampjes'] = {ip = '192.168.1.58', pin = '4', rgb = false},
['Trap'] = {ip = '192.168.1.57', pin = '14', rgb = false},
['Test'] = {ip = '192.168.1.25', red = '15', grn = '13', blu = '12', rgb = true}
}

function setlight (ip, pin, dvalue)
os.execute("curl 'http://" .. ip.. "/control?cmd=PWM,".. pin .."," .. tostring(dvalue) .. ",1028'")
end

commandArray = {}

for deviceName,deviceValue in pairs(devicechanged) do
if (lights[deviceName]) then
if (deviceValue == 'Off') then
dvalue = 0 ;
elseif (deviceValue == 'On') then
dvalue = 1024
else
inputValue = tonumber(otherdevices_svalues[deviceName])

curve = 1.5848931924611
normalizedCurVal = (inputValue - 1.0) / 99.0
rangedValue = (math.pow(normalizedCurVal, curve) * 1023.0) + 1.0

dvalue = math.ceil(rangedValue)
end

if (lights[deviceName]['rgb']) then
setlight(lights[deviceName]["ip"], lights[deviceName]["red"], dvalue)
setlight(lights[deviceName]["ip"], lights[deviceName]["grn"], dvalue)
setlight(lights[deviceName]["ip"], lights[deviceName]["blu"], dvalue)
else
setlight(lights[deviceName]["ip"], lights[deviceName]["pin"], dvalue)
end
end
end
return commandArray
Unleashe the magic smoke ;)

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests