Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team

Question
hansdr 0
Hi all,
I have problems with the script below.
Can anyone say what is going wrong?
I have debug message added at the bottom.
Thanks You.
Thanks to MSB for the script
--[[
%% autostart
%% properties
%% globals
ActivityProjector
ActivityTV
LastSeenHans
LastSeenChrista
TV
Projector
Home
Night
--]]
--kill any extra instances of the same scene
if (fibaro:countScenes() > 1) then fibaro:abort() end;
--Loop
while true do
--Settings
local ExecuteTimer = 60; -- Execute Every N-th second
local GlobalVariablesDevice = 174; -- ID of helperdevice for GlobalVars!
local AbsenceTime = 10; -- 10 minutes
local SunriseTime = 30; -- 30 minutes after sunrise
local SunsetTime = 30; -- 30 minutes before sunrise
local UserInactivity = 10; -- 10 minutes delay after switchoff
--Setup local variables
local CurrentDate = os.date("*t");
--Announce start
fibaro:debug(" -|- Start: "..os.date("%Y-%m-%d %H:%M:%S",os.time()))
-- LastSeenHans,Christa
fibaro:call(GlobalVariablesDevice, "pressButton", "11"); -- Check if Hans is at Home
fibaro:call(GlobalVariablesDevice, "pressButton", "12"); -- Check if Christa is at Home
local LastSeenHenrik = fibaro:getGlobalValue("LastSeenHans");
local LastSeenJennie = fibaro:getGlobalValue("LastSeenChrista");
fibaro:debug(" -|- LastSeenHans: "..os.date("%Y-%m-%d %H:%M:%S",LastSeenHans));
fibaro:debug(" -|- LastSeenChrista: "..os.date("%Y-%m-%d %H:%M:%S",LastSeenChrista));
-- Home, anyone ?
AbsenceTime = os.time() - (AbsenceTime * 60);
fibaro:debug(" -|- AbsenceTime: "..os.date("%Y-%m-%d %H:%M:%S",AbsenceTime));
if tonumber(LastSeenHans) < AbsenceTime and tonumber(LastSeenChrista) < AbsenceTime then
fibaro:debug(" -|- Home: Noone is Home!");
if tonumber(fibaro:getGlobalValue("Home")) == 1 then fibaro:setGlobal("Home", 0);
end
else
fibaro:debug(" -|- Home: Someone is at home!");
if tonumber(fibaro:getGlobalValue("Home")) == 0 then
fibaro:setGlobal("Home", 1);
end
end
-- SunriseTime
SunriseHour = os.time{year=CurrentDate.year, month=CurrentDate.month, day=CurrentDate.day, hour=string.sub(fibaro:getValue(1, 'sunriseHour'), 1 , 2), min=string.sub(fibaro:getValue(1, 'sunriseHour'), 4)}+SunriseTime*60;
fibaro:debug(" -|- SunriseTime: "..os.date("%Y-%m-%d %H:%M:%S",SunriseHour));
-- SunsetTime
SunsetHour = os.time{year=CurrentDate.year, month=CurrentDate.month, day=CurrentDate.day, hour=string.sub(fibaro:getValue(1, 'sunsetHour'), 1 , 2), min=string.sub(fibaro:getValue(1, 'sunsetHour'), 4)}-SunsetTime*60;
fibaro:debug(" -|- SunsetTime: "..os.date("%Y-%m-%d %H:%M:%S",SunsetHour));
-- Night or day?
if (os.time() > SunsetHour or os.time() < SunriseHour) then
fibaro:debug(" -|- Night: It's night!");
if tonumber(fibaro:getGlobalValue("Night")) == 0 then
fibaro:setGlobal("Night", 1);
end
else
fibaro:debug(" -|- Night: It's day!");
if tonumber(fibaro:getGlobalValue("Night")) == 1 then
fibaro:setGlobal("Night", 0);
end
end
-- TV running?
if tonumber(fibaro:getValue(19, "valueSensor")) > 10 then
fibaro:debug("-|- TV: TV is ON");
fibaro:setGlobal("ActivityTV", os.time());
if tonumber(fibaro:getGlobalValue("TV")) == 0 then
fibaro:setGlobal("TV", 1);
end
elseif (os.time()-(60*UserInactivity)) > tonumber(fibaro:getGlobalValue("ActivityTV")) then
fibaro:debug("-|- TV: TV is OFF");
if tonumber(fibaro:getGlobalValue("TV")) == 1 then
fibaro:setGlobal("TV", 0);
end
else
fibaro:debug("-|- TV: TV is Undetermined");
end
-- Projector running?
if tonumber(fibaro:getValue(19, "valueSensor")) > 10 then
fibaro:debug("-|- Projector: Projector is ON");
fibaro:setGlobal("ActivityProjector", os.time());
if tonumber(fibaro:getGlobalValue("Projector")) == 0 then
fibaro:setGlobal("Projector", 1);
end
elseif (os.time()-(60*UserInactivity)) > tonumber(fibaro:getGlobalValue("ActivityProjector")) then
fibaro:debug("-|- Projector: Projector is OFF");
if tonumber(fibaro:getGlobalValue("Projector")) == 1 then
fibaro:setGlobal("Projector", 0);
end
else
fibaro:debug("-|- Projector: Projector is Undetermined");
end
--Announce end
fibaro:debug(" -|- End: "..os.date("%Y-%m-%d %H:%M:%S",os.time()))
--Sleep XX seconds
fibaro:sleep(ExecuteTimer*1000);
end
[DEBUG] 18:20:41: -|- Start: 2015-03-21 18:20:41
[DEBUG] 18:20:41: -|- LastSeenHans: 2015-03-21 18:20:41
[DEBUG] 18:20:41: -|- LastSeenChrista: 2015-03-21 18:20:41
[DEBUG] 18:20:41: -|- AbsenceTime: 2015-03-21 18:10:41
[ERROR] 18:20:41: line 46: attempt to compare nil with number
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.