Maintaining state with harmony and all lights off

Hi Patrick, and others.

Firstly I must say I am loving Reactor and what we are able to do. Really changing how we look at our Vera and what we can do with it. Thank you.

I have a couple of things that I would love advice on the best way to achieve what I need.

Home Theatre.

  • I have a Switchboard switch setup called “MovieTime” that when I trigger, I start a Harmony activity and turn on a few lights, ready to watch a movie.
  • this works great, and when the switch turns off, I can then shut down everything. Very nice.
  • What I am struggling with is maintaining state of the Switch if I turn everything off via the Harmony remote, which leaves my Switch still ON.
  • What I have done so far is setup another condition if the State of the Harmony is off, I then switch the Switch to Off when that condition is true.
  • What I would like to do is have the Switch also switch ON, if the system is started via the Harmony remote, but if I do that by having a condition on the harmony state, I get a bit of a circular situation, where the harmony is turned on, and then the switch is turned on, which in turn starts the harmony. Not ideal.
  • I would appreciate any suggestions on how best to achieve this maintaining state, so I can turn on the harmony via Vera (with a switch) or via the remote, and both know the state.

All Lights Off

  • Any ideas how best to achieve an all lights off button? I can setup a SwitchBoard switch, and then have a reactor condition that sees that and then when true turns off lights, but I have too many lights to input them all manually. I have done that for now, but its a bit manual.
  • Is there a code string that i can use to do that? I can’t find it referenced anywhere.

Thanks again for reactor!! its awesome.

A couple of things:

  1. First, it won’t be circular for long. If the Harmony remote state changes and that ends up turning the switch on, and then the switch on condition sets up the home theater, including changing the Harmony remote state, that’s where it will end. Once the switch is on, turning it on again does not cause the switch on condition to refire–Reactor acts on state changes, and since the switch is then already on, it doesn’t change state (can’t make it more on than it already is) so no activity will run. So if you can solve your problem and tolerate that one potential repetition, proceed with the simple solution of just turning the virtual switch on from the Harmony routine.
  2. You could also gate the “switch on” condition together (AND) with a “Harmony off” condition, so the activity to set everything up only runs when the switch is turned on and the Harmony hasn’t started. This would depend on the Harmony plugin having very up-to-date information about the state of the remote; I don’t use it, so I don’t know its behaviors, but if it polls at some interval rather than maintaining current, active state, this isn’t likely to fly. Even with active state, race conditions are possible, as the timeliness and order with which things run is undefined and non-deterministic (i.e. between Vera and the various devices, there’s no guarantee as to when and what order). In many cases you can make an assumption, and that will work most of the time, but that is all the guarantee you get.

One thing that may help you is running test cases and examining the “Events” section of the Logic Summary (Tools tab). This will show you the timing of and order in which the ReactorSensor is receiving device updates, and the values changing. It’s more reliable than looking at the Status tab because the Vera UI only updates data about every two seconds, so anything that happens in less time than that (e.g. switch off-on-off in one second) may not be seen in the UI at all. The events list records everything as it happens.

I’ve thought about this several times but I don’t yet have a better solution than enumerating the lights in the actions. If you put them all in a scene and just have Reactor run the scene, you at least can re-use that in other places in your Vera world. You could also use a “Run Lua” action in your Reactor activity with code like this:

-- Turn off all lights and dimmers in a room specified below
local room = 3
for k,v in pairs( luup.devices ) do
	-- Match room
	if tonumber( v.room ) == room then
		-- Find cat 2,3: lights and dimmers
		local cat = tonumber( v.category_num )
		if cat == 2 or cat == 3 then
			luup.call_action( "urn:upnp-org:serviceId:SwitchPower1", "SetTarget", { newTargetValue="0" }, k )
		end
	end
end

You can extend this with more conditions, which is likely necessary as there are a bunch of things that might sit in categories 2 and 3 that you don’t want to play with (e.g. other virtual switches, switches that control non-lighting devices, etc.). You could, for example, “label” those switches that should be turned off by adding a state variable in your own personal service (e.g. urn:benc-name:serviceId:SwitchGroup) with some value to those devices, which a loop like the one above can then fetch and test for.

Hi,

With the latest Harmony Hub version there are some more state variables that can help you with this. See the Wiki on this Activity start details · reneboer/vera-Harmony-Hub Wiki · GitHub

Cheers Rene