I want to change the mode setting on a pair of thermostats at specific times in the day.
I've looked but cannot see any examples of how to make a setting at a specific time. I am using the in-built editor and saving as a time script. Both the following methods for retrieving the current time have failed for me.
Code: Select all
time = os.date("*t")
Code: Select all
time = os.time()
If I use the latter code (as in the full listing below) I see the error
"Error: EventSystem: in BedroomsEnergySave_time: [string "..."]:17: attempt to index global 'timenow' (a number value)"
Full code is as follows.
Code: Select all
print ("Time based event fired")
commandArray = {}
timenow = os.time()
print (timenow.hours)
print (" hours")
print (timenow.minutes)
print (" minutes")
if (timenow.hours>9) then
print ("It is after 0900 GMT")
end
for deviceName,deviceValue in pairs(otherdevices) do
if (timenow.hour == 19 and timenow.minutes == 1) then
if (deviceName=='T stat mode') then
if deviceValue == 'Comfort' then
print("T stat mode is Comfort")
commandArray['T stat mode'] = 'Energy Saving'
print("T stat mode switched to Energy Saving")
end
elseif (deviceName=='L stat mode') then
if deviceValue == 'Comfort' then
print("L stat mode is Comfort")
commandArray['L stat mode'] = 'Energy Saving'
print("L stat mode switched to Energy Saving")
end
end
elseif (timenow.hour == 8 and timenow.minutes == 35) then
if (deviceName=='T stat mode') then
if deviceValue == 'Energy Saving' then
print("T stat mode is Energy Saving")
commandArray['T stat mode'] = 'Comfort'
print("T stat mode switched to Comfort")
end
elseif (deviceName=='L stat mode') then
if deviceValue == 'Energy Saving' then
print("L stat mode is Energy Saving")
commandArray['L stat mode'] = 'Comfort'
print("L stat mode switched to Comfort")
end
end
end
end
return commandArray