We have moved at community.getvera.com

Author Topic: Tripped Sensor Lua Code Help!!  (Read 13388 times)

Offline m0jon

  • Full Member
  • ***
  • Posts: 113
  • Karma: +0/-0
  • @m0jon
Tripped Sensor Lua Code Help!!
« on: December 05, 2010, 11:10:11 am »
I'm trying to get a PUSH Message to my iPhone when i get home.

I've installed the ping plugin and have set it up to respond to my iPhones ip address. This then trips the virtual sensor which now exists in my Vera 2 and works great. iPhone wifi on sensor tripped, iPhone wifi off sensor goes back to armed state.

I've the created a scene to respond to the virtual sensor and added the following lua code in the appropriate section of that scene

--iPhone

local lul_tmp = luup.variable_get("urn:schemas-micasaverde-com:device:MotionSensor:1","Status",30)

if (lul_tmp=="Tripped") then

  luup.inet.wget("https://prowl.weks.net/publicapi/add?apikey=5b07921d1411b191a3a1654321ef833e531dej38&application=Vera&event=Message&description=Welcome+Home&priority=-1")

end

not sure if my uup.variable_get is correct?

i have other PUSH Messages sent to my phone for weather events so i know that part works

Any help will be greatly received. ( i've altered the push code so above is not mine or anyone else's)

Cheers

m0jon

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Tripped Sensor Lua Code Help!!
« Reply #1 on: December 05, 2010, 11:48:55 am »
You need to use a URN with the :serviceId: in it, not :device:

It's similar to the problem that was going on here (just with a different Device and Service being used)
    http://forum.micasaverde.com/index.php?topic=4907.0

From this list:
    http://wiki.micasaverde.com/index.php/Luup_UPNP_Files

You want:
  • serviceId -> urn:micasaverde-com:serviceId:SecuritySensor1
  • variable -> Tripped

Offline m0jon

  • Full Member
  • ***
  • Posts: 113
  • Karma: +0/-0
  • @m0jon
Re: Tripped Sensor Lua Code Help!!
« Reply #2 on: December 05, 2010, 12:28:12 pm »
Thanks guessed for your help, which has got me back on the right path.

Just having that well documented trouble with a Virtual Sensor, which is being Tripped but not triggering a scene!!!

Will keep at it and thanks again

m0jon

Offline pepebel4

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Tripped Sensor Lua Code Help!!
« Reply #3 on: December 06, 2010, 07:47:42 am »
I am also trying to use the ping sensor.
I have it working, but do not really see how to use it in an event.
I can schedule a 1 minute timer, this works good.
But I would like to have something to happen 'immediately'; not having to verify every minute (that delay is too big).
When creating a new scene; the 'ping sensor device' is not listed in the device list when selecting to add an event.

Any advice = very welcome!!! )

Offline pepebel4

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Tripped Sensor Lua Code Help!!
« Reply #4 on: December 06, 2010, 09:49:02 am »
Ok, managed to use it now in an event! No help needed anymore (for now)  :P

Offline m0jon

  • Full Member
  • ***
  • Posts: 113
  • Karma: +0/-0
  • @m0jon
Re: Tripped Sensor Lua Code Help!!
« Reply #5 on: December 06, 2010, 04:43:32 pm »
Hi pepebel4

How did you get the ping sensor to trigger a scene. It just won't work for me!!!!!

Offline pepebel4

  • Newbie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Tripped Sensor Lua Code Help!!
« Reply #6 on: December 06, 2010, 05:08:28 pm »
I modifed the D_PingSensor.xml.
I added <staticJson> after the devicetype :

<deviceType>urn:schemas-micasaverde-com:device:MotionSensor:1</deviceType>
<staticJson>D_MotionSensor1.json</staticJson>

Adding this line enables the device to be selected when creating a scene.
Hope that works out for you too.
Tested this evening; works perfect! When I come home in the evening with my iPad; my home welcomes
me with turning on the lights:) Cheaper then a motion sensor (taken into account you already have an iphone/ipad  :P :P )

Offline m0jon

  • Full Member
  • ***
  • Posts: 113
  • Karma: +0/-0
  • @m0jon
Re: Tripped Sensor Lua Code Help!!
« Reply #7 on: December 07, 2010, 10:44:54 am »
Thanks a lot pepebel4 that extra line of code did the trick and the sensor is now triggering scenes.

Cheers

M0jon

Offline mversluis

  • Jr. Member
  • **
  • Posts: 51
  • Karma: +0/-0
Re: Tripped Sensor Lua Code Help!!
« Reply #8 on: December 21, 2010, 04:13:28 pm »
This solution is now working.
Thanks for sharing this info

Marco
An optimist is a person who sees only the lights in the picture,
 Whereas a pessimist sees only the shadows.  An idealist, however is one who sees the light and the shadows, but in addition sees something else:  the possibility of changing the picture, of making the light prevail over shadows.

Offline mversluis

  • Jr. Member
  • **
  • Posts: 51
  • Karma: +0/-0
Re: Tripped Sensor Lua Code Help!!
« Reply #9 on: December 22, 2010, 03:44:24 pm »
Can someone point me into the right direction. I really appropriate it.

I have create 2 ping sensors and 2 scenes. Ip adresses are stated to the computers at our office.

When the ping sensor is tripped ( this mean the computer is turn on) , a event is trigger and will enable the printers and heating at the office. This works really good.

Now I want a step further. When both pc's are not used and turned off I want to shut even shut down the printers.

So would it be possible to create a luup code witch is checking both computers at the office of there are present at the network. When both are not present( i will amuse the are powered off ) then send a off command to the printers.

something like this :

-ping sensor 1 is not tripped AND -ping sensor 2 is not tripped
Then power off printers.

local lul_tmp = luup.variable_get("urn:schemas-micasaverde-com:serviceId:MotionSensor:1","Status",1)
   
if (lul_tmp=="Tripped") then goto end

else
   local lul_tmp = luup.variable_get("urn:schemas-micasaverde-com:serviceId:MotionSensor:1","Status",2)
         if (lul_tmp=="Tripped") then goto end
         else "Power down printers"
         
Endif


Many thanks in advance
Marco
« Last Edit: December 22, 2010, 03:52:58 pm by mversluis »
An optimist is a person who sees only the lights in the picture,
 Whereas a pessimist sees only the shadows.  An idealist, however is one who sees the light and the shadows, but in addition sees something else:  the possibility of changing the picture, of making the light prevail over shadows.

Offline mversluis

  • Jr. Member
  • **
  • Posts: 51
  • Karma: +0/-0
Re: Tripped Sensor Lua Code Help!!
« Reply #10 on: December 22, 2010, 04:25:01 pm »
local lul_tmp = luup.variable_get("urn:schemas-micasaverde-com:serviceId:MotionSensor:1","Status",1)
   
if (lul_tmp=="Tripped")
then
else
   local lul_tmp = luup.variable_get("urn:schemas-micasaverde-com:serviceId:MotionSensor:1","Status",2)
   
      if (lul_tmp=="Tripped")
      then
      else
         luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{ newTargetValue="0" },7)
end


IS this correct ..?
Regards Marco
An optimist is a person who sees only the lights in the picture,
 Whereas a pessimist sees only the shadows.  An idealist, however is one who sees the light and the shadows, but in addition sees something else:  the possibility of changing the picture, of making the light prevail over shadows.

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Tripped Sensor Lua Code Help!!
« Reply #11 on: December 22, 2010, 04:45:46 pm »
See my post above, and check the exact ServiceId used.  It's important.  ;)

Offline mversluis

  • Jr. Member
  • **
  • Posts: 51
  • Karma: +0/-0
Re: Tripped Sensor Lua Code Help!!
« Reply #12 on: December 22, 2010, 05:13:14 pm »
Hi Guessed,

Thanks for the very quick response.

See picture , i suppose the ServiceID would be the Id nr..?
correct ?

Regards,
Marco
An optimist is a person who sees only the lights in the picture,
 Whereas a pessimist sees only the shadows.  An idealist, however is one who sees the light and the shadows, but in addition sees something else:  the possibility of changing the picture, of making the light prevail over shadows.

Offline guessed

  • Community Beta
  • Master Member
  • ******
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Tripped Sensor Lua Code Help!!
« Reply #13 on: December 22, 2010, 05:20:21 pm »
That's a Device Type, not a Service Id.  A device has one Device Type, but can have (implement) multiple Serviced Id's.

You'll want to read my post 2nd from the top, it lists the exact Service Id to use.

Offline mversluis

  • Jr. Member
  • **
  • Posts: 51
  • Karma: +0/-0
Re: Tripped Sensor Lua Code Help!!
« Reply #14 on: December 23, 2010, 03:34:05 pm »
Hi Guessed,

Can you help me please into the right direction.
I have read you're post ( before you pointed me) and i don't get this.

Normally when you have a device , the have a 1 device type and 1 service ID

What I suspect would be something like this :
local lul_tmp = luup.variable_get("urn:schemas-micasaverde-com:serviceId:MotionSensor1","Status",62)

Thanks
Marco
An optimist is a person who sees only the lights in the picture,
 Whereas a pessimist sees only the shadows.  An idealist, however is one who sees the light and the shadows, but in addition sees something else:  the possibility of changing the picture, of making the light prevail over shadows.