and_cesbo

Astra. Scheduling inputs

Feb 14th, 2017
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.33 KB | None | 0 0
  1. -- Scheduling inputs for Astra 5.62 and newer
  2. --
  3. -- In the web interface create new stream
  4. -- Remember stream ID. In this example stream ID is a001
  5. -- Save this script to /etc/astra/mod/schedule.lua
  6. -- Write your own time map
  7.  
  8. schedule = {
  9.     ["a001"] = {
  10.         { -- Mon
  11.             { 07, 00, 2 }, -- on 7:00 turn on second input
  12.             { 07, 30, 1 }, -- on 7:30 turn on first input
  13.             { 12, 30, 2 },
  14.             { 13, 00, 1 },
  15.             { 19, 00, 2 },
  16.             { 19, 30, 1 },
  17.         },
  18.         { -- Tue
  19.             { 07, 00, 2 },
  20.             { 07, 30, 1 },
  21.             { 12, 30, 2 },
  22.             { 13, 00, 1 },
  23.             { 19, 00, 2 },
  24.             { 19, 30, 1 },
  25.         },
  26.         { -- Wed
  27.             { 07, 00, 2 },
  28.             { 07, 30, 1 },
  29.             { 12, 30, 2 },
  30.             { 13, 00, 1 },
  31.             { 19, 00, 2 },
  32.             { 19, 30, 1 },
  33.         },
  34.         { -- Thu
  35.             { 07, 00, 2 },
  36.             { 07, 30, 1 },
  37.             { 12, 00, 2 },
  38.             { 13, 00, 1 },
  39.             { 19, 00, 2 },
  40.             { 19, 30, 1 },
  41.         },
  42.         { -- Fri
  43.             { 07, 00, 2 },
  44.             { 07, 30, 1 },
  45.             { 12, 00, 2 },
  46.             { 13, 00, 1 },
  47.             { 19, 00, 2 },
  48.             { 19, 30, 1 },
  49.         },
  50.         { -- Sat
  51.             { 12, 30, 2 },
  52.             { 13, 00, 1 },
  53.         },
  54.         { -- Sun
  55.         },
  56.     },
  57. }
  58.  
  59. -- Keep code below as is
  60.  
  61. function get_current_input(map)
  62.     local i = 1
  63.     local ct = os.date("*t")
  64.     ct.wday = ct.wday - 1
  65.     if ct.wday == 0 then
  66.         ct.wday = 7
  67.     end
  68.     for _,v in ipairs(map[ct.wday]) do
  69.         if ct.hour < v[1] then
  70.             break
  71.         elseif ct.hour == v[1] then
  72.             if ct.min < v[2] then
  73.                 break
  74.             end
  75.         end
  76.         i = v[3]
  77.     end
  78.     return i
  79. end
  80.  
  81. timer({
  82.     interval = 5,
  83.     callback = function(self)
  84.         for k,v in pairs(schedule) do
  85.             local channel_data = channel_list_ID[k]
  86.             if k then
  87.                 local i = get_current_input(v)
  88.                 if i ~= channel_data.current_input_id then
  89.                     channel_kill_input(channel_data, channel_data.current_input_id)
  90.                     channel_init_input(channel_data, i)
  91.                 end
  92.             end
  93.         end
  94.     end
  95. })
Advertisement
Add Comment
Please, Sign In to add comment