Page 1 of 1

Domoticz seems to stall

Posted: Tuesday 18 March 2025 22:39
by HvdW
Hi,
Domoticz 2024.7 on RPI3+ Bookworm.
My Domoticz seems to stall.
sudo domoticz restart does the tric.
Just 20 dzVents scripts running, no errors in the log.
Started somewhere a week ago.
Maybe it is a script that asks too much or too many script starting the same moment (every minute)
I don't know.

Can you tell me where to start searching, except for switching off all scripts and gradually day by day starting the scripts one by one.
Can I measure the time it takes to execute a script?

Re: Domoticz seems to stall

Posted: Tuesday 18 March 2025 22:49
by waltervl
Check for a script that does something outside Domoticz eg open an URL or run an external command.
Make sure you use the asynchronous methods of dzvents and for example do not use os.execute.
Read the dzvents wiki about asynchrous actions.

By default Dzvents gives an error when a script execution takes longer than 10 seconds.
Also in the log you should see the start and stop time so you can calculate the execution time.
There is also the dzvents debug log option that I believe also shows total execution time of a script.

Re: Domoticz seems to stall

Posted: Tuesday 18 March 2025 23:02
by HvdW
Thanks Walter.
waltervl wrote: Tuesday 18 March 2025 22:49 Check for a script that does something outside Domoticz eg open an URL or run an external command.
Make sure you use the asynchronous methods of dzvents and for example do not use os.execute.
Read the dzvents wiki about asynchrous actions.

By default Dzvents gives an error when a script execution takes longer than 10 seconds.
I was aware.
waltervl wrote: Tuesday 18 March 2025 22:49 Make sure you use the asynchronous methods of dzvents and for example do not use os.execute.
I'll check.
waltervl wrote: Tuesday 18 March 2025 22:49 Also in the log you should see the start and stop time so you can calculate the execution time.
There is also the dzvents debug log option that I believe also shows total execution time of a script.
I'll set them all on LOG_DEBUG (in bundles of 3 or 4)

Re: Domoticz seems to stall

Posted: Thursday 20 March 2025 23:02
by HvdW

Code: Select all

2025-03-20 20:00:10.417 Error: EventSystem: Warning!, lua script /home/pi/domoticz/dzVents/runtime/dzVents.lua has been running for more than 10 seconds
Created a script to calculate execution times.
Voltage: 0.016731 seconden
EV Consumption: 0.003408 seconden
Vliegen: 0.002155 seconden
Stroomkosten: 0.007438 seconden
Presence detection: 0.004311 seconden
Regen: 0.004395 seconden
Earthquake: 0.002352 seconden
EVSE switch: 0.001276 seconden
Energy today: 0.000000 seconden
Energy tomorrow: 0.000000 seconden
Car charging: 0.002019 seconden
Car facts: 0.020661 seconden
Alles text: 0.000213 seconden

These data are logged and also written in a text sensor.
The script:

Code: Select all

return {
    on = {
        timer = {'every 5 minutes'}, -- Voer het script elke 5 minuten uit
    },
    logging = {
        level = domoticz.LOG_DEBUG, -- Gebruik LOG_DEBUG voor gedetailleerde logging
        marker = 'Execution times',
    },
    execute = function(domoticz, triggeredItem)
        -- Log het starten van het script
        domoticz.log('Execution times script gestart', domoticz.LOG_DEBUG)

        -- Definieer de tekstsensor waar de resultaten worden weergegeven
        local textSensor = domoticz.devices('YourTextSensor')
        if not textSensor then
            domoticz.log('Fout: Tekstsensor "YourTextSensor" niet gevonden!', domoticz.LOG_ERROR)
            return -- Stop het script als de tekstsensor niet bestaat
        else
            domoticz.log('Tekstsensor gevonden: ' .. textSensor.name, domoticz.LOG_DEBUG)
        end

        -- Tabel met scriptnamen en bijbehorende globale variabelen
        local scripts = {
            { name = 'Voltage', average = domoticz.globalData.scriptExecutionTime_voltage.avg() },
            { name = 'EV Consumption', average = domoticz.globalData.scriptExecutionTime_EVConsumption.avg() },
            { name = 'Vliegen', average = domoticz.globalData.scriptExecutionTime_vliegen.avg() },
            { name = 'Stroomkosten', average = domoticz.globalData.scriptExecutionTime_stroomkosten.avg() },
            { name = 'Presence detection', average = domoticz.globalData.scriptExecutionTime_presence_detection.avg() },
            { name = 'Regen', average = domoticz.globalData.scriptExecutionTime_regen.avg() },
            { name = 'Earthquake', average = domoticz.globalData.scriptExecutionTime_earthquake.avg() },
            { name = 'EVSE switch', average = domoticz.globalData.scriptExecutionTime_EVSE_switch.avg() },
            { name = 'Energy today', average = domoticz.globalData.scriptExecutionTime_energy_today.avg() },
            { name = 'Energy tomorrow', average = domoticz.globalData.scriptExecutionTime_energy_tomorrow.avg() },
            { name = 'Car charging', average = domoticz.globalData.scriptExecutionTime_car_charge.avg() },
            { name = 'Car facts', average = domoticz.globalData.scriptExecutionTime_car_facts.avg() },
            { name = 'Alles text', average = domoticz.globalData.scriptExecutionTime_alles_text.avg() },

            -- Voeg hier meer scripts toe, bijvoorbeeld:
            -- { name = 'Script 3', average = domoticz.globalData.scriptExecutionTime_3.avg() },
            -- { name = 'Script 4', average = domoticz.globalData.scriptExecutionTime_4.avg() },
            -- ...
            -- { name = 'Script 20', average = domoticz.globalData.scriptExecutionTime_20.avg() },
        }

        -- Log de scripts die worden verwerkt
        domoticz.log('Aantal scripts in de tabel: ' .. #scripts, domoticz.LOG_DEBUG)
        for i, script in ipairs(scripts) do
            domoticz.log(string.format('Script %d: %s, Gemiddelde: %.6f seconden', i, script.name, script.average), domoticz.LOG_DEBUG)
        end

        -- Bouw de tekst op die naar de tekstsensor wordt gestuurd
        local resultText = 'Gemiddelde uitvoeringstijden:\n'
        for i, script in ipairs(scripts) do
            resultText = resultText .. string.format('%s: %.6f seconden\n', script.name, script.average)
        end

        -- Log de opgebouwde tekst
        domoticz.log('Opgebouwde tekst voor tekstsensor:\n' .. resultText, domoticz.LOG_DEBUG)

        -- Update de tekstsensor
        textSensor.updateText(resultText)
        domoticz.log('Tekstsensor bijgewerkt', domoticz.LOG_DEBUG)

        -- Log het succesvol afronden van het script
        domoticz.log('Execution times script succesvol afgerond', domoticz.LOG_DEBUG)
    end
}
In global_data

Code: Select all

scriptExecutionTime_voltage = { history = true, maxItems = 64 } , 
        scriptExecutionTime_EVConsumption = { history = true, maxItems = 64 },
        scriptExecutionTime_vliegen = { history = true, maxItems = 64 },
        scriptExecutionTime_stroomkosten = { history = true, maxItems = 64 },
        scriptExecutionTime_presence_detection = { history = true, maxItems = 64 },
        scriptExecutionTime_regen = { history = true, maxItems = 64 },
        scriptExecutionTime_weerlive = { history = true, maxItems = 64 },
        scriptExecutionTime_earthquake = { history = true, maxItems = 64 },
        scriptExecutionTime_EVSE_switch = { history = true, maxItems = 64 },
        scriptExecutionTime_energy_today = { history = true, maxItems = 64 },
        scriptExecutionTime_energy_tomorrow = { history = true, maxItems = 64 },
        scriptExecutionTime_car_charge = { history = true, maxItems = 64 },
        scriptExecutionTime_car_facts = { history = true, maxItems = 64 },
        scriptExecutionTime_alles_text = { history = true, maxItems = 64 },
In the script to be checked.

Code: Select all

    execute = function(domoticz, triggeredItem)
        -- Start de timer to check execution time
        local startTime = os.clock()

------ Your code here

        -- Stop de timer and calculate execution time
        local executionTime = os.clock() - startTime
        -- Add execution tim to the global  scriptExecutionTime_your_script_name
        domoticz.globalData.scriptExecutionTime_your_script_name.add(executionTime)
        -- Log execution time
        domoticz.log('Execution time of the my_script_name script: ' .. executionTime .. ' seconden', domoticz.LOG_DEBUG)
    end
}
Possible solutions to avoid the lagging:
- pay attention to Asynchronous HTTP Request and handling and Asynchronous shell command execution (minor problem)
- swap SD card which maybe at the end of it's lifespan. (major problem)

Re: Domoticz seems to stall

Posted: Friday 21 March 2025 0:28
by waltervl
If you keep scripting to monitor scripting in the end you will run into scripting issues.... :D

But did you find a reason why you had the initial issues?