The Vera Community forums have moved!

Advanced => Programming => Plugins & Plugin Development => Topic started by: rigpapa on February 25, 2018, 10:41:54 am

Title: PLUGIN: Virtual Sensor
Post by: rigpapa on February 25, 2018, 10:41:54 am
This is a development tool that I've used to assist in the development and testing of other plugins. I decided to package and release it, on the chance that others may find it useful. It has utility not just for developers, but for any Vera user testing their work with scene triggers, PLEG, etc.

VirtualSensor can emulate a security sensor (tripped/not tripped, e.g. motion, door, etc.), temperature sensor, humidity sensor, light sensor, or generic sensor. It uses a simple sinusoidal function with user-settable parameters to produce output data. To other devices, it appears and operates as any sensor would. It also can emulate battery drain and replacement behavior. While there are other virtual sensors out there, many are old (pre-UI7) and not consistently maintained, the landscape is fragmented (many plugins to do the work of one), and didn't give me the kind of control I wanted for my testing purposes.

Documentation and the latest "edgy" code for project can be found in its GitHub repository. (https://github.com/toggledbits/VirtualSensor)


UPDATE HISTORY
2019-01-20: Version 1.4 submitted to Vera Plugin Marketplace for approval; immediately available in AltAppStore. This version allows the user to create any number of sensors (temp, humidity, light, generic, or security), where the sensor's well-known value is simply copied from any state variable in any other device.

2018-07-29: Version 1.3 released. Just a fix to follow Vera semantics for ArmedTripped and LastTrip more closely, by allowing both Vera and openLuup to manage them (VirtualSensor no longer touches them).

2018-03-05: Version 1.2 released, available in Vera plugin marketplace. Allows the external control of trip and reset by actions (service urn:toggledbits.com:serviceId:VirtualSensor1 actions Trip and Reset, no parameters), or through UI on control panel.

2018-02-26: Version 1.1 is now available in the Vera plugin marketplace. Add battery emulation, improved UI controls, and a number of code cleanups.

2018-01-19: Version 1.0 released.
Title: Re: PLUGIN: Virtual Sensor
Post by: jeubanks on March 01, 2018, 12:12:45 pm
I'm wondering if this virtual sensor is what I'm looking for.  I want a virtual motion sensor that I can trigger through a http call.  How would I configure the sensor parameters for a simple motion scenario of on/off detection being toggled through a web call?
Title: Re: PLUGIN: Virtual Sensor
Post by: rigpapa on March 01, 2018, 02:58:37 pm
OK, so to be clear, you want to make an HTTP request TO VERA from somewhere outside (or heck, even from the Vera itself), and have it set, reset, or toggle the Tripped state of a VirtualSensor?
Title: Re: PLUGIN: Virtual Sensor
Post by: jeubanks on March 01, 2018, 06:09:29 pm
OK, so to be clear, you want to make an HTTP request TO VERA from somewhere outside (or heck, even from the Vera itself), and have it set, reset, or toggle the Tripped state of a VirtualSensor?

Yup....

Doing that already with Virtual Switches to integrate with Life360 :) 

I want to integrate with my camera system to use Virtual Sensor for motion events.
Title: Re: PLUGIN: Virtual Sensor
Post by: rigpapa on March 01, 2018, 06:53:14 pm
OK. It doesn't do this at the moment, but it's good timing. It's easy to do, and I can get it into Vera's plugin approval cycle for Monday. And you can hand-install the modified files if you wish. I can have those for you tomorrow.
Title: Re: PLUGIN: Virtual Sensor
Post by: jeubanks on March 01, 2018, 07:39:09 pm
Ok cool.  No rush on it.  Just toying with my system and trying to integrate left over pieces.
Title: Re: PLUGIN: Virtual Sensor
Post by: rigpapa on March 07, 2018, 10:34:55 am
Ok cool.  No rush on it.  Just toying with my system and trying to integrate left over pieces.

It's in. Version 1.2 in the Vera plugin marketplace. There is control panel UI to trip and reset the sensor manually. Scenes, PLEG, and Lua can also use the Trip and Reset actions (service urn: toggledbits-com:serviceId:VirtualSensor1).
Title: Re: PLUGIN: Virtual Sensor
Post by: jeubanks on March 08, 2018, 08:52:04 pm
Ok cool.  No rush on it.  Just toying with my system and trying to integrate left over pieces.

It's in. Version 1.2 in the Vera plugin marketplace. There is control panel UI to trip and reset the sensor manually. Scenes, PLEG, and Lua can also use the Trip and Reset actions (service urn: toggledbits-com:serviceId:VirtualSensor1).

Very cool.  I'll take a look at it soon.  Busy with doing some home stuff.
Title: Re: PLUGIN: Virtual Sensor
Post by: Drex on March 11, 2018, 10:30:51 pm
Ok cool.  No rush on it.  Just toying with my system and trying to integrate left over pieces.

It's in. Version 1.2 in the Vera plugin marketplace. There is control panel UI to trip and reset the sensor manually. Scenes, PLEG, and Lua can also use the Trip and Reset actions (service urn: toggledbits-com:serviceId:VirtualSensor1).

I'm looking for a virtual alarm contact to parallel alarm settings called by HTTP requests that functions like a native alarm contact in Vera.

I loaded the plug in and understand how to trip on and off with a url.  My only question: how do you shut it off from autogenerating values of the switch per the sine algorithm (ie disable all the sinusodal features?)?

Thanks!
Title: Re: PLUGIN: Virtual Sensor
Post by: jeubanks on March 12, 2018, 12:47:03 am
Hoping to get to this still.  I think I want to use this with my Life360 integration.
Title: Re: PLUGIN: Virtual Sensor
Post by: rigpapa on March 12, 2018, 07:43:18 am
Sorry, I missed your follow-up. Disabling the function is just a matter of setting the plugin to disabled on its UI. That stops the function generator. Everything else continues to work.
Title: Re: PLUGIN: Virtual Sensor
Post by: rafale77 on April 12, 2018, 04:53:13 am
Would you release 1.2 to the AltAppstore? I guess I can always get it from GitHub... but would be nice to have it updated.
Title: Re: PLUGIN: Virtual Sensor
Post by: rigpapa on April 12, 2018, 10:33:21 am
Done!
Title: Re: PLUGIN: Virtual Sensor
Post by: cozmokramer on May 07, 2018, 05:24:12 pm
Came across this plugin in my search for Vera virtual sensors.

Installed it from app store, went ok.

It shows up in the device list - all well.
But I need like 5 virtual sensors of this type. How do I instatiate more like the one created by install?
Title: Re: PLUGIN: Virtual Sensor
Post by: Don Phillips on May 07, 2018, 09:29:41 pm
Here is a screen shot:
Title: Re: PLUGIN: Virtual Sensor
Post by: cozmokramer on May 08, 2018, 04:07:23 am
Excellent. I figured it out another way too, just a little new to this Vera thiny :)
Title: Re: PLUGIN: Virtual Sensor
Post by: rigpapa on May 08, 2018, 05:53:40 am
Spot on. Go to your installed plugins list, click on VittualSensor, and you'll find that "Create Another" button.
Title: Re: PLUGIN: Virtual Sensor
Post by: cranb on March 19, 2019, 05:40:10 am
Hello,

Woke up this morning with three virtual devices that showed the "can't connect to device" error. When i checked the Virtual sensor plugin, it now shows that the plugin needs to be "enabled" for the virtual sensors to work. I am almost sure that this was not necessary before as this also enables the simulator which i don't use at the moment.

Is the above a result of the new version (1.5) ?? Or am i missing something?
Title: Re: PLUGIN: Virtual Sensor
Post by: rigpapa on March 19, 2019, 09:29:12 am
The copy-to-child-virtual-sensor functionality was hastily added, you may recall. So I'm now working at cleaning that up, and ultimately making that the central interface of the plugin, with the function generator secondary (but I'm not there yet). One of the other requests was that there be a way to stop the copy action, so the enabled/disabled state now does that. For the moment, if you don't want to use the function generator, just set a large period and interval; this will minimize the CPU effort there, which is already miniscule, anyway.
Title: Re: PLUGIN: Virtual Sensor
Post by: cranb on March 19, 2019, 11:55:32 am
Makes perfect sense! Was just wondering, my Vera has been so unstable lately that the three "not connected" devices almost gave me a heart attack  ;) 8)

Thanks again for the great work on your plugins!
Title: Re: PLUGIN: Virtual Sensor
Post by: rigpapa on March 19, 2019, 01:31:23 pm
Makes perfect sense! Was just wondering, my Vera has been so unstable lately that the three "not connected" devices almost gave me a heart attack  ;) 8)

I am so sorry! I know exactly how that feels. More good stuff coming. I'll warn you first. :)
Title: Re: PLUGIN: Virtual Sensor
Post by: guest32500 on March 20, 2019, 10:34:57 am
Hi RigPapa,

While searching for an answer to my problem, I came across your thread and plug-in :)
I wish I had found you earlier as I have been looking for the functionality of a Virtual Switch but with an extra Arm/Disarm toggle for ages.

I thought that I had found my ideal answer when I came across this thread;-
http://forum.micasaverde.com/index.php/topic,86502.0.html

I have made several Virtual Motion Sensors by uploading a new I_MotionSensor1.xml  to my VERA and following their instructions to create the devices manually.
Everything works very well, with one exception.
For a few of the devices, I want to only trigger them and cannot easily send an untrigger.
I would like some of them to revert to untriggered by themselves - after a set period (30 seconds)

I have tried to install a new service using the instructions in this thread;-
http://forum.micasaverde.com/index.php/topic,102089.0.html
but the variable AutoUntrip is not created.

I don't want to hijack your thread as I've not installed your plug-in (it seems a bit overkill for my needs) but you seem to be very knowledgeable about variables and possibly know what I should do?
.

Title: Re: PLUGIN: Virtual Sensor
Post by: rigpapa on March 20, 2019, 07:43:36 pm
You should just be able to create the AutoUntrip variable yourself in your sensor, and assign it a non-zero number of seconds for the time period. You can do that by going to the Advanced tab for your sensor, then go to the "New Service" sub-tab, and enter the following:

New service: urn:micasaverde-com:serviceId:SecuritySensor1
New variable: AutoUntrip
New value: (enter the number of seconds for the reset time)

The hit the "Add" button, and then the "Reload Engine" button. That should be all you need to do.