Page 1 of 1

Execute Python script in dzvents

Posted: Thursday 01 October 2020 20:48
by jberinga
When trying to execute a Python script in dzvents:
Spoiler: show

Code: Select all

return {
    on = {
        devices = { 'Test' },
        },
    
    execute = function(domoticz, item)
    
    if 
        domoticz.devices('Test').state == 'On'
    then
        domoticz.devices('Test').switchOff().afterSec(5)
        domoticz.utils.osExecute("script:///usr/bin/python /volume1/@appstore/domoticz/var/scripts/python/volumeset.py 031")
    end
   
end
}
nothing is happening; it should set the volume to a certain level. There are no errors in the log.

When activating the script (script:///usr/bin/python /volume1/@appstore/domoticz/var/scripts/python/volumeset.py 031) in the On Action of the device, the volume is changed.

What am I doing wrong? :?

Re: Execute Python script in dzvents

Posted: Thursday 01 October 2020 21:28
by waaren
jberinga wrote: Thursday 01 October 2020 20:48 What am I doing wrong? :?
You don't need the script:// part when executing from a script.
Can you try with

Code: Select all

return {
    on = {
        devices = { 'Test' },
        },
    
    logging = 
    {
    	level = domoticz.LOG_DEBUG, -- change to domoticz.LOG_ERROR when all OK
    	marker = 'Python execution',
    },
    
    execute = function(domoticz, item)
    
    if 
        domoticz.devices('Test').state == 'On'
    then
        domoticz.devices('Test').switchOff().afterSec(5)
        domoticz.utils.osExecute("/usr/bin/python /volume1/@appstore/domoticz/var/scripts/python/volumeset.py 031")
        
        -- if standard execution does not work you could try with sudo 
        -- domoticz.utils.osExecute("sudo /usr/bin/python /volume1/@appstore/domoticz/var/scripts/python/volumeset.py 031")
    end
   
end
}

Re: Execute Python script in dzvents  [Solved]

Posted: Friday 02 October 2020 16:42
by jberinga
Thanks waaren!
That did it (domoticz.utils.osExecute("/usr/bin/python /volume1/@appstore/domoticz/var/scripts/python/volumeset.py 031"))