Script starts too many times at specific time????

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
jaisomnmick
Posts: 2
Joined: Friday 24 January 2020 16:29
Target OS: Linux
Domoticz version:
Contact:

Script starts too many times at specific time????

Post by jaisomnmick »

Hi,

I've made a new script to control my outdoor lights (previous was in blockly). My first attempt worked (see an example at First code), but I noticed that when the script triggered at 15 minutes after sunset (or at 05:40), the script started more then 1000 times. The lights were going on and the logging of the lights showed ~2,130 entries (7 days of history). My Domotiz crashed a little later. To prevent that much of On commands, I've changed my script to the current script. Now the On and Off commands are only 1 or 2. But Domoticz is still crashing sometimes and I have the feeling that this is because of this script that starts still a lot of times in one minute (or is it coincidence?). Am I doing something wrong or is this a bug?https://19216811.cam/ https://xender.vip/ https://testmyspeed.onl/

Code: Select all

             if domoticz.time.matchesRule(ONEVENING) then
                LOGGING = LOGGING .."\n".."Program On-Evening"
                    OUTDOORHALLWAY.switchOn()
                    OUTDOORSTORAGEROOM.switchOn()

Code: Select all

--[[
SCRIPT DESCRIPTION:
This script turns on and off the outdoor lights based on time, sunset and sunrise.

DEVICES USED:
Idx 39 = Berging buitenlamp
Idx 43 = Gang buitenlamp
]]--

--SET USER INPUT VARIABLES:
local IDOSR = 39
local IDOHW = 43
local SECLLOFF = 60         -- turn off the lights after xx seconds at day time
local ONMORNING = 'at 05:40 on mon,tue,wed,thu,fri'
local OFFMORNING = '15 minutes before sunrise on mon,tue,wed,thu,fri'
local ONEVENING = '15 minutes after sunset'
local OFFEVENING = 'at 23:30'
local LOGGINGON = "Yes"     -- turn logging on or off (values: On = "Yes", Off = "No")

return {
    active = true,
    on = {
        devices = {
            IDOSR,
            IDOHW,
        },
        timer = {
            ONMORNING,
            OFFMORNING,
            ONEVENING,
            OFFEVENING,
            'at sunset',
            'at sunrise',
            '2 minutes after sunrise',
        },
    },
    execute = function(domoticz, triggeredItem, info)

        --SET VARIABLES:
        local OUTDOORHALLWAY = domoticz.devices(IDOHW)
        local OUTDOORSTORAGEROOM = domoticz.devices(IDOSR)
        local LOGGING = "\n++++++++++++++++++++\n".."SCRIPT LIGHTS OUTDOOR:".."\n...................."

        -- EXECUTE SCRIPT
        LOGGING = LOGGING .."\n".."Outdoor light StorageRoom: "..OUTDOORSTORAGEROOM.state..", Outdoor light Hallway: "..OUTDOORHALLWAY.state
        if (domoticz.time.isNightTime) then 
            LOGGING = LOGGING .."\n".."Program Nighttime active"
            if domoticz.time.matchesRule(ONEVENING) then
                LOGGING = LOGGING .."\n".."Program On-Evening"
                if (OUTDOORHALLWAY.state == "Off") or (OUTDOORSTORAGEROOM.state == "Off") then
                    LOGGING = LOGGING .."\n".."Turn on the lights "..ONEVENING
                    OUTDOORHALLWAY.switchOn()
                    OUTDOORSTORAGEROOM.switchOn()
                else
                    LOGGING = LOGGING .."\n".."No action needed, lights "..OUTDOORSTORAGEROOM.state
                end
            elseif domoticz.time.matchesRule(OFFEVENING) then
                LOGGING = LOGGING .."\n".."Program Off-Evening"
                if (OUTDOORHALLWAY.state == "On") or (OUTDOORSTORAGEROOM.state == "On") then
                    LOGGING = LOGGING .."\n".."Turn off the lights "..OFFEVENING
                    OUTDOORHALLWAY.switchOff()
                    OUTDOORSTORAGEROOM.switchOff()
                else
                    LOGGING = LOGGING .."\n".."No action needed, lights "..OUTDOORSTORAGEROOM.state
                end
            elseif domoticz.time.matchesRule(ONMORNING) then
                LOGGING = LOGGING .."\n".."Program On-Morning"
                if (OUTDOORHALLWAY.state == "Off") or (OUTDOORSTORAGEROOM.state == "Off") then
                    LOGGING = LOGGING .."\n".."Turn on the lights "..ONMORNING
                    OUTDOORHALLWAY.switchOn()
                    OUTDOORSTORAGEROOM.switchOn()
                else
                    LOGGING = LOGGING .."\n".."No action needed, lights "..OUTDOORSTORAGEROOM.state
                end
            elseif domoticz.time.matchesRule(OFFMORNING) then
                LOGGING = LOGGING .."\n".."Program Off-Morning"
                if (OUTDOORHALLWAY.state == "On") or (OUTDOORSTORAGEROOM.state == "On") then
                    LOGGING = LOGGING .."\n".."Turn off the lights "..OFFMORNING
                    OUTDOORHALLWAY.switchOff()
                    OUTDOORSTORAGEROOM.switchOff()
                else
                    LOGGING = LOGGING .."\n".."No action needed, lights "..OUTDOORSTORAGEROOM.state
                end
            else
                LOGGING = LOGGING .."\n".."No action needed (night time)"
            end
        elseif (domoticz.time.isDayTime) then
            LOGGING = LOGGING .."\n".."Program Daytime active"
            if (OUTDOORHALLWAY.state == "On") or (OUTDOORSTORAGEROOM.state == "On") then
                LOGGING = LOGGING .."\n".."Lights are on, turn off the lights in "..SECLLOFF .." seconds"
                OUTDOORHALLWAY.switchOff().afterSec(SECLLOFF)
                OUTDOORSTORAGEROOM.switchOff().afterSec(SECLLOFF)
            else
                LOGGING = LOGGING .."\n".."No action needed (day time)"
            end
        else
            LOGGING = LOGGING .."\n".."No action needed (no night/day time)"
        end

        LOGGING = LOGGING .."\n++++++++++++++++++++"
        
        --LOGGING:
        if (LOGGINGON == "Yes") then
            domoticz.log(LOGGING)
        end
end
}
Last edited by jaisomnmick on Sunday 26 January 2020 6:29, edited 1 time in total.
User avatar
boum
Posts: 135
Joined: Friday 18 January 2019 11:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10717
Location: France
Contact:

Re: Script starts too many times at specific time????

Post by boum »

Hello,
You set your script to be triggered by devices too. IDOSR is OUTDOORSTORAGEROOM so when you do OUTDOORSTORAGEROOM.switchOn(), the script will be triggered again. Inside the execute function, it will go through the same path.

You should remove the devices ={...} triggers, and add .silent() to your switchOn(), switchOff() calls to stop any other scripts to be triggered, or at least add checkFirst() if you want other script to be triggered on those devices.
(Maybe both if that's what you want.)

Code: Select all

                    OUTDOORHALLWAY.switchOn().checkFirst().silent()
                    OUTDOORSTORAGEROOM.switchOn().checkFirst().silent()
If you want your script to react to the devices, you should test triggeredItem.isTimer and triggeredItem.isDevice to differentiate the source of the trigger.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest