and_cesbo icon

Astra. Scheduling inputs

and_cesbo | PRO | 02/14/17 05:54:46 PM UTC | 0 ⭐ | 661 👁️ | Never ⏰ | []
Lua |

2.33 KB

|

None

|

0 👍

/

0 👎

-- Scheduling inputs for Astra 5.62 and newer
--
-- In the web interface create new stream
-- Remember stream ID. In this example stream ID is a001
-- Save this script to /etc/astra/mod/schedule.lua
-- Write your own time map
 
schedule = {
    ["a001"] = {
        { -- Mon
            { 07, 00, 2 }, -- on 7:00 turn on second input
            { 07, 30, 1 }, -- on 7:30 turn on first input
            { 12, 30, 2 },
            { 13, 00, 1 },
            { 19, 00, 2 },
            { 19, 30, 1 },
        },
        { -- Tue
            { 07, 00, 2 },
            { 07, 30, 1 },
            { 12, 30, 2 },
            { 13, 00, 1 },
            { 19, 00, 2 },
            { 19, 30, 1 },
        },
        { -- Wed
            { 07, 00, 2 },
            { 07, 30, 1 },
            { 12, 30, 2 },
            { 13, 00, 1 },
            { 19, 00, 2 },
            { 19, 30, 1 },
        },
        { -- Thu
            { 07, 00, 2 },
            { 07, 30, 1 },
            { 12, 00, 2 },
            { 13, 00, 1 },
            { 19, 00, 2 },
            { 19, 30, 1 },
        },
        { -- Fri
            { 07, 00, 2 },
            { 07, 30, 1 },
            { 12, 00, 2 },
            { 13, 00, 1 },
            { 19, 00, 2 },
            { 19, 30, 1 },
        },
        { -- Sat
            { 12, 30, 2 },
            { 13, 00, 1 },
        },
        { -- Sun
        },
    },
}
 
-- Keep code below as is
 
function get_current_input(map)
    local i = 1
    local ct = os.date("*t")
    ct.wday = ct.wday - 1
    if ct.wday == 0 then
        ct.wday = 7
    end
    for _,v in ipairs(map[ct.wday]) do
        if ct.hour < v[1] then
            break
        elseif ct.hour == v[1] then
            if ct.min < v[2] then
                break
            end
        end
        i = v[3]
    end
    return i
end
 
timer({
    interval = 5,
    callback = function(self)
        for k,v in pairs(schedule) do
            local channel_data = channel_list_ID[k]
            if k then
                local i = get_current_input(v)
                if i ~= channel_data.current_input_id then
                    channel_kill_input(channel_data, channel_data.current_input_id)
                    channel_init_input(channel_data, i)
                end
            end
        end
    end
})

Comments