Page 1 of 2
Script can not run inside Domoticz
Posted: Monday 15 April 2019 9:52
by vamp
Hello there,
i would like to run this script via dummy switch:
Code: Select all
#!/bin/bash
/usr/local/bin/miio protocol call ID set_arming '["on"]' > /dev/null 2>&1 &
exit 0
The Domoticz log say that is run well, but nothing happen...
I try:
1. chmod +x
2. script://start_alarm.sh
3. script:///home/user/domoticz/scripts/start_alarm.sh
4. login to root and run the scipt via terminal (working well)
5. login to my user and run script via terminal (working well)
The domoticz installed via installer script (Ubuntu) i think (??) it run with root priv.
Not other idea, why not run in domoticz and why run with normal terminal...
Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 17:40
by jvdz
It does have the X attribute set?
Jos
Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 17:58
by emme
try addind a space after the last & at the end of the miio launch line
Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 21:03
by vamp
jvdz wrote: ↑Monday 15 April 2019 17:40
It does have the X attribute set?
Jos
It is the first thing in my list that i try
@emme it not help...

Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 21:20
by EddyG
Insert something like below on different places.
Code: Select all
echo "Bin here 1" > /home/pi/log.txt
And change the number on the different places.
Also redirect the output to the same file, instead of the ' > /dev/null 2>&1'
This way you can track if the script is executed and where things go wrong.
Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 21:28
by waaren
vamp wrote: ↑Monday 15 April 2019 9:52
I would like to run this script via dummy switch:
Code: Select all
#!/bin/bash
/usr/local/bin/miio protocol call ID set_arming '["on"]' > /dev/null 2>&1 &
exit 0
[/code]
if you change exit 0 to exit $? you will see the actual returncode of the command
Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 21:37
by vamp
waaren wrote: ↑Monday 15 April 2019 21:28
vamp wrote: ↑Monday 15 April 2019 9:52
I would like to run this script via dummy switch:
Code: Select all
#!/bin/bash
/usr/local/bin/miio protocol call ID set_arming '["on"]' > /dev/null 2>&1 &
exit 0
[/code]
if you change exit 0 to exit $? you will see the actual returncode of the command
Now it say:
2019-04-15 21:36:38.685 Status: User: admin initiated a switch command (151/riaszto_auto/On)
2019-04-15 21:36:38.905 Status: Executing script: /home/vamp/domoticz/scripts/start_alarm.sh
2019-04-15 21:36:38.913 Error: Error executing script command (/home/vamp/domoticz/scripts/start_alarm.sh). returned: 512
Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 21:46
by vamp
EddyG wrote: ↑Monday 15 April 2019 21:20
Insert something like below on different places.
Code: Select all
echo "Bin here 1" > /home/pi/log.txt
And change the number on the different places.
Also redirect the output to the same file, instead of the ' > /dev/null 2>&1'
This way you can track if the script is executed and where things go wrong.
I put echo one of before the exetuce line and one of after them.
also i replace the /dev/null.... thing.
The reason:
The file(log.txt) is created (with root priv.)and write the echo line correctly. but the script not working...
Info: i use x86 ubuntu , not Pi.
Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 22:16
by waaren
returncode 512 points into the direction of an access violation.
Can you try and change
Code: Select all
/usr/local/bin/miio protocol call ID set_arming '["on"]' > /dev/null 2>&1 &
to
Code: Select all
/bin/bash -c '/usr/local/bin/miio protocol call ID set_arming ["on"] > /tmp/miio.out'
this worked for me when I had a similar problem when trying to execute a command from within monit. Have to admit I did not (and don't) understand why this worked but it does (from monit that is)
If it works you can try and add the & to see if it also works in the background.
Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 22:47
by vamp
waaren wrote: ↑Monday 15 April 2019 22:16
returncode 512 points into the direction of an access violation.
Can you try and change
Code: Select all
/usr/local/bin/miio protocol call ID set_arming '["on"]' > /dev/null 2>&1 &
to
Code: Select all
/bin/bash -c '/usr/local/bin/miio protocol call ID set_arming ["on"] > /tmp/miio.out'
this worked for me when I had a similar problem when trying to execute a command from within monit. Have to admit I did not (and don't) understand why this worked but it does (from monit that is)
If it works you can try and add the & to see if it also works in the background.
I try it, but if i change the script that you suggest it, the script is not execute (in terminal)
Working scirpt:
Code: Select all
vamp@ubuntu:~$ /usr/local/bin/miio protocol call ID set_arming '["on"]'
INFO Attempting to call set_arming on ID
INFO Device found, making call
INFO Got result:
[
"ok"
]
Not working (need to break it)
Code: Select all
vamp@ubuntu:~$ /bin/bash -c '/usr/local/bin/miio protocol call ID set_arming '["on"]''
INFO Attempting to call set_arming on ID
INFO Device found, making call
^C
Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 23:08
by waaren
vamp wrote: ↑Monday 15 April 2019 22:47
waaren wrote: ↑Monday 15 April 2019 22:16
returncode 512 points into the direction of an access violation.
Can you try and change
Code: Select all
/usr/local/bin/miio protocol call ID set_arming '["on"]' > /dev/null 2>&1 &
to
Code: Select all
/bin/bash -c '/usr/local/bin/miio protocol call ID set_arming ["on"] > /tmp/miio.out'
this worked for me when I had a similar problem when trying to execute a command from within monit. Have to admit I did not (and don't) understand why this worked but it does (from monit that is)
If it works you can try and add the & to see if it also works in the background.
I try it, but if i change the script that you suggest it, the script is not execute (in terminal)
Working scirpt:
Code: Select all
vamp@ubuntu:~$ /usr/local/bin/miio protocol call ID set_arming '["on"]'
INFO Attempting to call set_arming on ID
INFO Device found, making call
INFO Got result:
[
"ok"
]
Not working (need to break it)
Code: Select all
vamp@ubuntu:~$ /bin/bash -c '/usr/local/bin/miio protocol call ID set_arming '["on"]''
INFO Attempting to call set_arming on ID
INFO Device found, making call
^C
Can you try with only one pair of single quotes ? see my previous post.
Re: Script can not run inside Domoticz
Posted: Monday 15 April 2019 23:09
by vamp
Can you try with only one pair of single quotes ? see my previous post.
Yes, same result...
Code: Select all
vamp@ubuntu:~$ sudo /bin/bash -c '/usr/local/bin/miio protocol call 78823132 set_arming ["on"]'
INFO Attempting to call set_arming on ID
INFO Device found, making call
^C
Re: Script can not run inside Domoticz
Posted: Wednesday 17 April 2019 13:25
by vamp
Any other ideas?
Re: Script can not run inside Domoticz
Posted: Wednesday 17 April 2019 14:54
by waaren
vamp wrote: ↑Wednesday 17 April 2019 13:25
Any other ideas?
Not really but would it be possible for you to add your xiaomi gateway as hardware to domoticz ?
Re: Script can not run inside Domoticz
Posted: Wednesday 17 April 2019 20:50
by vamp
waaren wrote: ↑Wednesday 17 April 2019 14:54
vamp wrote: ↑Wednesday 17 April 2019 13:25
Any other ideas?
Not really but would it be possible for you to add your xiaomi gateway as hardware to domoticz ?
Unfortunately it this mode is not support alert on/off.
Edit: I try to write it on python:
Code: Select all
#!/usr/bin/python
import subprocess
args = ['/usr/local/bin/miio', 'protocol', 'call', 'ID', 'set_arming', ""'["on"]'""]
with open('/tmp/out', "w") as outfile:
subprocess.call(args, stdout=outfile)
Same result... it working in terminal, but not working if i run it in Domoticz.
I try to stdout to a file. if i run it in terminal, the script write the expected output. if i run it in Domoticz, the stdout file is empty....
Re: Script can not run inside Domoticz
Posted: Thursday 18 April 2019 0:12
by waaren
vamp wrote: ↑Wednesday 17 April 2019 20:50
I try to stdout to a file. if i run it in terminal, the script write the expected output. if i run it in Domoticz, the stdout file is empty....
Can you try the dzVents script below ?
If you are not yet familiar with dzvents then please look at the 10 lines
using dzVents with Domoticz for an intro to dzVents and howto get this script active in domoticz.
Code: Select all
return {
on = { timer = {'every minute'}, -- This will trigger the script and display the content of miio.out
devices = { "triggerDevice" }}, -- change this to a virtual device you created. The script will execute if you switch this virtual device
logging = {
level = domoticz.LOG_DEBUG,
marker = "miio"
},
execute = function(dz, item)
local miioCMD = 'sudo /usr/local/bin/miio protocol call 78823132 set_arming ["on"] > miio.out &'
-- local miioCMD = 'sudo /usr/local/bin/miio discover > miio.out &' -- this produces output on my system
local getOutCMD = 'cat miio.out'
local function logWrite(str,level)
dz.log(tostring(str),level or dz.LOG_DEBUG)
end
local function osExecute(cmd)
logWrite("command for osExecute: ".. cmd)
local fileHandle = assert(io.popen(cmd, 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
logWrite("commandOutput: " .. commandOutput)
logWrite("returncode : " .. returnTable[3])
return commandOutput,returnTable[3] -- rc[3] contains returnCode
end
if item.isTimer then
osExecute(getOutCMD) -- this will show output of miio command. Can take more then 1 cycle before any output is in miio.out
else
osExecute(miioCMD)
end
end
}
Re: Script can not run inside Domoticz
Posted: Thursday 18 April 2019 7:55
by vamp
Thanks the help!
Here my output:
Code: Select all
2019-04-18 07:54:00.120 Status: dzVents: Info: miio: ------ Start internal script: teszt:, trigger: every minute
2019-04-18 07:54:00.120 Status: dzVents: Debug: miio: command for osExecute: cat miio.out
2019-04-18 07:54:00.126 Status: dzVents: Debug: miio: commandOutput: INFO Attempting to call set_arming on ID
2019-04-18 07:54:00.126
2019-04-18 07:54:00.126 INFO Device found, making call
2019-04-18 07:54:00.126
2019-04-18 07:54:00.126
2019-04-18 07:54:00.126 Status: dzVents: Debug: miio: returncode : 0
2019-04-18 07:54:00.126 Status: dzVents: Info: miio: ------ Finished teszt
But not active... It possible that the running time is too short?
It is the good output (it come if i run it in terminal)
Code: Select all
vamp@ubuntu:~$ /usr/local/bin/miio protocol call ID set_arming '["on"]'
INFO Attempting to call set_arming on ID
INFO Device found, making call
INFO Got result:
[
"ok"
]
Re: Script can not run inside Domoticz
Posted: Thursday 18 April 2019 8:26
by waaren
vamp wrote: ↑Thursday 18 April 2019 7:55
Thanks the help!
Here my output:
Code: Select all
2019-04-18 07:54:00.120 Status: dzVents: Info: miio: ------ Start internal script: teszt:, trigger: every minute
2019-04-18 07:54:00.120 Status: dzVents: Debug: miio: command for osExecute: cat miio.out
2019-04-18 07:54:00.126 Status: dzVents: Debug: miio: commandOutput: INFO Attempting to call set_arming on ID
2019-04-18 07:54:00.126
2019-04-18 07:54:00.126 INFO Device found, making call
2019-04-18 07:54:00.126
2019-04-18 07:54:00.126
2019-04-18 07:54:00.126 Status: dzVents: Debug: miio: returncode : 0
2019-04-18 07:54:00.126 Status: dzVents: Info: miio: ------ Finished teszt
But not active... It possible that the running time is too short?
It is the good output (it come if i run it in terminal)
Code: Select all
vamp@ubuntu:~$ /usr/local/bin/miio protocol call ID set_arming '["on"]'
INFO Attempting to call set_arming on ID
INFO Device found, making call
INFO Got result:
[
"ok"
]
No because command will run in the background and will finish when the called process finished. It can happen that the script when triggered by the timer = section executes before the command has finished but then the next minute it should pick up the result from miio.out.
Re: Script can not run inside Domoticz
Posted: Thursday 18 April 2019 8:47
by vamp
Well i don't know... now visible that the script is start running, the question is why missing the " Got result" part?
Interesting thing. I got the same problem if i delete the quotation marks the part of
or replace it with single quotation mark. (in terminal)
Re: Script can not run inside Domoticz
Posted: Thursday 18 April 2019 12:33
by waaren
vamp wrote: ↑Thursday 18 April 2019 8:47
Well i don't know... now visible that the script is start running, the question is why missing the " Got result" part?
Interesting thing. I got the same problem if i delete the quotation marks the part of
or replace it with single quotation mark. (in terminal)
Indeed very interesting.
can you try and change line 12 to
Code: Select all
local miioCMD = 'sudo /usr/local/bin/miio protocol call 78823132 set_arming [\\"on\\"] > miio.out &'
?