Help with Luup function returns and the Door Sensor code

Hi I have been working to switch off the AC when the door sensors are open a x minutes. No issue with this, but I have been testing and I noticed that if the door sensor is out of communication i.e. the battery is flat it defaults to tripped in the GUI and set the variable to match.

If the door sensor code is running it will consider that the door is open and will switch off the AC, and you will enter a deadly loop with the renter turning on the AC and Vera turning it off since it thinks the door is open when the issue is that the sensor is down.

To fix this I thought of forcing a poll and checking the result. This is where I get into trouble the luup function I used is…

lul_resultcode, lul_resultstring, lul_job, lul_returnarguments = luup.call_action(“urn:micasaverde-com:serviceId:HaDevice1”,“Poll”,{},3)

Firstly where are the expected return values described in the Wiki or manual. I cannot find this described. In my tests…

lul_resultcode returns a 0 always regardless of the state of the device on or off.
lul_resultstring returns nothing regardless
lul_job returns a variable that changes every time so I assume it is a system variable
lul_returnargument returns a table

Two questions

  1. Where are the return variables for Luup functions described
  2. How can you implement code to avoid the dead loop if the device status is “dead”

Many thanks

Hi usmampoer,

[ul][li]error: this is -1 if the action couldn’t be invoked, 0 if the UPnP device reported the action was successful, and other number if the UPnP device reported the action failed.[/li]
[li]error_msg: if error wasn’t -1 or 0, this is the error message.[/li]
[li]job: if the action is handled asynchronously by a Luup job, then this is the job number.[/li]
[li]arguments: this is a table of string->string pairs with the return arguments from the action. Usually the pair is “JobID” → .[/li][/ul]

  1. To find if the job was successful use the luup.job.status function, with the job number from the call_action function. However, you must wait at least a couple of seconds before calling it, otherwise you will get the status 1 or 7. Here is the list of possible statuses and their meaning:

[ul][li]-1: No job, i.e. job doesn’t exist.[/li]
[li]0: Job waiting to start.[/li]
[li]1: Job in progress.[/li]
[li]2: Job error.[/li]
[li]3: Job aborted.[/li]
[li]4: Job done.[/li]
[li]5: Job waiting for callback. Used in special cases.[/li]
[li]6: Job requeue. If the job was aborted and needs to be started, use this special value.[/li]
[li]7: Job in progress with pending data. This means the job is waiting for data, but can’t take it now.[/li][/ul]

Please don’t ask for further explanations of these statuses, as I don’t have them. :slight_smile:

Hope this helps.