Espeasy led dimming
Moderator: leecollings
- thecosmicgate
- Posts: 188
- Joined: Monday 06 April 2015 14:37
- Target OS: Linux
- Domoticz version: newest
- Location: The Netherlands / Hoeven
- Contact:
Espeasy led dimming
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
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 ;)
Scooter ;)
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: Espeasy led dimming
Try this:
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.
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
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.
-
- Posts: 17
- Joined: Saturday 18 March 2017 21:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8889
- Location: Newcastle/UK
- Contact:
Re: Espeasy led dimming
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.
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.
-
- Posts: 17
- Joined: Saturday 18 March 2017 21:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8889
- Location: Newcastle/UK
- Contact:
Re: Espeasy led dimming
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.
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: Espeasy led dimming
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.
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.
-
- Posts: 17
- Joined: Saturday 18 March 2017 21:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8889
- Location: Newcastle/UK
- Contact:
Re: Espeasy led dimming
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.
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.
-
- Posts: 17
- Joined: Saturday 18 March 2017 21:24
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.8889
- Location: Newcastle/UK
- Contact:
Re: Espeasy led dimming
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
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
Re: Espeasy led dimming
Create a dummy slider, name it "LED".
In /domoticz/scripts/lua/ put:
script_device_LED.lua
Check if you have "socat" installed. It's better than anything, because it's not freezing Domoticz while sending the command.
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
- ledfreak3d
- Posts: 98
- Joined: Sunday 01 November 2015 15:30
- Target OS: Linux
- Domoticz version: 3.8025
- Location: Hoorn
- Contact:
Re: Espeasy led dimming
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
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 ;)
-
- Posts: 13
- Joined: Monday 31 August 2015 14:52
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Espeasy led dimming
Hmm, bij mij lukt op een of andere manier de "pairs" operator niet.
Code: Select all
[string "--..."]:42: bad argument #1 to 'pairs' (table expected, got nil)
- jvdz
- Posts: 2189
- Joined: Tuesday 30 December 2014 19:25
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.107
- Location: Netherlands
- Contact:
Re: Espeasy led dimming
Guess you are running it as Time event and not only as Device event?
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
-
- Posts: 13
- Joined: Monday 31 August 2015 14:52
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Espeasy led dimming
ok, that was the issue..
When using a normal dimmer value the script works as it should. I tested with rgb and then the output value is either 0, 1024 or if you want to make a color it outputs always 476 no matter which color is selected
After a bit of struggle this now seems to work well for me. I am using the PCA9685 so I need to write each color separate to the ESP..
When using a normal dimmer value the script works as it should. I tested with rgb and then the output value is either 0, 1024 or if you want to make a color it outputs always 476 no matter which color is selected
After a bit of struggle this now seems to work well for me. I am using the PCA9685 so I need to write each color separate to the ESP..
Code: Select all
local devicename
devicename = 'Carport'
return {
on = {devices = {devicename}},
execute = function(domoticz, device)
local kleur
local brightness
local state
kleur = domoticz.devices(devicename).getColor()
brightness = domoticz.devices(devicename).level
state = domoticz.devices(devicename).state
local rood
local blauw
local groen
if (state == 'Off') then
os.execute('curl "http://10.0.1.19/control?cmd=PCAPWM,0,0"')
os.execute('curl "http://10.0.1.19/control?cmd=PCAPWM,1,0"')
os.execute('curl "http://10.0.1.19/control?cmd=PCAPWM,2,0"')
else
brightness = brightness/25
rood = domoticz.utils.round(kleur.r * brightness,0)
groen = domoticz.utils.round(kleur.g * brightness,0)
blauw = domoticz.utils.round(kleur.b * brightness,0)
os.execute('curl "http://10.0.1.19/control?cmd=PCAPWM,0,'..blauw..'"')
os.execute('curl "http://10.0.1.19/control?cmd=PCAPWM,1,'..groen..'"')
os.execute('curl "http://10.0.1.19/control?cmd=PCAPWM,2,'..rood..'"')
print ("R = " ..rood.. ", G = " ..groen.. ", B = "..blauw);
end
end
}
-
- Posts: 1
- Joined: Wednesday 25 September 2024 20:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: Espeasy led dimming
Hi,
I set up everything as you described and variable "dimmer" does not update as I move the dimmer slider. When updated manually, with json link everything seems to work fine. Where is my mistake? Which variable type should i choose? String?
I set up everything as you described and variable "dimmer" does not update as I move the dimmer slider. When updated manually, with json link everything seems to work fine. Where is my mistake? Which variable type should i choose? String?
MikeF wrote: ↑Sunday 14 January 2018 23:14 Try this: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.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
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.
Who is online
Users browsing this forum: No registered users and 0 guests