Page 1 of 1

Help with time function

Posted: Wednesday 14 February 2018 11:46
by anthropo
Hello, I have a question about time function. In fact I want to command my swimming pool filter. I need to power it during (temperature_of_water/2) hours. For example if temperature is 28°C i need to put motor on 14 hours. It's a lot, and so I want to make sleeps (nb_of_pauses) of 15 minutes to preserve the motor.

I have a String variable 'startHour' and a function timeBeetween()

Code: Select all

function timeBetween(s,e)
        timenow = os.date("*t")
        year = timenow.year
        month = timenow.month
        day = timenow.day
        s = s .. ":00"  -- add seconds in case only hh:mm is supplied
        e = e .. ":00"
        shour = string.sub(s, 1, 2)
        sminutes = string.sub(s, 4, 5)
        sseconds = string.sub(s, 7, 8)
        ehour = string.sub(e, 1, 2)
        eminutes = string.sub(e, 4, 5)
        eseconds = string.sub(e, 7, 8)
        t1 = os.time()
        t2 = os.time{year=year, month=month, day=day, hour=shour, min=sminutes, sec=sseconds}
        t3 = os.time{year=year, month=month, day=day, hour=ehour, min=eminutes, sec=eseconds}
        sdifference = os.difftime (t1, t2)
        edifference = os.difftime (t1, t3)
        isbetween = false
        if sdifference >= 0 and edifference <= 0 then
                isbetween = true
        end
--~     print(" s:" .. s  .. "  e:" .. e .. "  sdifference:" .. sdifference.. "  edifference:" .. edifference)
        return isbetween
end
How can i add (temperature_of_water/2*nb_of_pauses + nb_of_pauses*15) to os.time and use the timeBetween() function ?

Thank you for your help