Give me a lei! Its a Lua!

Sadly, no luau…. no roasted pig… no pineapples. Lua is scripting language supported by Vera. Generally speaking, it’s how you do stuff they didn’t already build in.

I mentioned that I have my pool pump turning on or off by a schedule and I have managed to get it to turn on when the temperature sensor goes below 36 degrees. That temperature may be set lower at some point, but for now, I want a margin of safety.

What is not ideal is that the schedule can turn off the pump even if the temperature is below freezing. The next time the temperature is polled, that trigger will turn it back on but that is a bit inelegant and potentially dangers. What if something suddenly stops the temperature sensor from polling for long enough for the exposed filter hoses to begin to freeze?

There are several examples of Conditional Scene Execution and I have lifted the Lua code below and attached it to the scene that turns the pump off.

local dID   = e3    — Device ID of temperature sensor
local tHigh = 37    — Highest temperature of range
local allow = true  — true runs scene when in range
local tCurrent = tonumber((luup.variable_get(“urn:schemas-micasaverde-com:device:TemperatureSensor:1”, “CurrentTemperature”,dID)))
return ((tCurrent >= tHigh) == allow)

I lifted this snippet pretty much directly from the forum then edited to be appropriate in my environment. I don’t really have range of temperatures where I want to allow the pump to turn off. It’s pretty much the one temperature. Below that, don’t turn the pump off.

I looked at the “Settings” tab of the temperature sensor to get the device ID and the “Advanced” tab to get the urn: details. I chose 37 degrees as the set point because the trigger to turn the pump on is 35 degrees. Hopefully, this ensure some hysteresis to prevent the pump from cycling back on if the temperature is hovering at 36.

Once I’m sure this is working, I will add a trigger to turn the pump off above some fairly warm temperature, say 50, to prevent it from running all day just because it happened to be chilly at 6AM when the schedule went by.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.