Author Topic: Conditional Scene Execution: Some Examples  (Read 156445 times)

Offline blairRosen

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #255 on: May 18, 2017, 09:23:54 pm »
Thank you.  Wow. They couldn't make it less intuitive if they tried.  You are right, under Variable, if I hover of over "UI7check" it says "urn:upnp-org:serviceId:VSwitch1". Another question if you don't mind. Since I don't want to have the scene run because  I have set "local allow =  false" what is the function of the line "return ((status == "1") == allow)"

In any event , based on your comments, would it be correct to say the LUUP code for not allowing the scene to run when the Summer Virtual Switch ID 148 is on would be:

Summer:
Code: [Select]
local dID = 148
local allow = false
local status = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",dID)
return ((status == "1") == allow)

Thanks again.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 799
  • Karma: +18/-7
    • Worthington Engineering, Inc.
Re: Conditional Scene Execution: Some Examples
« Reply #256 on: May 18, 2017, 09:34:07 pm »
+1 to jswim788.
Vera 3, UI7 1.7.947, CT101 t-stat, Everspring motion detector, GE/Jasco switch, Leviton outlet, AeonLabs door sensor, Insteon garage control, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual & Multi Switch, Weather, Sys. Mon.

Offline blairRosen

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #257 on: May 18, 2017, 09:58:28 pm »
Following Up:   This LUUA code did not work:

Summer:
Code: [Select]
local dID = 148
local allow = false
local status = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",dID)
return ((status == "1") == allow)

I got the message "error in lua for scenes and events"

Offline jswim788

  • Sr. Member
  • ****
  • Posts: 480
  • Karma: +23/-2
Re: Conditional Scene Execution: Some Examples
« Reply #258 on: May 19, 2017, 12:24:32 am »
You are not including the "Summer: and Code" are you?  Not needed and will cause a syntax error.  And the "allow" stuff was to make it flexible, but it confuses more people than it helps.  Finally, you need the return to say whether the scene runs or not.  This is simpler:
Code: [Select]
local dID = 148
local status = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",dID)
return (status == "0")
By the way, run this in the test code window of Vera.  It should indicate a pass if your switch is off and a fail if the switch is on.

Change the above to check for "1" if you want your scene to run if the switch is on.

Offline blairRosen

  • Newbie
  • *
  • Posts: 5
  • Karma: +0/-0
Re: Conditional Scene Execution: Some Examples
« Reply #259 on: May 19, 2017, 08:23:57 am »
You are a genius.  When I removed the lines "Summer: and Code",  both variations of your code post, the original and the simpler one in your last post, worked without error.  Now hopefully everything will work as planned. I very much appreciate the time and effort you took to solve my problem.  One suggestion to help us newbies. When posting code, perhaps the programmers should distinguish between the text necessary to run and that which is not. A great way would be  by enclosing the executable lines between horizontal bars as in your last post. BTW this has convinced me that I ought to at least learn the elements of rudimentary programming for lua.  Can you suggest an online tutorial?

Offline jswim788

  • Sr. Member
  • ****
  • Posts: 480
  • Karma: +23/-2
Re: Conditional Scene Execution: Some Examples
« Reply #260 on: May 19, 2017, 09:42:28 am »
This is a good starting point for Lua: https://www.lua.org/pil/1.html

I'd never heard of Lua until I stumbled into it with Vera.  I'm not sure where else it is used.

Offline aa6vh

  • Hero Member
  • *****
  • Posts: 597
  • Karma: +12/-0
Re: Conditional Scene Execution: Some Examples
« Reply #261 on: May 19, 2017, 10:19:41 am »
I'd never heard of Lua until I stumbled into it with Vera.  I'm not sure where else it is used.

The Watchmaker app for Android smartwatches uses the LUA Language. (Makes it a lot simplier when programming the smartwatch to control Vera stuff.)

Offline doinitsideways

  • Jr. Member
  • **
  • Posts: 53
  • Karma: +2/-0
Re: Conditional Scene Execution: Some Examples
« Reply #262 on: June 29, 2017, 12:15:57 am »
You are not including the "Summer: and Code" are you?  Not needed and will cause a syntax error.  And the "allow" stuff was to make it flexible, but it confuses more people than it helps.  Finally, you need the return to say whether the scene runs or not.  This is simpler:
Code: [Select]
local dID = 148
local status = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",dID)
return (status == "0")
By the way, run this in the test code window of Vera.  It should indicate a pass if your switch is off and a fail if the switch is on.

Change the above to check for "1" if you want your scene to run if the switch is on.

Hi there, im trying to get a scene to turn on a light when i turn my water feature on ONLY at night using the DayNight plugin.

Everytime i run the following through the test area in develop app it just says code sent succesfully, no pass or fail comment regardless of changing the status to 1 or 0

Code: [Select]
local dID = 11
local allow = false
local status = luup.variable_get("urn:schemas-rts-services-com:device:DayTime1","Status",dID)
return ((status == "1") == allow)

Not sure what i am doing wrong. The dID is from the device ID tab for the day night plugin and the urn.... is copied directly from the Advanced-Device Type field...

Cheers,
Josh

Offline jswim788

  • Sr. Member
  • ****
  • Posts: 480
  • Karma: +23/-2
Re: Conditional Scene Execution: Some Examples
« Reply #263 on: June 29, 2017, 05:02:06 pm »
Are you sure about that URN?  I may have a different version of the DayTime plugin, but mine is "urn:rts-services-com:serviceId:DayTime"

Did you hover the mouse over the "Status" variable?  That's the way to see the URN.  (Or open up the plugin's files.)

If you had the URN incorrect, it would result in the behavior you see.  If this doesn't work, I'd really recommend installing AltUI and using its debug window which is really helpful.  Or you can use luup.log and check your log file.  But my guess is the URN.

On a side note, if you only want to check for night, there is the built in "luup.is_night()".  But I suspect you want more than that which is why you are using DayTime.

Offline RichardTSchaefer

  • Master Member
  • *******
  • Posts: 9566
  • Karma: +729/-135
    • RTS Services Plugins
Re: Conditional Scene Execution: Some Examples
« Reply #264 on: June 30, 2017, 07:54:59 pm »
@jswim788 is correct ... you have a device URN and not a service URN ... these are different things in Vera.