Virtual Device - Flag

Greetings,

I’m interested in a ‘Virtual’ Device, call it a virtual binary flag, that I can use to indicate whether I’m home or not. I would create ‘Scenes’ to turn it on or off.

I would like then to create events that would test whether this device was ‘on’ or ‘off’ based on certain times of the day or night. Ultimately I’d like some random function, but first steps first.

I tried to add a device based on the D_BinaryLight1.xml file, but I got an error something to the affect of no implementation.

If someone has the proper D_, S_, I_ files, I would greatly appreciate it. Or if someone smarter than me could point me in the proper direction, I would attempt to build one.

Thanks in advance.

Hi brsipaq,

you may use the ?_AwarenessSensor.xml files from the Ping Sensor.
As I started writing it, I had the same idea you are having now. I wanted to have a generic binary device which could be controlled by whatever trigger I could think of.
If you want, you can rewrite the plugin itself. [url=http://wiki.micasaverde.com/index.php/Ping_Sensor_Plugin]http://wiki.micasaverde.com/index.php/Ping_Sensor_Plugin[/url]
Currently the “ping” is the event which changes the binary state. If you erase that functionality, then you can replace it, by whatever function you want, or trigger it even by UPnP calls.

I tried to take your Awareness sensor. I created a D_ file and loaded it. I have your Ping working, so I thought it would just load and I’d get the ARM/DISARM ui, but I get nothing showing up in the device.

In your Ping Sensor LUA code, there’s a comment about having to reload LUA to make the UI work. What is that all about.

Any ideas on why the UI wouldn’t work?

Thanks,
Brian

Hi brsipaq,

I’ve got news for you. Due to the fact that I need such a virtual device too, I’m going to create one.
I’ll update this thread and wiki when it’s done.
Maybe it’s already done next week. :slight_smile:

It might be easier to use binary switch on/off for this purpose

Guys, it just occurred to me (again) that back in the olden days of X10, it was quite simple and straightforward to create numerous “fictitious devices” for the purpose of having “flags”.

X10 didn’t mind one bit whether the physical device actually existed or not. You could declare a switch, say, using a certain code (A5, for example). It was then completely OK to use IF-THEN constructs such as: “IF (A5)=ON THEN SET (A5, B4) OFF”

No problem. Of course, all this was possible, because X10 was completely ignorant of whether devices ACTUALLY were ‘On’ or ‘Off’ (because unlike Z-Wave, X10 devices did not report status). By comparison, Z-Wave is rigid in what it allows, but pays back dividends in reliability and reporting ability.

Nice that you’re onto a work-around for this “limitation” … something MCV ought to have considered from the outset of Vera.

of course :wink: thank’s for the hint.
I’ll create another AwarenessSensor for this, I guess.

I tried the Binary Switch device. But whenever I clicked the ON or OFF button, I get an ‘Implementation’ Error.

Then I tried a “Motion Sensor” device. And it created the UI under the LUUP devices, and after awhile the UI showed up. I could click the ARM / DISARM buttons, and even enter a Tripped value of 0 or 1. No ‘Implementation’ Error. However, I couldn’t use the LUUP get variable (or even set Variable) code to test or set them…

Until I loaded version 949. Now it works.

So I have ‘Motion Sensor’ called ‘We Are Gone’ flag. I now have a Living room light that has an event that triggers at sunset. My Luup code tests if my We Are Gone flag is ARMED, if so it returns true, which allows the scene to continue and turn the light on.

I then have a late night event that will do the same test and turn it off.

If this flag is DISARMED, it returns false and does nothing.

So it appears to work in my testing.

Now for a ‘Randomize’ function…

Brian

Did you use the D_MotionSensor1.xml file?
I created one and I never get the ARM/DISARM options on the device.
I tried the binary switch and, like you, got the implementation errors.
I’m also at 949.

Yes, that’s the XML file I used. It took awhile for the UI to ultimately show up. I rebooted the router a couple of times. Can’t remember, but it took several of these attempts, maybe 30 minutes or so, but ultimately it showed up.

I did a second one and it also took awhile, but it also showed up. So while not pretty, it is repeatable.

Then I used the following to test the Arm and Tripped variables (my device is 49):
luup.variable_set(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Tripped”,0, 49)
luup.variable_set(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Armed”,0, 49)
This code did not work before version 949.

Once I knew I could set / get readings, I have the following in my ‘Scenes’ (WAG = We Are Gone; Armed = 0 means it is disarmed):

local WAGStatus = luup.variable_get(“urn:micasaverde-com:serviceId:SecuritySensor1”,“Armed”,49)
if (WAGStatus == “0”) then
return false
end
return true

Right you are, after about 18 hours it showed up. Why so long? Dunno.

Thanks for the code snippets…I’ll tinker this weekend.

Works great.
I have a question. What’s the command to embed a delay? Is there a “sleep” command by chance?
I’ve got the ping sensor set up, but I want to base the modem restart on TWO addresses being down, not just one. So I plan to ping one address and if it fails, arm a virtual device, if the second fails, sleep for a few minutes, then check that the other device is armed and THEN do the reboot.

I wrote a simple virtual switch based on binary switch, took about 5 minutes, it “just works”, and you can stuff it with any logic you can think about.

http://edmidor.com/simple-state-device-for-vera/

@325xi: any examples of how to use it?

Well, that was an example of how to make a virtual device; as for how to use it read this thread :slight_smile:

Basically it’s a logical flag that you can control in a convenient way just as a regular switch. You assign the meaning, and use it in scenes: “do this, but if that virtual device is On, do something else”

325xi,

I downloaded your StateDevice files and tried to set up a LUUP device. The UI seems fine, but when I click the on or off buttons, I get a “Command failed: device not ready” error. I’ve had it set up for about an hour so far. I’m running firmware 949.

Any thoughts?

Thanks,
Brian

You uploaded both files, didn’t you?

Yes. D_StateDevice.xml and I_Statedevice.xml.

What version firmware are you on?

Thanks,
Brian

.949.

If you could

  • ssh into vera
  • tail -f /tmp/log/cmh/LuaUPnP.log
  • click Save

and if you notice error messages on this device startup, post it here, I guess we could figure it out

Do I just upload the files using the “Luup files” button under the Luup plugins screen?