ESPEasy LED dimming with LUA
Posted: Tuesday 16 January 2018 11:43
I'm using the following LUA script for dimming an LED strip connected to an ESP8266 running ESPEasy:
This works well for me, and restores the last dim value if I switch off and back on by clicking the device's icon in Domoticz.
However, if I power off and then power on the ESP8266, the LED strip remains off, even though Domoticz shows the dimmer as on (and at its last dim value).
Is there any way in LUA (or dzVents) to change the device state on power on?
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
However, if I power off and then power on the ESP8266, the LED strip remains off, even though Domoticz shows the dimmer as on (and at its last dim value).
Is there any way in LUA (or dzVents) to change the device state on power on?