Page 1 of 1

Issues with making selector switch execute script (Windows)

Posted: Friday 30 December 2022 17:52
by calania
Hello! I am having some issues making domoticz run a script when I change the level of a selector switch. I have a few parameters that I want to run the script with so I have done as suggested on the forum and written the script with three forward slashes under "Selector actions".

script:///C:\Users\server\Desktop\MyAir2.py 192.168.0.201 --mode Favorite

But domoticz thinks the third forward slash is part of the path and I'm getting this error (without the parameters)

Error: SQLHelper: Error script not found '/C:\Users\server\Desktop\MyAir2.py

When that didn't work I also found a dzvents script that I modified

Code: Select all

return 
{ 
    on = 
    { 
        devices = 
        { 
            331,          -- MI robot Control
        }, 
    }, 

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = 'cleaner',
    },
    
	execute = function(dz, device)
        local lodash = dz.utils._
        
		dz.log('Device ' .. device.name .. ' was updated', dz.LOG_DEBUG)
        dz.log('LevelNames: ' .. lodash.str(device.levelNames), dz.LOG_DEBUG)
        
        if device.levelName == 'Auto' then
            os.execute("C:\\Users\\server\\Desktop\\MyAir2.py 192.168.0.201 --mode Favorite")
        end
        
        dz.log(lodash.str(dz.globalData),dz.LOG_DEBUG)
	end
}
And when I change the switch I see the following in the log but the script doesn't seem to run. This is what's shown in the log

2022-12-30 17:47:40.981 Status: dzVents: Info: cleaner: ------ Start internal script: Script #3: Device: "Air purifer (Custom Sensors)", Index: 331
2022-12-30 17:47:40.982 Status: dzVents: Debug: cleaner: Device Air purifer was updated
2022-12-30 17:47:40.982 Status: dzVents: Debug: cleaner: LevelNames: {"Off", "Auto"}
2022-12-30 17:47:41.091 Status: dzVents: Debug: cleaner: {}
2022-12-30 17:47:41.091 Status: dzVents: Info: cleaner: ------ Finished Script #3

Does anybody know how I could make it work?

Re: Issues with making selector switch execute script (Windows)

Posted: Friday 30 December 2022 19:38
by psubiaco
What about placing the script into DOMOTICZDIR/scrips/python and call it using the path "scripts/python/MyAir2.py" ?
I'm not familiar with windows, but with linux relative path is ok, starting from DOMOTICZ dir.

Re: Issues with making selector switch execute script (Windows)

Posted: Friday 30 December 2022 20:52
by calania
The problem with doing it that way is that it seems ignores my arguments