Automatic Christmas Tree

Our home is running Domoticz and a Z-Wave network. Using these, I added a simple LUA script to turn the Christmas tree on and off automatically, depending on motion in the living room. To be precise, motion would turn it on immediately, and 10 minutes after motion stopped, it would turn off again. This was to avoid the tree turning off while we we just sitting quietly for a bit too long, and worked well in our case. Here is the LUA script:

return { 
    on = {
        devices = {
            'TV beweging'
        }
    },
    execute = function(domoticz, device)
        domoticz.log('TV beweging!', domoticz.LOG_INFO)
        domoticz.log('Device ' .. device.name .. ' was changed to ' .. tostring(device.active), domoticz.LOG_INFO)
        domoticz.log('TV lichtsterkte is ' .. domoticz.devices('TV lichtsterkte').lux, domoticz.LOG_INFO)
        if (domoticz.time.hour > 22 or domoticz.time.hour < 5) then
            if (device.active) then
                -- domoticz.devices('Entree lamp').switchOn() -- Besta links
            else
                -- domoticz.devices('Entree lamp').switchOff().afterMin(2)
            end
        else 
            if (device.active) then
                if (domoticz.devices('TV lichtsterkte').lux < 100) then
                    domoticz.log('Kerstboom meteen aan ', domoticz.LOG_INFO)
                    domoticz.devices('Kerstboom').switchOn()
                end
            else
                domoticz.devices('Kerstboom').switchOff().afterMin(10)
                    domoticz.log('Kerstboom uit over 10 minuten ', domoticz.LOG_INFO)
            end
        end
    end
}

At night, we preferred not to light the Christmas tree, so not to disturb anyone. Instead a different lamp could be lit. But we decided to leave it dark.