Page 1 of 1

Calling a bash script

Posted: Sunday 10 November 2019 20:13
by Olfer
Hi,

is it possible somehow to ca a bash script from DzVents? (location: script://home/piuser/domoticz/scripts/myscript.sh)

Background:
I want to TTS my Washingmachine and Dryer Status to Alexa via the alexa_remote script. Yes, I could do it with On and Off actions on a switch or using the http notification, but...
I use the http notification for notifying me via Microsoft Flow (don't hate me!) and I have already an Off Script running. So I think callit via dzvents would be a nice solution.Also it would be more flexible as this would not be limited to switches.


Cheers

Re: Calling a bash script

Posted: Sunday 10 November 2019 20:42
by waaren
Olfer wrote: Sunday 10 November 2019 20:13 is it possible somehow to ca a bash script from DzVents? (location: script://home/piuser/domoticz/scripts/myscript.sh)
Something like this:

Code: Select all

return 
{ 
    on = 
    { 
        timer = {'at 20:41'}, -- change to to tine to trigger
        devices = { 'MotionSensor' }, -- Change to name of your trigger device
    },  

    logging = { level = domoticz.LOG_DEBUG  },

    execute = function(dz, item)
        _G.logMarker =  _G.moduleLabel -- set logmarker to scrptname

        local function osCommand(cmd)
            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)

            local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}

            if commandOutput:find '::ERROR::' then     -- something went wrong
               dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_ERROR)
            else -- all is fine!!
                dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
            end

            return commandOutput,returnTable[3] -- rc[3] contains returnCode
        end

        osCommand('bash -c /bashdir/test.sh') -- Full qualified /path/scriptname
    end
}

Re: Calling a bash script  [Solved]

Posted: Sunday 10 November 2019 21:14
by Olfer
:D Thanks a LOT!
I'll try osCommand(...) as helper function until Wednesday.
It seems to be exactly what I'm looking for!

Re: Calling a bash script

Posted: Monday 11 November 2019 22:07
by Olfer
Thanks again waaren! Works like a charm!