Page 1 of 1

Execution scripts problem

Posted: Monday 07 October 2019 20:50
by czasas
Hello could you tell me what Im doing wrong? When I rotate cube in right there should be executed specific scripts, the same for left. Scripts is recognising left and right (printing proper value, but scripts are not executed). Could you help ?

Code: Select all

return {
 on ={devices ={'Cube_kat'}},

    execute = function(dz,item)
        local kat = item.nValue
        print(kat)
if kat > 0 then
    print("Zwiekszam glosnosc")
    os.execute ('sh /home/pi/domoticz/scripts/radio/volume_plus.sh')
end
if kat < 0 then
    print("Zmniejszam glosnosc")
    os.execute ('sh /home/pi/domoticz/scripts/radio/volume_minus.sh')
end
end
}

Re: Execution scripts problem

Posted: Monday 07 October 2019 23:04
by waaren
czasas wrote: Monday 07 October 2019 20:50 Hello could you tell me what Im doing wrong? When I rotate cube in right there should be executed specific scripts, the same for left. Scripts is recognising left and right (printing proper value, but scripts are not executed). Could you help ?
Hard to tell but cannot see anything wrong. Maybe something with domoticz user not having enough authorisation to access the sh script?
I use something similar

Code: Select all

return 
{
 on = 
 { 
    devices =
    {   
        'cubeSwitch'
    }
 },

    execute = function(dz,item)
        local cubeState = item.levelName
        dz.log('cube state: ' .. cubeState,dz.LOG_FORCE)
        os.execute ('/bashdir/argtest.sh ' .. cubeState)
    end
}
Log

Code: Select all

2019-10-07 22:57:03.093 Status: dzVents: Info: ------ Start external script: Xcube.lua: Device: "cubeSwitch (Xiaomi)", Index: 1739
2019-10-07 22:57:03.093 Status: dzVents: !Info: cube state: clock_wise
2019-10-07 22:57:03.108 Status: dzVents: Info: ------ Finished Xcube.lua
bash script

Code: Select all

cat /bashdir/argtest.sh

#!/bin/bash

echo $(date) $@ >> /usr/local/domotica/data/test$$
created file

Code: Select all

cat /usr/local/domotica/data/test14324
Mon 07 Oct 2019 10:57:03 PM CEST clock_wise
devices.png
devices.png (47.13 KiB) Viewed 342 times
cubeSwitch.png
cubeSwitch.png (16.65 KiB) Viewed 342 times

Re: Execution scripts problem

Posted: Monday 07 October 2019 23:30
by czasas
Hmmm , I have also 'shake' for one script, the first one below and its working . My permission looks like here:

drwxrwxrwx 2 pi pi 4096 Oct 7 23:24 .
drwxr-xr-x 13 pi pi 4096 Oct 7 18:21 ..
-rwxrwxrwx 1 pi pi 74 Oct 7 18:21 radiozet.sh
-rwxrwxrwx 1 root root 21 Oct 7 18:30 stop.sh
-rwxrwxrwx 1 root root 38 Oct 7 23:24 volume_minus.sh
-rwxrwxrwx 1 root root 38 Oct 7 23:21 volume_plus.sh

Re: Execution scripts problem

Posted: Tuesday 08 October 2019 1:01
by waaren
czasas wrote: Monday 07 October 2019 23:30 Hmmm , I have also 'shake' for one script, the first one below and its working . My permission looks like here:
Do you have to use sh as shell for these scripts ?
You might get a better indication in the log on what happens if you use this.

Code: Select all

return 
{
    on =
    {   
        devices = 
        { 
            'Cube_kat'
        }
    },

    execute = function(dz,item)
        local kat = item.nValue
        dz.log("nValue of " .. item.name .. ': ' .. item.nValue,dz.LOG_FORCE)
        
        local function osExecute(cmd)
            local fileHandle     = assert(io.popen(cmd, 'r'))
            local commandOutput  = assert(fileHandle:read('*a'))
            local returnTable    = {fileHandle:close()}

            dz.log("commandOutput: " .. commandOutput,dz.LOG_FORCE)
            dz.log("returncode   : " .. returnTable[3],dz.LOG_FORCE)
        end

        if kat > 0 then
            dz.log("Zwiekszam glosnosc",dz.LOG_FORCE)
            osExecute ('sh /home/pi/domoticz/scripts/radio/volume_plus.sh')
        elseif kat < 0 then
            dz.log("Zmniejszam glosnosc",dz.LOG_FORCE)
            osExecute ('sh /home/pi/domoticz/scripts/radio/volume_minus.sh')
        else
            dz.log("Nic nie robie",dz.LOG_FORCE)
        end
        
    end
}