toggle on/off of virtual switch

Hi All,

this works fro device 59 of a real switch:

luup.call_action(“urn:micasaverde-com:serviceId:HaDevice1”, “ToggleState”, {}, 59)

but not for a virtual switch?

am i missing something?

just want to toggle state of a virtual switch… ??? ::slight_smile:

Most likely that the toggle action is not coded into the virtual switch.

  • Garrett

Thanks Garret,

so is there any virtual switch / device that i can toggle? any virtual “toggleable” soloution would work but cant find one?

you can implement toggle yourself, check the value of the variable first, then do an if/then/else statement to change the value accordingly.

Thnaks capjay but thats way beyond me! :-\

is there a current virtual device you know of I can install that would work already - or perhaps do you have any code i can insert into my curent virtual switch?

I know when i added it I added an xml and json file i think? i gues i edit the .xml?

Thanks for you support.

Please forgive the novice question, but ‘Toggle’ what does that mean in this situation ?

one command that turns off if on or on if off :slight_smile:

Toggle is an action that is provided in many of the standard device files like binary light, dimmable light, locks, etc. When issuing the toggle command, the device will either turn on or off, lock or unlock based on the status of the device. So if the light is in the off position, it will then turn on. If the lock is in the locked position, then the lock will unlock. The only permanent solution is for the developer to implement the toggle state into the virtual switch plugin.

  • Garrett

I’m trying to do the exact same thing with a virtual switch. What I actually want is a virtual indicator light that I can toggle on or off but I’ll settle for seeing the switch state.

It’s not as easy as I expected…

SOLOUTION

found i can achive this by following information in this thread:

•Use one scene controller button to toggle a light

http://forum.micasaverde.com/index.php?topic=10995.0

will be trying later today but expect this to do the job - if not a bit of a messy set up it should work and once set up i wont need to look at it again so hopefuly will be a fine soloution :slight_smile:

hope it works for you too.

I found the same thread. Tried the exact same thing earlier but it didn’t work for me. I’m trying to toggle a virtual switch instead of a light. WOuldn’t work for me.

Hi Jvilla,

“booooo” it didnt work for me either… :-[ (well not on a virtual switch)

so only thing left to try is luup code with and if /then / else statement. i know we can check device status of a virtual switch but can we control one via luup?

i tried the below but did not work:

luup.call_action(“urn:upnp-org:serviceId:Vswitch1”, “SetTarget”, {newTargetValue = “1”}, 59)

any ideias?

Well at least it’s not me… I thought I was missing something. Now I gotta figure out this “Luup” and what it all means. Sucks being a noob. Even if I’m a tech expert in my own field… Hehehe.

J

Hi JVilla,

yes this is all new and chalengeing to me also - however - good news i have a soloution working :slight_smile:

create 2 scenes, one that turns the virtual switch on and one that turns it off - simple enough. now creat yet anouther scenen (this will be the toggle button for the virtual switch. in the toggle button scene add the below luup code:

Name_of_action = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status",ADD_DEVICE_ID) if(Name_of_action=="1")then luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",{SceneNum="ADD_SCENE_NUMBER"},0) else luup.call_action("urn:micasaverde-com:serviceId:HomeAutomationGateway1","RunScene",{SceneNum="ADD_SCENE_NUMBER"},0) end

change your device id, scene number, and add a name for the action - or leave name of action as is as it will still work.

you now can toggle a virtual switch - happy days ;D

now time for a sit down and a brain relax for me…

[quote=“LightsOn, post:14, topic:172221”]Hi JVilla,

yes this is all new and chalengeing to me also - however - good news i have a soloution working :slight_smile:

create 2 scenes, one that turns the virtual switch on and one that turns it off - simple enough. now creat yet anouther scenen (this will be the toggle button for the virtual switch. in the toggle button scene add the below luup code:

Name_of_action = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”,ADD_DEVICE_ID)
if(Name_of_action==“1”)then
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”,“RunScene”,{SceneNum=“ADD_SCENE_NUMBER”},0)
else
luup.call_action(“urn:micasaverde-com:serviceId:HomeAutomationGateway1”,“RunScene”,{SceneNum=“ADD_SCENE_NUMBER”},0)
end

change your device id, scene number, and add a name for the action - or leave name of action as is as it will still work.

you now can toggle a virtual switch - happy days ;D

now time for a sit down and a brain relax for me…[/quote]

Try this:

status = luup.variable_get("urn:upnp-org:serviceId:VSwitch1","Status", DEVICE_ID) if(status=="1")then luup.call_action("urn:upnp-org:serviceId:VSwitch1", "SetTarget", {newTargetValue = "0"}, DEVICE_ID) else luup.call_action("urn:upnp-org:serviceId:VSwitch1", "SetTarget", {newTargetValue = "1"}, DEVICE_ID) end

No need for two additional scenes. Just create the one scene and add the luup code.

  • Garrett

worked like a charm - thank you garrett

Hi

Another noobie struggling with Virtual Switches, I started a thread here outlining what I was trying to setup. I have managed to install a Virtual Switch add-in and I have a Virtual Switch device now present in Vera and I can turn this Virtual Switch on and off when I press the buttons on the device.

[i]"I have some scenes that have schedules in them to turn lights on some time after sunset, one of them is called “Kids Bed Lamp On”

I have another new scene called “Leaving House” this scene turns on the Virtual Switch, turns all the lights off in the house and arms some security sensors.
I have programmed my new ZME_KeyFob to run the Leaving House scene on button 1 which I can use when leaving.

Obviously if the scenes with the lights on schedules have already run (i.e. after sunset), then if I press the button 1 on the fob, all lights will then go out as I am leaving the house.

But if I leave the house before the scenes with the lights on schedules have run (i.e before sunset), the lights would come on whilst I am still out.

My question is: is it somehow possible to override or stop the scenes with schedules in them from turning on the lights, if I have run the Leaving House scene?

I have also created another new scene called “Welcome Home” and programmed button 2 on the key fob, this scene turns off the Virtual Switch and turns on some lights (If its night time) and disarms the security sensors."
[/i]
Initially I’d like to setup - when I leave the house before sunset and run the 'Leaving House" scene, I would like to prevent the scheduled “Kids Bed Lamp On” scene from running, if we are out.

But I am not sure about the Luup code I need or even in which scene to put the code in to?

Many Thanks

EDIT: Think I have this working now see here.

Just to let you know, the virtual switch plugin does have the ToggleState function implemented. To call it set it up in the advanced section of a scene or use the following luup code:

luup.call_action("urn:upnp-org:serviceId:VSwitch1", "ToggleState", {}, DEVICE_ID)

Hi all,

I’m trying to get this going and using the 'toggle function"…but im clueless as to how i would do this.

Here is what i have so far for my scene “Toggle Relay 2”

[code]status = luup.variable_get(“urn:upnp-org:serviceId:VSwitch1”,“Status”, 60)
if(status==“1”)then
luup.call_action(“urn:upnp-org:serviceId:VSwitch1”, “SetTarget”, {newTargetValue = “0”}, 60)
luup.inet.wget(“http://192.168.0.48:85/?3”)
return true

else
luup.call_action(“urn:upnp-org:serviceId:VSwitch1”, “SetTarget”, {newTargetValue = “1”}, 60)
luup.inet.wget(“http://192.168.0.48:85/?4”)
return true
end[/code]

when i save the config, the relay will switch on, but on subsequent presses, will not turn off again.

Also, do i need to change the code examples in this thread which say “DEVICE_ID” to my actual device_id ie: “60” ?

thanks in advance.

@greglions: do you still need help with that setup? because I don’t really get what you wish to achieve, can you maybe describe this?

You are correct, the DEVICE_ID has to be replaced just as you did.