Ping Sensor and lighting

Hi there,

I am a novice to Lua scripting and based on the forums and wikis constructed the following script. The intent is for the living room light to turn on when the ping sensor detects that my phone is present on the WiFi network but has not been present for 30 minutes or more. The script isn’t working as expected, though I don’t get any errors when running the scene so the variables seem to be configured OK. Could someone please offer advice on how to revise the script so that it works?

Thanks!

local SENSOR = 8
local DELAY = 1800
local SENSORID = “urn:upnp-org:serviceId:SecuritySensor1”
local LVNGRMLGHT = 21
local LGHTID = “urn:upnp-org:serviceId:SwitchPower1”

luup.call_delay( “turnOnLvLght”, 60)

function turnOnLvLght()
local tripped = luup.variable_get( SENSORID, “Tripped”, SENSOR) or “0”
local lastTrip = luup.variable_get( SENSORID, “LastTrip”, SENSOR) or os.time()
lastTrip = tonumber (lastTrip)
if (tripped == “1” and (os.difftime (os.time(), lastTrip) >= DELAY)) then
local lastStatus = luup.variable_get( LGHTID, “Status”, LVNGRMLGHT) or “1”
luup.call_action( LGHTID, “SetTarget”, {NewTarget = lastStatus}, LVNGRMLGHT)
end
end

Check the ServiceIdfor the SecuritySensor1. Yours doesn’t look correct.

You’re right, it should be urn:micasaverde-com:serviceId:SecuritySensor1. Will update and report back.

There are lot’s of details missing in your description … Like what triggers the scene and where your LUUP code is placed.

I would suggest NOT using LUUP but use the PLEG see:
[url=http://forum.micasaverde.com/index.php/topic,13234.0.html]http://forum.micasaverde.com/index.php/topic,13234.0.html[/url]

PLEG Device Setup:
Trigger
Home = Ping Sensor Indicatates I am home
NotHome = Ping Sensor Indicates I am not Home
Night = Day or Night Indicates Night
Condition:
TurnOnLight = Nigth and (NotHome;Home > 30:00)

Then have a scene (TurnOnLight) that is triggered when PLEG satatisfies TurnOnLight

Do you think you could provide a picture of how this is done in PLEG, or a similar simple example, please? I had a fiddle, but it’s a bit over my head without a starting point. Cheers.

PLEG uses the same style of interface as Vera does for Scenes. (Much of the same code).
There is a separate tab for each of it’s major configuration tasks:

[ul][li]Inputs
You provide a name to each of the following inputs you choose to use:
[list]
[li]Triggers - Similar to Scene Triggers[/li]
[li]Schedules - Similar to Scene Schedules[/li]
[li]Device Properties - Any Device Property can be a trigger[/li]
[/list][/li]
[li]Conditions
This is where you put your control logic. It references the named inputs. The Sequence expressions are the most obscure … but also the most powerful construct.[/li]
[li]Actions[/li]
[list]
[li]Output Triggers
[list]
[li]When PLEG has satisfied condition XXX[/li]
[li]When PLEG has satisfied condition XXX and state is Armed or NotArmed
The latter is not working right now because of a Vera bug. A fix was sent to MCV.[/li]
[/list][/li]
[li]Notifications
Just like any other Vera Device.[/li]
[li]Actions
This will be in the next release. This equivalent to the Device and Advanced tab of a Scene … only better![/li]
[/list][/ul]

I expect there will be problems mapping a problem to the appropriate control logic. I have provided some examples on the web site and am willing to help if you provide your scenario.

If you have the PLEG plugin installed and you have the examples I have shown … which part do I need to explain more clearly ?

I installed the Program Logic Event Generator plugin and the Core Files but it seems to hang on Opening pleg_Inputs when I go to the Inputs tab. How do I get past this?

Never mind - seems to work on my other computer, maybe just needed some time to start up.

When you download ANY new code to Vera you always have to refresh your browser window.
It remembers (caches) the old stuff.

Actually it’s the first thing I do when anything weird goes on with Vera.

Going to a new computer effectively did that for you.

[quote=“RichardTSchaefer, post:6, topic:173973”]I have provided some examples on the web site and am willing to help if you provide your scenario.

If you have the PLEG plugin installed and you have the examples I have shown … which part do I need to explain more clearly ?[/quote]

Thank you, I did manage to reach your website the other day, but every time I’ve tried since it’s been down. I must’ve tried it 10 times since it’s been released and I’ve only got through once. Maybe a pic on the forum could help users… or it’s already on here and I’ve missed it.

I’m looking to use the watt reading of a switch to trigger a powering off of said switch, if the watts go below 5W.

At the moment I run a schedule every 5 mins and if the PC is shutdown, it’s only drawing 4W and it sends an action to turn off the z-wave switch.

Attached are my blind attempts. :slight_smile: But I’m not sure what I’m doing…obviously.

Thanks for any help.

So far it looks good …
You can add a notification for now on the PLEG when condition c1 is satisfied.
Or you can create your KarensPCOff scene that is triggered by PLEG when condition c1 is satisfied.

Thank you, that works well. My mistake was trying to do it all in PLEG, and thinking it would flip the switch to armed, or provide some indication the condition had been met, but it happens in the background. :slight_smile:

Using a scene with the trigger pictured below, I can send an off signal now, without having to check every 5 mins.

Cheers.

Haven’t been able to get this to work for me. Installed PLEG and the code backend, plus the Day/Night sensor and I’ve got the Ping sensor installed and pointing to the IP of my phone. PLEG is set up as follows:

Inputs:
Home - Ping Sensor armed is tripped
NotHome - Ping Sensor armed is not tripped
Night - Day or Night indicates Night time

Conditions:
TurnOnLight - Night and (NotHome;Home > 30:00)

I’ve then added a scene as follows:

Devices:
Living Room Light - On

Triggers:
PLEG - TurnOnLight = 1

The expected behavior is that when it’s night time and my phone has not been detected by the ping sensor for at least 30 minutes but then comes online the living room light will turn on. This is not happening, however.

Any thoughts?

For the scene should be:

Trigger where PLEG Device has satisified condition TurnOnLight

The spelling of a condition name when used as a trigger in a scene must match the name of a condition in PLEG.
You can’t put a condition expression there.

Right - to be clear, that’s what I’ve put in the trigger. I changed the Ping Sensor attribute to just say it’s tripped and ignore the armed state, maybe that will help.