Unable to change a device status with LUA

Moderator: leecollings

Post Reply
gbuico
Posts: 14
Joined: Saturday 25 November 2017 13:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Nice, France
Contact:

Unable to change a device status with LUA

Post by gbuico »

I'm currently testing how to change the status of a device On/Off or Open/Close.
For this purpose I wrote a very simple LUA security event which is supposed to do the following:
1) When I go on the security panel and press Disarm, I want "Relay 0" to go Off
2) When I go on the security panel and press Arm Away, I want the shutter "Kitchen shutter" to become "Closed"

Function 1 works perfectly, function 2 doesn't work at all.
"Relay 0" is a relay on a Piface Digital 2 directly connected to Raspberry and is defined as Lighting, Impuls, On/Off
"Kitchen shutter" is a Blyss blind controller, interfaced via RFLink and defined as Light/Switch, Blyss, Blinds inverted

An important information is that "Kitchen shutter is perfectly opening, closing and stopping the movement of the shutters if I change its status from the Device or Dashboard panels

Here is the LUA code I'm using for test:

Code: Select all

commandArray = {}
        if globalvariables['Security'] == 'Disarmed' 
        then
            commandArray['Relay 0'] = 'Off'
        end
        if globalvariables['Security'] == 'Armed Away' 
        then
            print (otherdevices['Kitchen shutter']) 
            commandArray['Kitchen shutter'] = 'Close'
            print ('here')
            print (otherdevices['Kitchen shutter']) 
        end 
return commandArray
Any help/suggestion?
User avatar
jvdz
Posts: 2267
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Unable to change a device status with LUA

Post by jvdz »

This script doesn't look right to me as that would set the devices each time it is executed in stead of when the status changes unless this is the scripname "script_security_panel-changes.lua".
Is it that scriptname in /domoticz/scripts/lus or else how is this script ran?
What exactly is not working as I would expect it to constantly set "relay 0" to Off at this moment?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
gbuico
Posts: 14
Joined: Saturday 25 November 2017 13:39
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.8153
Location: Nice, France
Contact:

Re: Unable to change a device status with LUA

Post by gbuico »

Let me first say that in the meanwhile I found the solution and will come to it in a minute.
Let me first answer your questions.
Having in mind that this LUA event is just for testing and not supposed to be used as such, I created this event in the internal editor saying it is written in LUA and should be called for Security events.
The logic is made of two pieces, first one executed when the system is Disarmed from the Security Panel, the second one when Armed Away is set.
As you see there is a Print statement that allowed me to check that the logic of the "if" was working properly.

Now let me go to the solution that I found by chance looking at the log of the RAW data sent to RFLink. There I saw that when I was changing manually the status of the blind in the Device page, the command sent was not "CLOSE" but "DOWN"
I checked in the documentation and I found no way to set "DOWN" so I just tried to try
commandArray['Kitchen shutter'] = 'Off'
instead of the "Close' .... and... pufff... working fine.
Conclusion, I found my solution but I find a bit strange that you should use an On/Off command to change the stats of a device that can be Open or Closed
I'd love to hear from the development team if they agree or no

Giacomo
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest