Author Topic: Question RE virtual switch logic  (Read 481 times)

Offline casmo

  • Sr. Newbie
  • *
  • Posts: 38
  • Karma: +0/-4
Question RE virtual switch logic
« on: May 05, 2017, 08:09:18 am »
Hi,

I'm using the echo to control some virtual switches which are triggering scenes that fire off http commands to a broadlink rm pro. This works fine so long as the switches are the only means by which the devices are turned on/off but for example, if my tv is off (and the corresponding virtual switch is off) but the tv is turned on via the standard remote control, my echo command 'turn off tv' will find the switch off and do nothing.

I could just use scenes without the switches but this would mean the echo command would be "turn on tv" (to turn on and off) or "turn on tv off" Can i make a virtual switch toggle so turning it off (if it already is off) turns it on, or is there a better solution i'm not thinking of?

Any suggestions would be most welcome.

Online kfxo

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: Question RE virtual switch logic
« Reply #1 on: May 05, 2017, 08:29:18 am »
Can i make a virtual switch toggle so turning it off (if it already is off) turns it on, or is there a better solution i'm not thinking of?

Any suggestions would be most welcome.

You can do it in Luup code

luup.call_action("urn:micasaverde-com:serviceId:HaDevice1", "ToggleState", {}, YOURVIRTUALDEVICENUMBER)

Also, a suggestion, depending on your TV you may be able to use the ping sensor plugin to determine if the tv is on or off. For example, my samsung tvs only have a network connection when they are on, so if the ping sensor can reach the TV then it is on and if it cant then it is off.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 804
  • Karma: +18/-7
    • Worthington Engineering, Inc.
Re: Question RE virtual switch logic
« Reply #2 on: May 05, 2017, 08:55:38 am »
You can also use PLEG to monitor a device and have it keep the virtual switch synced with the actual device.
Vera 3, UI7 1.7.947, CT101 t-stat, Everspring motion detector, GE/Jasco switch, Leviton outlet, AeonLabs door sensor, Insteon garage control, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual & Multi Switch, Weather, Sys. Mon.

Offline Alex Waverley

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +4/-0
Re: Question RE virtual switch logic
« Reply #3 on: May 07, 2017, 01:56:21 pm »
You could plug the TV into a smart module and use the energy consumption to determine the state of the TV. When consumption drops below a certain point, Vera knows the TV is off, above that point the TV is on. But so you really need to know the status of the TV to make this work?

If you are using discrete on/off commands you could simply program the scenes to make the switches to act like a momentary contact by having them turn themselves off after a 1 second delay. This way they would simply function like a second remote and the status of the TV wouldn't matter since sending an "ON" command to a device that is on does nothing. Likewise for an "OFF" command.

Essentially:

When "TV On" switch is activated it immediately sends an "ON" command to the TV then waits 1 second and sends an "OFF" command to itself. The TV will turn on and the switch will reset for the next use, just like the button on the remote control.

Do the same for the "OFF" scene and Bob's your uncle.
Please hold your applause until I have concluded my remarks.

Offline casmo

  • Sr. Newbie
  • *
  • Posts: 38
  • Karma: +0/-4
Re: Question RE virtual switch logic
« Reply #4 on: May 08, 2017, 07:16:38 am »
Hi,

Thank you all for your suggestions.

Alex, if i understand correctly this means having a switch for on and a switch for off? the issue with this is that the echo commands would be 'turn on tv on' and 'turn on tv off' whereas having just one switch called 'tv' means the commands are 'turn tv on' and 'turn tv off'

Regarding making the switch a toggle, does this code go in the startup lua section?
The issue with this is that it doesn't allow me to keep track of the actual device state. As far as i can see either it needs to be closed system i.e. tv remote is not used or i need a power consumption unit as mentioned above. (its not a smart tv so ping is not an option)
« Last Edit: May 08, 2017, 08:24:02 am by casmo »

Online kfxo

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: Question RE virtual switch logic
« Reply #5 on: May 08, 2017, 08:57:42 am »
Regarding making the switch a toggle, does this code go in the startup lua section?

No. It will go in a scene where the virtual switch is the trigger

Offline Alex Waverley

  • Jr. Member
  • **
  • Posts: 54
  • Karma: +4/-0
Re: Question RE virtual switch logic
« Reply #6 on: May 10, 2017, 06:19:22 pm »
Hi,

Thank you all for your suggestions.

Alex, if i understand correctly this means having a switch for on and a switch for off? the issue with this is that the echo commands would be 'turn on tv on' and 'turn on tv off' whereas having just one switch called 'tv' means the commands are 'turn tv on' and 'turn tv off'

Regarding making the switch a toggle, does this code go in the startup lua section?
The issue with this is that it doesn't allow me to keep track of the actual device state. As far as i can see either it needs to be closed system i.e. tv remote is not used or i need a power consumption unit as mentioned above. (its not a smart tv so ping is not an option)

I see what you mean now. I don't use voice control so I missed it at first. I think the easiest thing by far is to get a smart module (one can be had for about $20) and use that for status. The other option would be to use an IR controlled relay connected to a MimoLite and include the commands to control the relay in the ON/OFF sequences (macros) of the remote. I do the latter for control of lighting in my theater, but  I use URC remotes with RF so no IR commands can "get lost" or out of sync. The smart module may not be as quick to update status, but I don't think that will make a difference in your application since ON/OFF commands from Vera and the remote won't be made in rapid succession. Plus, the smart module actually reads the state of the device as opposed to the relay which would toggle in sync with the device.

If you use a surround sound receiver there is another option. Many receivers have a 12VDC output that can be used to activate motorized screens. If the receiver is always on when the TV is on you can use that output to send status to the MimoLite. Easy and elegant.

« Last Edit: May 10, 2017, 06:26:04 pm by Alex Waverley »
Please hold your applause until I have concluded my remarks.