Windows Batch, make use of taskschedular in domoticz
Posted: Saturday 01 February 2025 21:46
Sometimes i use os.execute command to do things and when it hangs, domoticz slows down & gives an error running >10 secs.
Thats unwanted and after some thinking i have a simple solution :
Create in the domoticz dir a batchfile named "run_command.bat"
Create in taskschedular a task named "z__run_command"
Call this function anywhere in your script with "uitvoeren(<your os command>)"
The script above writes your command to the batch file and starts the scheduled task without almost any wait. (Powershell is very fast.)
Taskschedular will run the batch file in another process, no influence on domoticz.
Be aware there is no feedback and domoticz does not wait to finisch, it continues normally, thus no dependencies on the result are posible.
With a trick (redirect console to a txt file) it would be possible to get the result (by reading the txt file) but then you have to test it later as domoticz has allready seconds continued.
Thats unwanted and after some thinking i have a simple solution :
Create in the domoticz dir a batchfile named "run_command.bat"
Create in taskschedular a task named "z__run_command"
- this task executes the "run_command.bat"
- this task has no trigger (it will be triggered from the script below)
Code: Select all
function uitvoeren(tedoen)
local f = io.open("run_command.bat", "w") f:write(tedoen) f:close()
os.execute('powershell.exe Start-ScheduledTask -TaskName "z__run_command"')
end
The script above writes your command to the batch file and starts the scheduled task without almost any wait. (Powershell is very fast.)
Taskschedular will run the batch file in another process, no influence on domoticz.
Be aware there is no feedback and domoticz does not wait to finisch, it continues normally, thus no dependencies on the result are posible.
With a trick (redirect console to a txt file) it would be possible to get the result (by reading the txt file) but then you have to test it later as domoticz has allready seconds continued.