Vera <=> Vera Heartbeat

I have two Vera 3 unit running; Vera_1 is the ZWave devices; and Vera_2 is the DSC Alarm Panel and Blue Iris interface. I have created a Heart beat system for each Vera to notify the other if it is running properly. Each Vera is plugged into a GE/Jasco outlet controlled by the “other” Vera. If Vera_1 does not Heartbeat Vera_2 every 90 seconds, Vera_2 will power cycle Vera_1 and vice. Because the Heartbeat process is contained in “LuaUPnP” if it fails to start the HB will not occur and the “other” Vera can power cycle the failing Vera.

The process is simple, every 90 seconds Vera_1 sends an HTTP command to set a MultiSwitch on Vera_2 which serves to trigger Vera_2 to restart a 5 minute PLEG selfRetrigger timer. If this timer expires it causes the power for Vera_1 to be switched off and then back on 30 seconds later. Vera_1 will then restart and hopefully return to normal operation. The same process works vice for Vera_2 and Vera_1

Trigger:

Vera2SemaphoreON	Vera 2 State 2 Switch 1 is turned on	false	2015-05-28 10:08:52.494	2015-05-28 10:08:52.889

Schedule Items:

Vera1SetSemaphoreTimer	Interval	01:30		None	Interval	00:00:05		None	true	2015-05-28 10:09:57.100	2015-05-28 10:08:32.100
Vera2OFF_ONTimer	Self Trigger			None	Interval	00:00:10		None	false	2015-03-28 02:50:53.035	2015-03-28 02:51:08.005
Vera2PowerCycleTimer	Self ReTrigger			None	Interval	00:05:00		None	false	2015-04-01 10:57:42.479	2015-04-01 11:07:42.100

Conditions:

SetVera2Semaphore	No	Vera1SetSemaphoreTimer	true	2015-05-28 10:09:57.181	2015-05-28 10:08:32.162
Vera2OK	                        No	Vera2SemaphoreON	        false	2015-05-28 10:08:52.602	2015-05-28 10:08:52.969
Vera2TimeOut	                No	(Vera2PowerCycleTimer; !Vera2PowerCycleTimer) AND checkFirst	false	0	0
Vera2PowerCycle	        No	Vera2TimeOut AND Vera2Bypass == 0	false	0	0
Vera2PowerRestore	        No	(Vera2OFF_ONTimer; !Vera2OFF_ONTimer)	true	2015-04-03 09:27:03.769	2015-04-03 09:24:25.427

Actions for Condition: SetVera2Semaphore

LUA:
luup.inet.wget("http://192.168.15.116:3480/data_request?id=lu_action&DeviceNum=1633&serviceId=urn:dcineco-com:serviceId:MSwitch1&action=SetStatus1&newStatus1=1")

Actions for Condition: Vera2OK
(<><><> I believe the problem lies in here but i don’t see why)

LUA:
      local checkFirst = NotFirst
      NotFirst = TRUE
      return (checkFirst ~= nil)
Device Actions:
      Immediate
           Device	                        Action	                     Arguments
           . PLEG Common	        StartTimer	             timerName=Vera2PowerCycleTimer intervalTime=

[b]Actions for Condition: Vera2PowerCycle[/b]

Device Actions:
      Immediate
          Device	                        Action	                      Arguments
          Vera 2 Power Control	SetTarget	newTargetValue=0
          . PLEG Common	         StartTimer	             timerName=Vera2OFF_ONTimer intervalTime=

Actions for Condition: Vera2PowerRestore

Device Actions:
      Immediate
          Device	                         Action	                      Arguments
          Vera 2 Power Control	 SetTarget	newTargetValue=1

Actions for Condition: Vera2TimeOut

Device Actions:
      Immediate
          Device	                         Action	                      Arguments
          Vera 2 State 2	         SetStatus3	              newStatus3=1

In addition, there are two variables created in “.PLEG Common”, NotFirst, set to “1” and checkFirst set to nul.

Right now everything works except the power cycle. I believe the problem lies in the LUA for the “checkfirst”, my guess is its in the wrong place in the process or there is an error in the logic. Rex Beckett suggested this as a way to prevent the timer from tripping the power cycle for Vera_1 as soon as Vera_2 started up. The idea was to force it to receive one update from the other Vera before it would start timing. But it isn’t happening, as it stands now it never power cycles the other Vera.

Any ideas?

Wow, this looks pretty complicated. Why not simply get each Vera to poll the other using the “alive” HTTP request [url=http://wiki.micasaverde.com/index.php/Luup_Requests#alive]http://wiki.micasaverde.com/index.php/Luup_Requests#alive[/url],and cycle the power if no response?

I must be missing something here.

[quote=“akbooer, post:2, topic:187468”]Wow, this looks pretty complicated. Why not simply get each Vera to poll the other using the “alive” HTTP request [url=http://wiki.micasaverde.com/index.php/Luup_Requests#alive]http://wiki.micasaverde.com/index.php/Luup_Requests#alive[/url],and cycle the power if no response?

I must be missing something here.[/quote]

Where shall I start, perhaps with “I didn’t realize the was such a command” :slight_smile:

@clippermiami, are you still trying to get this to work?

Try changing the Condition Vera2TimeOut to:

Vera2TimeOut No !Vera2PowerCycleTimer and (Vera2OK; !Vera2PowerCycleTimer)

In addition, there are two variables created in ".PLEG Common", NotFirst, set to "1" and checkFirst set to nul.

Do you mean that you have defined these variables in PLEG’s Startup Lua section? If so, remove them. The Lua in the Action for Vera2OK will set the variable NotFirst to true when it runs. It relies on it being nil after a restart so that the timer Vera2PowerCycleTimer is not started on the first cycle.

If you still have problems, it would be easier to help if you posted the Status report as a pdf.

[quote=“RexBeckett, post:4, topic:187468”]@clippermiami, are you still trying to get this to work?

Try changing the Condition Vera2TimeOut to:

Vera2TimeOut No !Vera2PowerCycleTimer and (Vera2OK; !Vera2PowerCycleTimer)

In addition, there are two variables created in ".PLEG Common", NotFirst, set to "1" and checkFirst set to nul.

Do you mean that you have defined these variables in PLEG’s Startup Lua section? If so, remove them. The Lua in the Action for Vera2OK will set the variable NotFirst to true when it runs. It relies on it being nil after a restart so that the timer Vera2PowerCycleTimer is not started on the first cycle.

If you still have problems, it would be easier to help if you posted the Status report as a pdf.[/quote]

Rex, thanks for the followup.

First, no the variables are not defined in Startup LUA, they are created as variabled in the PLEG Advanced tab however.

Second, since I’m trying to learn as well as solve a problem I’m trying to grasp this :):
!Vera2PowerCycleTimer and (Vera2OK; !Vera2PowerCycleTimer)
specifically the NOT condition at the beginning… does this mean then that WHEN the timer expires, IF Vera2OK is TRUE AND the timer has expired then the Condition “Vera2Timeout” will be TRUE or am I misreading it?

Thanks

First, no the variables are not defined in Startup LUA, they are created as variabled in the PLEG Advanced tab however.

Are they referenced somewhere else then? I don’t see any Device Properties or Actions that refer to them.

Second, since I'm trying to learn as well as solve a problem I'm trying to grasp this :): !Vera2PowerCycleTimer and (Vera2OK; !Vera2PowerCycleTimer) specifically the NOT condition at the beginning.... does this mean then that WHEN the timer expires, IF Vera2OK is TRUE AND the timer has expired then the Condition "Vera2Timeout" will be TRUE or am I misreading it?

This will become true when the timer Vera2PowerCycleTimer is stopped and it stopped after Vera2OK was last true. The idea is to detect when the timer runs to completion - i.e. the watchdog expires.

[quote=“RexBeckett, post:6, topic:187468”]

First, no the variables are not defined in Startup LUA, they are created as variabled in the PLEG Advanced tab however.

Are they referenced somewhere else then? I don’t see any Device Properties or Actions that refer to them.

Second, since I'm trying to learn as well as solve a problem I'm trying to grasp this :): !Vera2PowerCycleTimer and (Vera2OK; !Vera2PowerCycleTimer) specifically the NOT condition at the beginning.... does this mean then that WHEN the timer expires, IF Vera2OK is TRUE AND the timer has expired then the Condition "Vera2Timeout" will be TRUE or am I misreading it?

This will become true when the timer Vera2PowerCycleTimer is stopped and it stopped after Vera2OK was last true. The idea is to detect when the timer runs to completion - i.e. the watchdog expires.[/quote]

This code is in LUUP for “Vera2OK”

local checkFirst = NotFirst
NotFirst = TRUE
return (checkFirst ~= nil)

Is that not correct?

Now I understand. Thanks

This code is in LUUP for "Vera2OK" Code: [Select] local checkFirst = NotFirst NotFirst = TRUE return (checkFirst ~= nil) Is that not correct?

This code uses Lua variables. It does not refer to any device variables defined on the Advanced tab.

NotFirst is a global variable so will retain its value between executions of the Action. Following a Luup restart, it will be nil and this is used to suppress the StartTimer action the first time the Action is executed. On subsequent executions, NotFirst will be true so the StartTimer action will run.

So the code should be fine. The device variables are not necessary with this code.

[quote=“RexBeckett, post:8, topic:187468”]

This code is in LUUP for “Vera2OK”
Code: [Select]
local checkFirst = NotFirst
NotFirst = TRUE
return (checkFirst ~= nil)
Is that not correct?

This code uses Lua variables. It does not refer to any device variables defined on the Advanced tab.

NotFirst is a global variable so will retain its value between executions of the Action. Following a Luup restart, it will be nil and this is used to suppress the StartTimer action the first time the Action is executed. On subsequent executions, NotFirst will be true so the StartTimer action will run.

So the code should be fine. The device variables are not necessary with this code.[/quote]

didn’t grasp the difference between code variables and device variables, to me a variable is a variable is a variable :slight_smile: