Page 1 of 1

ESPEasy LED dimming with LUA

Posted: Tuesday 16 January 2018 11:43
by MikeF
I'm using the following LUA script for dimming an LED strip connected to an ESP8266 running 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
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?

Re: ESPEasy LED dimming with LUA

Posted: Tuesday 16 January 2018 12:36
by freijn
You can send 'system info' from the Easy ESP to the domoticz , as soon as something is fails you can reset the status.

Re: ESPEasy LED dimming with LUA

Posted: Tuesday 16 January 2018 13:20
by MikeF
Many thanks for this pointer!

I delved into ESPeasy Rules, and set up this simple rule:

Code: Select all

On System#Boot do
   SendToHTTP 192.168.0.63,8080,/json.htm?type=command&param=switchlight&idx=269&switchcmd=Set%20Level&level=50
endon
(which turns it on at 50%)

Re: ESPEasy LED dimming with LUA

Posted: Thursday 05 September 2019 13:13
by haajee
Why is it so difficult in Domoticz to add a dimmer from ESPEasy... I have a dimmer what would work perfectly with PWM commands. But integration in Domoticz looks like a nogo.

A copy and paste the script aboven but get contineusly a error:

Code: Select all

2019-09-05 13:12:20.696 Status: LUA: Other
2019-09-05 13:12:20.696 Error: EventSystem: in v3-berging: [string "--..."]:64: attempt to call global 'toString' (a nil value)
How could i get my dimmer working in domoticz?? :(