The Vera Community forums have moved!

Advanced => Programming => Scene Scripting => Topic started by: m0jon on December 05, 2010, 11:10:11 am

Title: Tripped Sensor Lua Code Help!!
Post by: m0jon 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
Title: Re: Tripped Sensor Lua Code Help!!
Post by: guessed 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:
Title: Re: Tripped Sensor Lua Code Help!!
Post by: m0jon 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
Title: Re: Tripped Sensor Lua Code Help!!
Post by: pepebel4 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!!! )
Title: Re: Tripped Sensor Lua Code Help!!
Post by: pepebel4 on December 06, 2010, 09:49:02 am
Ok, managed to use it now in an event! No help needed anymore (for now)  :P
Title: Re: Tripped Sensor Lua Code Help!!
Post by: m0jon 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!!!!!
Title: Re: Tripped Sensor Lua Code Help!!
Post by: pepebel4 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 )
Title: Re: Tripped Sensor Lua Code Help!!
Post by: m0jon 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
Title: Re: Tripped Sensor Lua Code Help!!
Post by: mversluis on December 21, 2010, 04:13:28 pm
This solution is now working.
Thanks for sharing this info

Marco
Title: Re: Tripped Sensor Lua Code Help!!
Post by: mversluis 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
Title: Re: Tripped Sensor Lua Code Help!!
Post by: mversluis 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
Title: Re: Tripped Sensor Lua Code Help!!
Post by: guessed on December 22, 2010, 04:45:46 pm
See my post above, and check the exact ServiceId used.  It's important.  ;)
Title: Re: Tripped Sensor Lua Code Help!!
Post by: mversluis 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
Title: Re: Tripped Sensor Lua Code Help!!
Post by: guessed 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.
Title: Re: Tripped Sensor Lua Code Help!!
Post by: mversluis 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
Title: Re: Tripped Sensor Lua Code Help!!
Post by: futzle on December 24, 2010, 06:05:05 am
Normally when you have a device , the have a 1 device type and 1 service ID

Normally, yes, but that's a degenerate case. Imagine a remote-controlled power board, with three individually-controllable appliance switches in it.  One device, three on-off services.  Each service would have a "Status" variable, so how would your program get the status of switch #3?

The way it's done is that each switch has its own Service ID.  Same Service type, different Service ID:
* Switch 1: Service type urn:schemas-upnp-org:service:SwitchPower:1, Service ID urn:upnp-org:serviceId:SwitchPower1
* Switch 2: Service type urn:schemas-upnp-org:service:SwitchPower:1, Service ID urn:upnp-org:serviceId:SwitchPower2
* Switch 3: Service type urn:schemas-upnp-org:service:SwitchPower:1, Service ID urn:upnp-org:serviceId:SwitchPower3

That's why you need to provide the Service ID of the variable that you're interested in.  If you like, you can think of the ServiceID and VariableName as a two-part primary key.  Both are needed to get or set a variable uniquely.

Go back to the Advanced tab in UI4 and hover the mouse pointer over the variable name ("Status").  Up pops some hover text.  That's the service ID, and it's needed to query or set that variable's value.
Title: Re: Tripped Sensor Lua Code Help!!
Post by: mversluis on December 24, 2010, 06:38:33 am
Hi Fuzzle,

That make sense to me , so this is a little step further.

Only looking for the "hover text" and there is nothing pops up within a text in the advance screen.
(see picture).


Can you help me with direction i must take a look ..?

Many thanks in advance
Marco
Title: Re: Tripped Sensor Lua Code Help!!
Post by: futzle on December 24, 2010, 03:31:56 pm
Only looking for the "hover text" and there is nothing pops up within a text in the advance screen.
(see picture).

Scroll to the bottom where the true Luup variables are.  Put the mouse pointer right on top of one of the words on the left.

This may be browser-dependent; I am using Firefox 3.6.
Title: Re: Tripped Sensor Lua Code Help!!
Post by: mversluis on December 25, 2010, 03:47:26 am
Oke found,

Thanks for pointed me that way. ( Its a little mess code , there are 3 or 4 different serviceid used for the pingsensor)
I will need to have the Tripped variable and that will use SecuritySensor1

Other question , to check of I will get the way of work :


[System variable]                                                                                 [serviceId]          [status],[Device id]
local lul_tmp = luup.variable_get("urn:schemas-micasaverde-com:serviceId:SecuritySensor1","Tripped",62)

Is This correct :

Tripped return a value with the current state of te device.
with error levels can those have :
0 = sensor not tripped
1= sensor Tripped

Am I correct ..?


What about "Status" , with values will be return by that funtion ?
What about "Armed" , with value will be return by that ..?


Many thanks in advance
Marco
Title: Re: Tripped Sensor Lua Code Help!!
Post by: Ap15e on December 25, 2010, 09:32:41 am
For 'Armed' see http://wiki.micasaverde.com/index.php/Luup_Scenes_Events#Arm_motion_sensor_.237 and http://wiki.micasaverde.com/index.php/Luup_Scenes_Events#Disarm_motion_sensor_.237.

'Status' for switches: 0 or 1

'Status' for locks: ?
Title: Re: Tripped Sensor Lua Code Help!!
Post by: mversluis on December 26, 2010, 08:58:24 am
Totally lost  ???

I just followed everything here is stated to make the ping sensor work in a luup code.
But nothing will work.

Now I have used this code :

local lul_tmp = luup.variable_get("urn:schemas-micasaverde-com:serviceId:SecuritySensor1","Tripped",62)

if (lul_tmp=="0")

then luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="0"},61)
end


And still no result.

Is there some misspelt into my code , or just something other ..?

Many Thanks for you're help.
Marco
Title: Re: Tripped Sensor Lua Code Help!!
Post by: Ap15e on December 26, 2010, 10:29:59 am
urn:micasaverde-com:serviceId:SecuritySensor1
Title: Re: Tripped Sensor Lua Code Help!!
Post by: mversluis on January 03, 2011, 04:05:38 pm
Totally confused.
I hope someone is able to help me ....... ???

I use this code :
local lul_tmp = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",62)

if (lul_tmp=="0")

then local lul_tmp1 = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",63)

if (lul_tmp1=="0")

then luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="0"},61)

end

end


When both pc running at the office are powered down , the ping sensor is not tripped.
When I run the scene manual , the switch will go off . So I will assume the scene is working.

I have added a timer , witch is running every hour to check the pc's are not running any more and will switch off the printers. ( like i tested manual ) .

This will not working  :o :o

Can you please point me into the right direction ..?
Many thanks in advance

best regards,
Marco
Title: Re: Tripped Sensor Lua Code Help!!
Post by: Henk on June 04, 2011, 01:52:39 pm
Totally confused.
I hope someone is able to help me ....... ???

I use this code :
local lul_tmp = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",62)

if (lul_tmp=="0")

then local lul_tmp1 = luup.variable_get("urn:micasaverde-com:serviceId:SecuritySensor1","Tripped",63)

if (lul_tmp1=="0")

then luup.call_action("urn:upnp-org:serviceId:SwitchPower1","SetTarget",{newTargetValue="0"},61)

end

end


When both pc running at the office are powered down , the ping sensor is not tripped.
When I run the scene manual , the switch will go off . So I will assume the scene is working.

I have added a timer , witch is running every hour to check the pc's are not running any more and will switch off the printers. ( like i tested manual ) .

This will not working  :o :o

Can you please point me into the right direction ..?
Many thanks in advance

best regards,
Marco

@mversluis
If you are still following this thread, triggering a scene was a problem for many people until @pepebel4 came up with the json code add for the D_PingSensor.xml

Have you ever checked that codesnippet was in your xml?