Domoticz seems to stall

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!

Moderators: leecollings, remb0

Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post

Please mark your topic as Solved when the problem is solved.
Post Reply
HvdW
Posts: 615
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Domoticz seems to stall

Post 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?
Bugs bug me.
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Domoticz seems to stall

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
HvdW
Posts: 615
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Domoticz seems to stall

Post 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)
Bugs bug me.
HvdW
Posts: 615
Joined: Sunday 01 November 2015 22:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Twente
Contact:

Re: Domoticz seems to stall

Post 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)
Bugs bug me.
User avatar
waltervl
Posts: 5859
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Domoticz seems to stall

Post 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?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest