Page 1 of 1

Lua not working because of device state

Posted: Wednesday 25 December 2019 17:35
by Willem81
HI all!

Merry X-mas :-)

I am struggling with Lua and I hope that somebody can help me.

I have Curtains which are controlled by Zwave (Zwave Fibaro Roller Shutter 2) and added in Domoticz as a Curtain (without Level).

I would like to create a Dummy switch (Push On button) which when enabled opens the curtains when closed, and closes them if open. With this Push button I then can create a Scene which I need for my double click function on a Wall Switch.

Therefore I created this Lua:

(Gordijnen = Curtains, the real Domoticz 'Inverted Blinds')
(DummyHulpGordijnen = my dummy Push On button)
commandArray = {}
if (devicechanged['DummyHulpGordijnen'] == 'On' and otherdevices['Gordijnen'] == 'Open') then
print("Gordijnen dicht")
commandArray['Gordijnen']='Off'
elseif (devicechanged['DummyHulpGordijnen'] == 'On' and otherdevices['Gordijnen'] ~= 'Open') then
print("Gordijnen open.")
commandArray['Gordijnen']='On'
end
return commandArray
I expected its states to be Open / Closed. Because the Log says "On / Off" I first made te script with On/Off: This didn't work.
Then I changed to the script above. This worked, but only in one direction. It does not matter if the curtains are open or closed, Lua Always says it is Open. So if my curtains are Closed, it still thinks they have the status "Open" and it tries to close them again.

I tried all kind of things, but I just cannot find the solution. Is there maybe a way to print the current status of the switch "Gordijnen" ? Then maybe I can find out what to put in my Lua script to know they are Closed.

Really strange problem. It seams that my Fibaro Roller Shutter does not report the right/changed status back. Although open and close work using the normal Inverted Blind switch in Domoticz.

I hope someone knows a solution

Re: Lua not working because of device state

Posted: Monday 13 January 2020 13:57
by bewo
Hi Willem81,

your script look's ok, it should be triggered... Hmm... maybe try in an other way:
(And be sure that the script is trigger-mode of the script is set to "device"!)

Code: Select all

commandArray = {}

if devicechanged['DummyHulpGordijnen'] then
	if otherdevices['Gordijnen'] == 'Open' then
		print("Gordijnen dicht")
		commandArray['Gordijnen'] = 'Off'
	else
		print("Gordijnen open.")
		commandArray['Gordijnen'] = 'On'
	end
end

return commandArray 
Is there maybe a way to print the current status of the switch "Gordijnen" ?
Yes, there is:

Code: Select all

commandArray = {}
	print(otherdevices['Gordijnen']) 
return commandArray