Windows Batch, make use of taskschedular in domoticz

All kinds of 'OS' scripts

Moderator: leecollings

Post Reply
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Windows Batch, make use of taskschedular in domoticz

Post by zicht »

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"
  • 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
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.
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
User avatar
waltervl
Posts: 5843
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Windows Batch, make use of taskschedular in domoticz

Post by waltervl »

What about using the dzvents asynchronous domoticz.executeShellCommand('some shell command')
function?

https://wiki.domoticz.com/DzVents:_next ... _execution
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
zicht
Posts: 272
Joined: Sunday 11 May 2014 11:09
Target OS: Windows
Domoticz version: 2023.1+
Location: NL
Contact:

Re: Windows Batch, make use of taskschedular in domoticz

Post by zicht »

waltervl wrote: Saturday 01 February 2025 22:01 What about using the dzvents asynchronous domoticz.executeShellCommand('some shell command')
function?

https://wiki.domoticz.com/DzVents:_next ... _execution
missed that one ! Thanks : that looks a lot better ...
Rpi & Win x64. Using : cam's,RFXCom, LaCrosse, RFY, HuE, google, standard Lua, Tasker, Waze traveltime, NLAlert&grip2+,curtains, vacuum, audioreceiver, smart-heating&cooling + many more (= automate all repetitive simple tasks)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest