Author Topic: checking or light level before turning lights on  (Read 223 times)

Offline ricsod

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
checking or light level before turning lights on
« on: August 13, 2017, 11:05:54 am »
I have a Fibaro motion detector and various controllable lamps and switches. A simple scene turns lights and switches on as soon as movement is detected and turns them off after a set number of minutes.

In order to limit the lights-on to times with low light intensity I?ve added a Lua script to the scene:

----- begin snippet ------

local light = tonumber((luup.variable_get("urn:micasaverde-com:serviceId:LightSensor1","CurrentLevel",80)))
 if (light>100.0)
 then
     return false
  else
     return true
  end

----- end snippet ------

(The first line works in other scripts)

My impression is that this function should prevent the scene from executing. However, this results in an error message in Vera.
If I tail the error log on the Vera with
tail -f LuaUPnP.log | grep "^01"
 I just get:

 01      08/13/17 15:50:32.398   LuaInterface::StartEngine returned false: 0 <0x737f4520>
  01      08/13/17 15:50:32.399   JobHandler_LuaUPnP::RunLua failed: local light = tonumber((luup.variable_get("urn:micasaverde-com:serviceId:LightSensor1","CurrentLevel",80)))

What am I doing wrong?
TIA,
/RS
 




Offline jswim788

  • Hero Member
  • *****
  • Posts: 538
  • Karma: +29/-2
Re: checking or light level before turning lights on
« Reply #1 on: August 14, 2017, 04:32:32 pm »
Maybe double check that the device really has the device ID of 80, that the URN is correct for the variable "CurrentLevel"?

Note that you should be able to run this in the test luup code window which might make debug a little easier.  AltUI's debug window is more helpful if you have it.

Offline jlind

  • Full Member
  • ***
  • Posts: 197
  • Karma: +7/-5
Re: checking or light level before turning lights on
« Reply #2 on: August 15, 2017, 02:19:33 pm »
Try changing your if statement to:
Code: [Select]
if (tonumber(light)>100.0)

I've noticed that vera handles comparison operations differently.  Even though the variable is saved as a number, sometimes it doesn't compare as a number.
VeraLite/VeraPlus with UI7, Multiple GE switches, GE Outlets, Aeon Smart Switches, Minimote, GE Portable outlets  Apps: (Pentair Autelis Plugin, Weather Underground, Honeywell WiFi Thermo, System Monitor, AlternateUI)

Offline ricsod

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
Re: checking or light level before turning lights on
« Reply #3 on: August 16, 2017, 02:05:35 pm »
Thx, will try this.
/RS