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
Calling a bash script [Solved]
Moderator: leecollings
-
- Posts: 21
- Joined: Thursday 17 November 2016 10:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Germany
- Contact:
Calling a bash script
Domoticz on RPi3 with Aeontec Z-Stick gen5. Beta.
Z-Wave, Zigbee, WiFi and MQTT (mainly Tasmota), Neo Cool Cam, Devolo, Fibaro, Shelly, Hue, Osram, Blitzwolf, TP-Link, Alexa. Latest: Somfy IO integration
Z-Wave, Zigbee, WiFi and MQTT (mainly Tasmota), Neo Cool Cam, Devolo, Fibaro, Shelly, Hue, Osram, Blitzwolf, TP-Link, Alexa. Latest: Somfy IO integration
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Calling a bash script
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 21
- Joined: Thursday 17 November 2016 10:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Germany
- Contact:
Re: Calling a bash script [Solved]

I'll try osCommand(...) as helper function until Wednesday.
It seems to be exactly what I'm looking for!
Domoticz on RPi3 with Aeontec Z-Stick gen5. Beta.
Z-Wave, Zigbee, WiFi and MQTT (mainly Tasmota), Neo Cool Cam, Devolo, Fibaro, Shelly, Hue, Osram, Blitzwolf, TP-Link, Alexa. Latest: Somfy IO integration
Z-Wave, Zigbee, WiFi and MQTT (mainly Tasmota), Neo Cool Cam, Devolo, Fibaro, Shelly, Hue, Osram, Blitzwolf, TP-Link, Alexa. Latest: Somfy IO integration
-
- Posts: 21
- Joined: Thursday 17 November 2016 10:28
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Beta
- Location: Germany
- Contact:
Re: Calling a bash script
Thanks again waaren! Works like a charm!
Domoticz on RPi3 with Aeontec Z-Stick gen5. Beta.
Z-Wave, Zigbee, WiFi and MQTT (mainly Tasmota), Neo Cool Cam, Devolo, Fibaro, Shelly, Hue, Osram, Blitzwolf, TP-Link, Alexa. Latest: Somfy IO integration
Z-Wave, Zigbee, WiFi and MQTT (mainly Tasmota), Neo Cool Cam, Devolo, Fibaro, Shelly, Hue, Osram, Blitzwolf, TP-Link, Alexa. Latest: Somfy IO integration
Who is online
Users browsing this forum: No registered users and 1 guest