Run Time Calculation

I’m trying to calculate the run time for my sprinklers. I haven’t had any issues with PLEG in the past, but can’t figure this out. I have looked all over the forum, including [url=http://forum.micasaverde.com/index.php?topic=38533.0]http://forum.micasaverde.com/index.php?topic=38533.0[/url], but can’t figure out how to determine the run time. Attached is a snippet of my PLEG Status page. Below is the code I am testing in Lua Test:

[code]–~ Logic
–~ Calculate Sprinkler Run Times at 10am
–~ Load run time data into Variable Container
local VAR_ID = 86
local VAR_SID = “urn:upnp-org:serviceId:VContainer1”

local MFBrunTime = {((#!tMFBon - #tMFBon) / 60)}
luup.variable_set(VAR_SID,“Variable1”,MFBrunTime,VAR_ID)[/code]

I am getting an error of “Code error: Line 7: unexpected symbol near ‘!’”

Thanks for any advice.

I use a counter to track my blower hours of my air handler so I know when it is time to change the filter. The attached seems to work well for me.

Thanks Don Phillips.

I have an irrigation system with nine zones. I am trying to track the run time for each of the zones over time. In the PLEG Basics manual put together by RexBeckett, he says “the expression (#!tSwitch-#tSwitch) returns the number of seconds that it was turned on.”. That is where I started with this effort. It seems pretty easy, Off Time - Start Time = Run Time. In my 20 years in IT, what has appeared to be an easy task, often turns into the most difficult task of the day.

The key is that your math will only work in PLEG… The variables are defined in PLEG and are only valid in PLEG.

The code that you are “testing” in the “Lua Test” window must be pure Lua. Lua does not have access to the variables that are defined in a PLEG instance. It does not have the same math operators that are defined in a PLEG instance. In Lua, the “#” operator is “length of string or table” and the “!” operator is “logical NOT”… The combination, “#!” is an impossiblity, and thus the unexpected symbol error.

I am not a Lua expert, and have only done limited coding, but I wondered if that was the problem.

I will try to get it to work in PLEG. Lua Test has been a good check tool for me.

Thanks for the help.

This is how I made this work for me.

[ol][li]Create a new MultiString Device, where each variable would contain the run time for a specific sprinkler zone[/li]
[li]Create a trigger in PLEG for each of my sprinkler zones turning on (e.g., NFBon)[/li]
[li]Create a schedule called sSprklrRunTime to run everyday for 1 minute at 10am[/li]
[li]Create a condition called cSprklrRunTime which would become true when the sSprklrRunTime schedule occurs[/li]
[li]Create an action from the cSprklrRunTime condition where I set a variable using the following - {((#!tNFBon-#tNFBon)/60)}[/li][/ol]

The last step was the most confusing for me. I did it with the following steps:

[ol][li]Go to the Advanced tab within the action in Step 5 above[/li]
[li]In the ‘Pick a Device’ drop down, select the MultiString device you created in Step 1 above, and click the ‘Add’ button[/li]
[li]In the new row created, select the ‘SetVariableX’(X is the variable number) for the variable you want to populate[/li]
[li]Enter the expression from Step 5 above into the box[/li]
[li]Click ‘Finished’, close PLEG, click ‘SAVE’, let you system reload and you should be ready to go[/li][/ol]

The /60 in the equation will give your result in minutes. If you want hours, change it to 3600.

I couldn’t figure out how to limit the calculation to two decimal places, but that’s not important in my situation.

My PLEG Status Report is attached.

I hope this helps someone else down the road.