Lua not working because of device state

Moderator: leecollings

Post Reply
Willem81
Posts: 35
Joined: Wednesday 13 January 2016 10:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Lua not working because of device state

Post 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
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: Lua not working because of device state

Post 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 
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest