Script can not run inside Domoticz

All kinds of 'OS' scripts

Moderator: leecollings

vamp
Posts: 34
Joined: Saturday 06 October 2018 13:20
Target OS: Linux
Domoticz version:
Contact:

Script can not run inside Domoticz

Post 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...
User avatar
jvdz
Posts: 2189
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Script can not run inside Domoticz

Post by jvdz »

It does have the X attribute set?

Jos
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: Script can not run inside Domoticz

Post by emme »

try addind a space after the last & at the end of the miio launch line
The most dangerous phrase in any language is:
"We always done this way"
vamp
Posts: 34
Joined: Saturday 06 October 2018 13:20
Target OS: Linux
Domoticz version:
Contact:

Re: Script can not run inside Domoticz

Post 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...:(
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Script can not run inside Domoticz

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

Re: Script can not run inside Domoticz

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
vamp
Posts: 34
Joined: Saturday 06 October 2018 13:20
Target OS: Linux
Domoticz version:
Contact:

Re: Script can not run inside Domoticz

Post 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
vamp
Posts: 34
Joined: Saturday 06 October 2018 13:20
Target OS: Linux
Domoticz version:
Contact:

Re: Script can not run inside Domoticz

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

Re: Script can not run inside Domoticz

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
vamp
Posts: 34
Joined: Saturday 06 October 2018 13:20
Target OS: Linux
Domoticz version:
Contact:

Re: Script can not run inside Domoticz

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

Re: Script can not run inside Domoticz

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
vamp
Posts: 34
Joined: Saturday 06 October 2018 13:20
Target OS: Linux
Domoticz version:
Contact:

Re: Script can not run inside Domoticz

Post 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
Last edited by vamp on Wednesday 17 April 2019 23:32, edited 1 time in total.
vamp
Posts: 34
Joined: Saturday 06 October 2018 13:20
Target OS: Linux
Domoticz version:
Contact:

Re: Script can not run inside Domoticz

Post by vamp »

Any other ideas?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script can not run inside Domoticz

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
vamp
Posts: 34
Joined: Saturday 06 October 2018 13:20
Target OS: Linux
Domoticz version:
Contact:

Re: Script can not run inside Domoticz

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

Re: Script can not run inside Domoticz

Post 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 
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
vamp
Posts: 34
Joined: Saturday 06 October 2018 13:20
Target OS: Linux
Domoticz version:
Contact:

Re: Script can not run inside Domoticz

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

Re: Script can not run inside Domoticz

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
vamp
Posts: 34
Joined: Saturday 06 October 2018 13:20
Target OS: Linux
Domoticz version:
Contact:

Re: Script can not run inside Domoticz

Post 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

Code: Select all

'["on"]'
or replace it with single quotation mark. (in terminal)
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Script can not run inside Domoticz

Post 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

Code: Select all

'["on"]'
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 &' 
?
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: No registered users and 1 guest