Author Topic: Trouble with Luup code  (Read 3548 times)

Offline MarkC

  • Jr. Member
  • **
  • Posts: 86
  • Karma: +0/-0
Trouble with Luup code
« on: June 09, 2011, 07:50:37 pm »
Hi,

I am currently trying to teach myself some basic Luup code. I have several things working but I'm struggling a bit with appliance modules. From what I can find in the Luup manuals, getting the status of an Appliance Module (HA02) should go something like this;

local lul_tmp = luup.variable_get("urn:upnp-org:serviceId:SwitchPower1","Status",7)
 if( lul_tmp=="1" ) then
    return false
 end

The device number I'm trying to access is 7

I get a message in the Luup test window saying "bad device" and I can't seem to get around it.

Can anyone see what I'm doing wrong?

Thanks,

Mark

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Trouble with Luup code
« Reply #1 on: June 09, 2011, 09:53:07 pm »
It looks correct. 

Do you have a screenshot of the Device's "Dialog", showing the Device # you're using?

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Trouble with Luup code
« Reply #2 on: June 10, 2011, 06:38:24 am »
Did you get the device number from where it says Device #7 (see Capture1.png) or from the altid (see Capture2.png)? The correct device number is the one from Capture1.png (Device #7).

Offline MarkC

  • Jr. Member
  • **
  • Posts: 86
  • Karma: +0/-0
Re: Trouble with Luup code
« Reply #3 on: June 10, 2011, 07:18:49 am »
I got it from the "Device #7" at that top. I've also tried it on a couple of other devices, no joy.

Trying to post a screen shot but not having much luck.




Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Trouble with Luup code
« Reply #4 on: June 10, 2011, 07:49:25 am »
The Device number field must be left empty for the code to work. Try again with the empty field and tell us if it worked.

Offline MarkC

  • Jr. Member
  • **
  • Posts: 86
  • Karma: +0/-0
Re: Trouble with Luup code
« Reply #5 on: June 10, 2011, 08:22:21 am »
Yep, worked now, thanks. I thought that field had to be populated (*).

Thanks again.

Offline robinnes

  • Full Member
  • ***
  • Posts: 171
  • Karma: +0/-0
Re: Trouble with Luup code
« Reply #6 on: June 10, 2011, 12:42:31 pm »
Yep, worked now, thanks. I thought that field had to be populated (*).

Thanks again.
Yeah, that one got me too when I first started with Vera!
Just cause it's clearly noted: "* Required fields" doesn't mean it's required. As a matter of fact actually including the device ID in "* Required fields" box usually causes the test to fail ???

The more you use it the more you'll see there's lots and lots of bugs/misinformation in the control panel....
« Last Edit: June 10, 2011, 12:45:33 pm by robinnes »

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Trouble with Luup code
« Reply #7 on: June 10, 2011, 01:41:53 pm »
I removed the asterisk from there, but this will be seen only on newer firmware versions.

Offline robinnes

  • Full Member
  • ***
  • Posts: 171
  • Karma: +0/-0
Re: Trouble with Luup code
« Reply #8 on: June 10, 2011, 02:00:32 pm »
I removed the asterisk from there, but this will be seen only on newer firmware versions.
Is there any reason to even have a "device number" box at all... just asking?

Offline mcvflorin

  • Administrator
  • Hero Member
  • *****
  • Posts: 1755
  • Karma: +11/-3
Re: Trouble with Luup code
« Reply #9 on: June 13, 2011, 06:11:28 am »
If a device number is present, then the Lua code is run with that device's Lua interface. Otherwise, it is run with the same interface as the code from Scenes. However, there seems to be a bug when a device number other than 0 is present. I asked Aaron about this and he'll decide if we keep that field or not.

Honestly, I don't know what are the advantages of running the code with a device's specific interface, but I will try to find out.