Jump to content

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


  • 0

Script fail "Usefull global variables script with settings section‏"


Question

Posted

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

  • 0
Posted

I guess your globalvalue Home has no value yet and you try to compare that with a number.

  • 0
  • Inquirer
  • Posted

    I have created a Global variable "Home" so?

     

    I think the vd of the iPhone does not work properly?

     

     

    This is the basic code

     

    To check iphones on/off?
    Device button 1:
    tcpSocket = Net.FTcpSocket("10.0.0.52", 62078)
    bytes, errorCode = tcpSocket:write("test")
    if errorCode == 0 then
    fibaro:setGlobal("LastSeenHenrik",os.time())
    fibaro:log("LastSeenHenrik: OK")
    else
    fibaro:log("LastSeenHenrik: Failed")
    end

    Device button 2:
    tcpSocket = Net.FTcpSocket("10.0.0.79", 62078)
    bytes, errorCode = tcpSocket:write("test")
    if errorCode == 0 then
    fibaro:setGlobal("LastSeenJennie",os.time())
    fibaro:log("LastSeenJennie: OK")
    else
    fibaro:log("LastSeenJennie: Failed")
    end

     

    Thanks for your help

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...