humz keep getting a error in domotiz when I try this oneDarkFoxDK wrote:How does os.execute curl compare to the OpenURL command in speed?deennoo wrote:MadBanana wrote:ledfreak3dCode: Select all
... runcommand = "curl 'http://" .. IP .. "/control?cmd=PWM," ..PIN.. "," .. CalcValue .. "'"; ...
Edit: Should've just tested it. It's much faster. Script below updated.
This is my current script for driving my ESPEasy lights, including a way to simulate white on RGB-only strips. It also uses a curve to get higher resolution at the lower end, where the brightness changes are more noticeable.
2nd edit: Cleaned up the code a bit.Code: Select all
local lights = { ['Stuereol Spots'] = {ip = '192.168.33.61', pin = '14', rgb = false}, ['Stuereol Skab'] = {ip = '192.168.33.61', pin = '4', rgb = false}, ['Vitrineskab'] = {ip = '192.168.33.62', pin = '13', rgb = false}, ['Kontorreol'] = {ip = '192.168.33.64', pin = '13', rgb = false}, ['Skrivebord'] = {ip = '192.168.33.67', pin = '14', rgb = false}, ['Sengelys'] = {ip = '192.168.33.66', pin = '14', rgb = false}, ['Kontorhylde W'] = {ip = '192.168.33.67', red = '15', grn = '13', blu = '12', rgb = true}, ['Stuereol W'] = {ip = '192.168.33.61', red = '15', grn = '13', blu = '12', rgb = true}, ['Seng W'] = {ip = '192.168.33.66', red = '15', grn = '13', blu = '12', rgb = true} } function setlight (ip, pin, dvalue) os.execute("curl 'http://" .. ip.. "/control?cmd=PWM,".. pin .."," .. tostring(dvalue) .. ",128'") 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
[string "local lights = { ..."]:12: bad argument #1 to 'pairs' (table expected, got nil)
cant realy figure out why