return {
    -- The script is active
    active = true,

    -- Trigger section: run the script every 1 minute
    on = {
        timer = {
            'every 1 minutes'
        }
    },

    -- Custom logging level for this script
    logging = {
        level = domoticz.LOG_INFO,
        marker = "AWTRIX_APP"
    },

    -- Persistent variables to track rotation for singleApp mode
    data = {
        currentIndex = { initial = 0 } -- Start with the first status
    },

    -- Event execution when the timer triggers the script
    execute = function(domoticz)
        -- Ordered list of device names to enforce consistent iteration
        local orderedDevices = {
            "ChristmasTree",
            "Temperature - Room1",
            "Power",
            "Water - Total usage",
            "Ventilation",
            "Heatpump - Status",
            "Temperature - Outside",
            "Gas"
        }
        
        -- Unified dictionary of devices with icon mappings
        local devicesConfig = {
            ["ChristmasTree"] = { icon = 4889, type = "switch" },
            ["Temperature - Room1"] = { icon = 2355, type = "temperature" },
            ["Power"] = { icon = 95, type = "power" },
            ["Water - Total usage"] = { icon = 18191, type = "water" },
            ["Ventilation"] = { icon = 20121, type = "selector" },
            ["Heatpump - Status"] = { icon = 7627, type = "text" },
            ["Temperature - Outside"] = { icon = 64162, type = "temperature" },
            ["Gas"] = { icon = 54633, type = "gas" }
        }
        
        -- Check if the "AWTRIX3 - Power" device is on
        local powerDevice = domoticz.devices("AWTRIX3 - Power")
        if not powerDevice or powerDevice.state ~= "On" then
            domoticz.log("AWTRIX3 - Power device is off. Skipping status updates.", domoticz.LOG_INFO)
            return
        else
            domoticz.log("AWTRIX3 - Power device is on. Proceeding with status updates.", domoticz.LOG_INFO)
        end

        local statuses = {}

        -- Function to generate JSON description ({"text": "status", "icon": icon})
        local function getDescription(device, config)
            local status = ""
            local icon = config.icon

            -- Check for different device types and retrieve the appropriate value
            if config.type == "temperature" and device.temperature then
                status = string.format("%.1fC", device.temperature)
            elseif config.type == "power" and device.usage then
                status = string.format("%dW", device.usage)
            elseif config.type == "water" and device.counterToday then
                status = string.format("%.1fL", device.counterToday)
            elseif config.type == "text" and device.text then
                status = device.text
            elseif config.type == "switch" then
                status = device.state
            elseif config.type == "selector" then
                status = device.levelName
            elseif config.type == "gas" and device.counterToday then
                status = string.format("%.2f m3", device.counterToday)
            end

            -- Return the formatted JSON description if status is not empty
            if status ~= "" then
                return { text = status, icon = icon }
            end

            return nil
        end

        -- Collect statuses for each relevant device in a fixed order
        for _, deviceName in ipairs(orderedDevices) do
            local config = devicesConfig[deviceName]
            local device = domoticz.devices(deviceName)
            if device then
                local description = getDescription(device, config)
                if description then
                    table.insert(statuses, description)
                    domoticz.log(string.format("Collected status for %s: %s", deviceName, domoticz.utils.toJSON(description)), domoticz.LOG_DEBUG)
                else
                    domoticz.log(string.format("No status collected for %s", deviceName), domoticz.LOG_INFO)
                end
            else
                domoticz.log("Device not found in Domoticz: " .. deviceName, domoticz.LOG_ERROR)
            end
        end

        -- Ensure we have statuses collected
        if #statuses == 0 then
            domoticz.log("No statuses available to send to AWTRIX.", domoticz.LOG_ERROR)
            return
        end

        -- MultiApp: Send all statuses as an array
        local statusesJSON = domoticz.utils.toJSON(statuses)
        domoticz.log("Sending statuses to AWTRIX (multiApp): " .. statusesJSON, domoticz.LOG_INFO)
          
        local appDevice = domoticz.devices('AWTRIX3 - Send Custom App')
        if appDevice then
            appDevice.setDescription(statusesJSON)
            appDevice.switchOn().afterSec(2)
        else
            domoticz.log("AWTRIX3 - Send Custom App device not found", domoticz.LOG_ERROR)
        end
    end
}