Execution scripts problem

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
czasas
Posts: 19
Joined: Thursday 26 September 2019 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Execution scripts problem

Post 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
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Execution scripts problem

Post 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 292 times
cubeSwitch.png
cubeSwitch.png (16.65 KiB) Viewed 292 times
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
czasas
Posts: 19
Joined: Thursday 26 September 2019 21:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Execution scripts problem

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Execution scripts problem

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: kniazio and 1 guest