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


[SCENE] Simple Scheduler for running scenes


AutoFrank

Recommended Posts

Hi,

I had the requirement for a very simple scheduler. The code below is a stripped down version of  @Sankotronic Main Scene code and just contains the Scene Scheduler. Thanks to @Sankotronic for his permission to post this.

Please login or register to see this code.

The full Main Scene code can be found at 

Please login or register to see this link.

 

I thought this many be useful for some new users starting out or those like me that need a simple yet well written scheduler and may even be a stepping stone for some to the full Main Scene.

-f

 

 

Edited by AutoFrank
Link to comment
Share on other sites

  • 5 months later...

 

I got this error!. why? what wrong

 

[DEBUG] 17:11:16: line 35: unexpected character @ character: 1 0:1 [T] line:

 

[DEBUG] 17:11:16: T

 

 

 

 

-- SIMPLE SCHEDULER. 
-- STRIPPED DOWN VERSION OF 'MAIN SCENE' CODE BY SANKOTRONIC

--[[
%% autostart
%% properties
%% globals
--]]

if (fibaro:countScenes() > 1) then fibaro:abort(); end

local jT           = json.decode(fibaro:getGlobalValue("HomeTable"));       -- comment out if you don't use a hometable
local currenttime   = os.date('*t');
local currentwday   = currenttime['wday'];
local TimeCurrent   = os.date("%H:%M", os.time());

-- SCHEDULED SCENES SETUP -- (seperate multiple entries by comma)
local runSceneSchedName   = {"Turn On", "Turn Off"};               -- Add scene names
local runSceneSchedID     = {50, 51, jT.scene.Wakeup};                         -- add scene ID's or references
local runSceneSchedHour   = {{"18:00"}, {"6:00"}};                            -- Add times to run the scenes
local runSceneSchedWeek   = {{1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1}}; -- specify what day to run the scenes, Sunday is first day in array

function doSceneSched()  
  if #runSceneSchedID > 0 then
    for i = 1, #runSceneSchedID do
      if runSceneSchedWeek[currentwday] == 1 then
        for t = 1, #runSceneSchedHour do                                                        
          if runSceneSchedHour[t] == TimeCurrent then
            fibaro:startScene(runSceneSchedID); end
        end
      end
    end
  end
end

-- MAIN LOOP
while true do
  currenttime   = os.date('*t');
  currentwday   = currenttime['wday'];
  TimeCurrent   = os.date("%H:%M", os.time());
  
  doSceneSched();
  fibaro:sleep(59700);
  
end

Link to comment
Share on other sites

  • Topic Author
  • 2 minutes ago, Infinity said:

     

    I got this error!. why? what wrong

     

    [DEBUG] 17:11:16: line 35: unexpected character @ character: 1 0:1 [T] line:

     

    [DEBUG] 17:11:16: T

     

     

     

     

    -- SIMPLE SCHEDULER. 
    -- STRIPPED DOWN VERSION OF 'MAIN SCENE' CODE BY SANKOTRONIC

    --[[
    %% autostart
    %% properties
    %% globals
    --]]

    if (fibaro:countScenes() > 1) then fibaro:abort(); end

    local jT           = json.decode(fibaro:getGlobalValue("HomeTable"));       -- comment out if you don't use a hometable
    local currenttime   = os.date('*t');
    local currentwday   = currenttime['wday'];
    local TimeCurrent   = os.date("%H:%M", os.time());

    -- SCHEDULED SCENES SETUP -- (seperate multiple entries by comma)
    local runSceneSchedName   = {"Turn On", "Turn Off"};               -- Add scene names
    local runSceneSchedID     = {50, 51, jT.scene.Wakeup};                         -- add scene ID's or references
    local runSceneSchedHour   = {{"18:00"}, {"6:00"}};                            -- Add times to run the scenes
    local runSceneSchedWeek   = {{1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1}}; -- specify what day to run the scenes, Sunday is first day in array

    function doSceneSched()  
      if #runSceneSchedID > 0 then
        for i = 1, #runSceneSchedID do
          if runSceneSchedWeek[currentwday] == 1 then
            for t = 1, #runSceneSchedHour do                                                        
              if runSceneSchedHour[t] == TimeCurrent then
                fibaro:startScene(runSceneSchedID); end
            end
          end
        end
      end
    end

    -- MAIN LOOP
    while true do
      currenttime   = os.date('*t');
      currentwday   = currenttime['wday'];
      TimeCurrent   = os.date("%H:%M", os.time());
      
      doSceneSched();
      fibaro:sleep(59700);
      
    end

     

    @Infinity 

     

    The error is a global / reference that doesn't exist which in this case is probably jT.scene.wakeup

    it's left over from my example

     

    Change this

    Please login or register to see this code.

    ... to include just the two you need which is probably this,...

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • @Infinity

    Please post the full code and what error you are getting

    I can try and take a look later of somebody doesn't jump in sooner

    Link to comment
    Share on other sites

    Please login or register to see this attachment.

    -- SIMPLE SCHEDULER. 
    -- STRIPPED DOWN VERSION OF 'MAIN SCENE' CODE BY SANKOTRONIC

    --[[
    %% autostart
    %% properties
    %% globals
    --]]

    if (fibaro:countScenes() > 1) then fibaro:abort(); end

    local jT           = json.decode(fibaro:getGlobalValue("HomeTable"));       -- comment out if you don't use a hometable
    local currenttime   = os.date('*t');
    local currentwday   = currenttime['wday'];
    local TimeCurrent   = os.date("%H:%M", os.time());

    -- SCHEDULED SCENES SETUP -- (seperate multiple entries by comma)
    local runSceneSchedName   = {"Turn On", "Turn Off"};               -- Add scene names
    local runSceneSchedID     = {50, 51};                         -- add scene ID's or references
    local runSceneSchedHour   = {{"18:00"}, {"6:00"}};                            -- Add times to run the scenes
    local runSceneSchedWeek   = {{1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1}}; -- specify what day to run the scenes, Sunday is first day in array

    function doSceneSched()  
      if #runSceneSchedID > 0 then
        for i = 1, #runSceneSchedID do
          if runSceneSchedWeek[currentwday] == 1 then
            for t = 1, #runSceneSchedHour do                                                        
              if runSceneSchedHour[t] == TimeCurrent then
                fibaro:startScene(runSceneSchedID); end
            end
          end
        end
      end
    end

    -- MAIN LOOP
    while true do
      currenttime   = os.date('*t');
      currentwday   = currenttime['wday'];
      TimeCurrent   = os.date("%H:%M", os.time());
      
      doSceneSched();
      fibaro:sleep(59700);
      
    end

    Link to comment
    Share on other sites

  • Topic Author
  • 7 minutes ago, Infinity said:

    Please login or register to see this attachment.

    -- SIMPLE SCHEDULER. 
    -- STRIPPED DOWN VERSION OF 'MAIN SCENE' CODE BY SANKOTRONIC

    --[[
    %% autostart
    %% properties
    %% globals
    --]]

    if (fibaro:countScenes() > 1) then fibaro:abort(); end

    local jT           = json.decode(fibaro:getGlobalValue("HomeTable"));       -- comment out if you don't use a hometable
    local currenttime   = os.date('*t');
    local currentwday   = currenttime['wday'];
    local TimeCurrent   = os.date("%H:%M", os.time());

    -- SCHEDULED SCENES SETUP -- (seperate multiple entries by comma)
    local runSceneSchedName   = {"Turn On", "Turn Off"};               -- Add scene names
    local runSceneSchedID     = {50, 51};                         -- add scene ID's or references
    local runSceneSchedHour   = {{"18:00"}, {"6:00"}};                            -- Add times to run the scenes
    local runSceneSchedWeek   = {{1, 1, 1, 1, 1, 1, 1}, {1, 1, 1, 1, 1, 1, 1}}; -- specify what day to run the scenes, Sunday is first day in array

    function doSceneSched()  
      if #runSceneSchedID > 0 then
        for i = 1, #runSceneSchedID do
          if runSceneSchedWeek[currentwday] == 1 then
            for t = 1, #runSceneSchedHour do                                                        
              if runSceneSchedHour[t] == TimeCurrent then
                fibaro:startScene(runSceneSchedID); end
            end
          end
        end
      end
    end

    -- MAIN LOOP
    while true do
      currenttime   = os.date('*t');
      currentwday   = currenttime['wday'];
      TimeCurrent   = os.date("%H:%M", os.time());
      
      doSceneSched();
      fibaro:sleep(59700);
      
    end

     

    @Infinity

     

    Comment out this line as you are not using hometable references

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 3 minutes ago, Infinity said:

    yah its working now. thanks a lot Autofrank. and to Sankatronics the main source of this scene..

     

    @Infinity

    glad you got it working... :-)

     

    Link to comment
    Share on other sites

  • Topic Author
  • Just now, Infinity said:

    i have question. what about pop up notification. is it working on 4.054 version. 

     

    you will have to me more specif with your question ...

    Link to comment
    Share on other sites

    like for ex. when the motion is breach then u will receieve  a pop up notification with button run/cancel.

    it seems like this. can I get your code for this scene

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

  • Topic Author
  • Sorry, that's a very different question 

    I'd suggest open a new topic

    I don't have code for this specific action 

    Link to comment
    Share on other sites

    30 minutes ago, AutoFrank said:

    Sorry, that's a very different question 

    I'd suggest open a new topic

    I don't have code for this specific action 

    ok thanks again. see you there in next problem/error.

    Link to comment
    Share on other sites

    is it posible if I include the lux in this scene to turn On the Lights  and when someone  turn Off the one switch lights or in application in 7:00 Pm then these lights will not turn On.

    Link to comment
    Share on other sites

    Join the conversation

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

    Guest
    Reply to this topic...

    ×   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...