ESPEasy LED dimming with LUA

Moderator: leecollings

Post Reply
MikeF
Posts: 350
Joined: Sunday 19 April 2015 0:36
Target OS: Raspberry Pi / ODroid
Domoticz version: V2022.2
Location: UK
Contact:

ESPEasy LED dimming with LUA

Post 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?
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: ESPEasy LED dimming with LUA

Post 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.
MikeF
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 with LUA

Post 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%)
haajee
Posts: 11
Joined: Tuesday 30 October 2018 17:31
Target OS: Linux
Domoticz version: V4.10149
Location: the Netherlands
Contact:

Re: ESPEasy LED dimming with LUA

Post 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?? :(
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest