Every second Monday I need a trigger to start a scene. How to do this?
The reason behind this is my son come and stay in my house every second week (50%). Every second Monday at a specified time I want to set the thermostat to 21, turn on the light etc.
I understand I need a global variable bool.
First thought: Set up your scene with a schedule for Mondays at the required time. Add the following into the Luup tab.
local dtab = os.date("*t")
return ((dtab.yday % 14) > 6)
This should only allow the scene to run every second week. It does this by taking the remainder of dividing the day of the year (1-366) by 14 (called the modulus). A result greater than 6 indicates the second week of each fortnight. If that is the wrong week, change it to:
local dtab = os.date("*t")
return ((dtab.yday % 14) <= 6)
Second thought: Using the day-of-year would give a creeping error of one day every year and two on leap years. A more stable solution would be to use the number of days since the epoch:
local epochday = math.floor(os.time() / 86400)
return ((epochday % 14) > 6)
or if that’s the wrong week:
local epochday = math.floor(os.time() / 86400)
return ((epochday % 14) <= 6)