General > Lock, Motion & Security Control

How I created a virtual motion sensor device

(1/2) > >>

I've just been poking around the forums and from various threads worked out how to create a virtual motion sensor device. I am using a VeraPlus UI7.

Some background: I have a Fibaro Double Switch relay module connected to some bog standard PIR Security Flood lights in my back garden.

When these PIR flood lights detect motion from their inbuilt motion sensors they turn on. Reading the currently used wattage on the Fibaro Double Switch module, I can determine if the flood lights have come on, hence motion was detected. And when they automatically turn off again after a minute or so, the wattage on the Fibaro module will go back to 0 e.g no motion.

So I plan to use some PLEG logic to control the virtual motion sensor and if it is tripped or not etc.

Here is how I created my virtual motion sensor device in Vera.

1. Go to Apps - Develop Apps - Create Device

In the "Description" field enter a name for your new device, I used: "Motion Sensor (Virtual)"
In the Upnp Device Filename field enter: D_MotionSensor1.xml
Select a room for the device to be located in and click the create device button.

2. Upload the attached I_MotionSensor1.xml file to your Vera. This makes the Disarmed / Armed buttons work in the GUI for the virtual motion sensor device.

Go to Apps - Develop Apps - Luup Files

Click the Upload button and browse to the I_MotionSensor1.xml file to upload it.

3. Edit the Parameters of the new Virtual motion sensor device

Go in to the device then go to Advanced - Params tab

Scroll down and look for device_json and enter D_MotionSensor1.json in to the field and then press tab on the keyboard.
look for impl_file and enter I_MotionSensor1.xml in to the field and then press tab on the keyboard.

Also whilst in here make a note of the devices ID number in my case it was 287.

Go to Settings - Z-Wave Settings - Advanced tab and select Reload Engine hit the Go button and wait for the engine to restart.

4. Perform two actions to make the variables appear for Armed and Tripped.

a. First from the devices list in the web GUI find your new virtual motion sensor and press the Armed button from being Disarmed.

b. Run this command, go to Apps - Develop Apps - Test Luup Code (Lua) paste it in to the box and then click the Go button.

But change the DeviceNum from 287 to whatever the device number is of your new virtual motion sensor.

--- Code: ---luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 1,287)
--- End code ---

This should change the virtual motion sensors status to tripped and you will then see a Red icon on it.

5. Check what you did in step 4. worked? In the Vera web GUI in the browser hit the F5 or reload the browser page. Now go back in to the Virtual Motion sensor device and go to Advanced - Variables tab. You should now see some variables have been added "Tripped" and "Armed"

The values of these variables will be 0 for OFF (Not Tripped) or 1 for ON (Tripped) etc.

That's it the new virtual motion sensor device has been created.

Now you need to create a scene or some PLEG logic to trip / untrip the virtual motion sensor device, to suit your requirements.

This is how the new virtual device looks in the UI7 web GUI, see screen shots.

If I made any mistakes or missed anything? Let me know!  ;D


I seem to have hit a snag with my PLEG logic and setting the Tripped variable in my actions.

If I use this http command it works and the Tripped variable is set to 1 and the motion sensors icon changes to red OK.

--- Code: ---
--- End code ---

However if instead I try to send a luup.variable_set to the virtual motion sensor instead like:

--- Code: ---luup.variable_set("urn:upnp-org:serviceId:SecuritySensor1", "Tripped", 1,287)
--- End code ---

It seems to create a second variable called Tripped and sets it to 1 and the icon does not change to red.

So then I end up with two variables called "Tripped" see screen shot.

I guess I could use a wget to send the http command in the PLEG action but its not ideal.

--- Code: ---luup.inet.wget("")
--- End code ---

Anyone know why when using a luup.variable_set command named Tripped it creates a second Tripped variable ?

OK here is my PLEG logic I just setup, I've not fully tested it yet as it not dark outside yet, but manually running the PLEG actions does change the Tripped status of the virtual motion sensor OK.

On the Fibaro Double Switch relay, I am using one side of it connected to a wall switch and to two PIR security flood lights, the other side of the relay is used for something else not related.

So in PLEG under device properties, I created a new one for the correct portion of the Fibaro Double Switch relay connected to my flood lights to monitor the current wattage.

For some reason when the lights are off but the relay is turned on, it says 0.6 watts are being used so I took that into consideration with my logic.

1. Device Property


Device Name
Flood Lights[278] 
Device Variable


2. Conditions

I created two conditions one for ON aka Greater than 1W and one for OFF aka Less than 1W.


Logic Expression

Comments: Device Status - If the current wattage of the Flood Lights is Greater than 1W


Logic Expression
Comments: Device Status - If the current wattage of the Flood Lights is Less than 1W

3. Logic Actions

I then created the two actions in PLEG. The one for when the PIR security lights have turned on sends me a Vera Alerts notification and also trips the virtual motion sensor.

The action for when the PIR security lights have turned off again, just un-trips the virtual motion sensor.


Condition is True with Repeats                                       

Defined Actions
Immediate - 2   

Comments: Device Status - If the current wattage of the Flood Lights is Greater than 1W then send Vera Alerts notification and trip the virtual motion sensor device


Condition is True with Repeats                                       

Defined Actions
Immediate - 1   

Comments: Device Status - If the current wattage of the Flood Lights is Less than 1W then un-trip the virtual motion sensor device

cFloodLights_Watts_On.png and cFloodLights_Watts_Off.png are the two PLEG actions to set the tripped status on the virtual motion sensor using the LUA tab option and the correct command in each.

LUA code to trip the virtual motion sensor:

--- Code: ---luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 1,287)
--- End code ---

LUA code to un-trip the virtual motion sensor:

--- Code: ---luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Tripped", 0,287)
--- End code ---

You are getting different variables because you are using different SID's:

--- Code: ---urn:upnp-org:serviceId:SecuritySensor1
--- End code ---
A unique variable is defined both by the SID and the variable name.


[0] Message Index

[#] Next page

Go to full version