Synology - script doesn't work

Moderator: leecollings

User avatar
fabry91
Posts: 67
Joined: Sunday 09 December 2018 16:52
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Italy
Contact:

Re: Synology - script doesn't work

Post by fabry91 »

EddyG wrote: Wednesday 05 January 2022 15:45 It should be:

Code: Select all

script:///opt/domoticz/scripts/relay....
because Domoticz is inside docker and using paths like /opt/domoticz/.....

You could check what the right path is by going inside docker.
Yes, right, now it returns a different error, maybe something to do with user rights?
Attachments
domologs.jpg
domologs.jpg (52.82 KiB) Viewed 46084 times
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Synology - script doesn't work

Post by EddyG »

That is probably because the 'nc' command is not in the docker image.
You could install that but remember that every time you update the image you will have to do it again, because it is lost if you update the image.
Go into the container with

Code: Select all

sudo docker run -it domoticz/domoticz /bin/bash
execute these command in the container.

Code: Select all

apt-get update
apt-get install netcat
exit the container.
User avatar
fabry91
Posts: 67
Joined: Sunday 09 December 2018 16:52
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Italy
Contact:

Re: Synology - script doesn't work

Post by fabry91 »

EddyG wrote: Wednesday 05 January 2022 16:26 That is probably because the 'nc' command is not in the docker image.
You could install that but remember that every time you update the image you will have to do it again, because it is lost if you update the image.
Go into the container with

Code: Select all

sudo docker run -it domoticz/domoticz /bin/bash
execute these command in the container.

Code: Select all

apt-get update
apt-get install netcat
exit the container.
I have tried to install netcut but it returns with some warnings, same error in Domoticz when I run the script:

PS. the script is:

Code: Select all

echo -n "11" | nc -n -w 1 192.168.0.99 6722
Attachments
containerbash.jpg
containerbash.jpg (184.29 KiB) Viewed 46082 times
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Synology - script doesn't work

Post by EddyG »

Try using netcat instead of the nc command in the script.

Code: Select all

echo -n "11" | netcat -n -w 1 192.168.0.99 6722
User avatar
fabry91
Posts: 67
Joined: Sunday 09 December 2018 16:52
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Italy
Contact:

Re: Synology - script doesn't work

Post by fabry91 »

EddyG wrote: Wednesday 05 January 2022 16:57 Try using netcat instead of the nc command in the script.

Code: Select all

echo -n "11" | netcat -n -w 1 192.168.0.99 6722
same error, I noticed that in the container scripts folder there isn't the same script files outside the docker:

PS. I have modified the scripts file in "\docker\Domoticz\scripts"
Attachments
scripts.jpg
scripts.jpg (107.8 KiB) Viewed 46076 times
domologs.jpg
domologs.jpg (47.46 KiB) Viewed 46076 times
User avatar
fabry91
Posts: 67
Joined: Sunday 09 December 2018 16:52
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Italy
Contact:

Re: Synology - script doesn't work

Post by fabry91 »

Maybe figured it out!!

I added at the end of the Action: "script:///opt/domoticz/.... & and now command are executing right, will check in place when I get home ;)
Attachments
domoactionscript.jpg
domoactionscript.jpg (26.02 KiB) Viewed 46069 times
domologs.jpg
domologs.jpg (41.27 KiB) Viewed 46069 times
User avatar
fabry91
Posts: 67
Joined: Sunday 09 December 2018 16:52
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Italy
Contact:

Re: Synology - script doesn't work

Post by fabry91 »

EddyG wrote: Wednesday 05 January 2022 16:57 Try using netcat instead of the nc command in the script.

Code: Select all

echo -n "11" | netcat -n -w 1 192.168.0.99 6722
Doesn't help to use netcat instead of "nc"...
Result of domoticz logs:

Code: Select all

Error: Error executing script command (/opt/domoticz/scripts/relay_ch2_on.sh). returned: 32512
and the relay doesn't turn on or off, maybe netcut is not installed right? :(
How can I test netcat and be sure it is working?
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Synology - script doesn't work

Post by EddyG »

I oversaw that you have to open port 6722 in the docker container besides the port 8080 and 443
Did you test the complete command on the command line in the docker container?
User avatar
fabry91
Posts: 67
Joined: Sunday 09 December 2018 16:52
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Italy
Contact:

Re: Synology - script doesn't work

Post by fabry91 »

EddyG wrote: Wednesday 05 January 2022 21:50 I oversaw that you have to open port 6722 in the docker container besides the port 8080 and 443
Did you test the complete command on the command line in the docker container?
Okay, port settings of the docker says that is in the same network of the docker host, how can I open port 6722?
Attachments
Screenshot_20220105-222521__01.jpg
Screenshot_20220105-222521__01.jpg (55.95 KiB) Viewed 46036 times
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Synology - script doesn't work

Post by EddyG »

Set the problem of the port aside, it does not hurt, I assumed that the same port might be used for a response.
First get your script working from inside docker.
Did you try to execute the script content inside the docker container?

Code: Select all

echo -n "11" | nc -n -w 1 192.168.0.99 6722
Did you try to find inside the container your script?
E.g. in /opt/domoticz/scripts or /opt/domoticz/userdata or /opt/domoticz/userdata/scripts
And what is the result?
If you found your script in the docker container, did you try to execute the script from inside the container?
And what is the result?
If you lack the experience with docker, either read more about docker and how to install and maintain containers or go back to your working raspberry.
User avatar
fabry91
Posts: 67
Joined: Sunday 09 December 2018 16:52
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Italy
Contact:

Re: Synology - script doesn't work

Post by fabry91 »

EddyG wrote: Thursday 06 January 2022 10:35 Set the problem of the port aside, it does not hurt, I assumed that the same port might be used for a response.
First get your script working from inside docker.
Did you try to execute the script content inside the docker container?

Code: Select all

echo -n "11" | nc -n -w 1 192.168.0.99 6722
Did you try to find inside the container your script?
E.g. in /opt/domoticz/scripts or /opt/domoticz/userdata or /opt/domoticz/userdata/scripts
And what is the result?
If you found your script in the docker container, did you try to execute the script from inside the container?
And what is the result?
If you lack the experience with docker, either read more about docker and how to install and maintain containers or go back to your working raspberry.
Hello Eddy and thank you again for your reply.

I am new with docker and I succesfull migrate Domoticz db, DZGA and get everything working, only thing that is not working is this SR-201 script relay.

So I tried to execute the script from a command line inside the docker and the result is "command not found":
Attachments
scripts.jpg
scripts.jpg (139.46 KiB) Viewed 45993 times
User avatar
waltervl
Posts: 5907
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Synology - script doesn't work

Post by waltervl »

Do I read netcut? it should be netcat.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
fabry91
Posts: 67
Joined: Sunday 09 December 2018 16:52
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Italy
Contact:

Re: Synology - script doesn't work

Post by fabry91 »

waltervl wrote: Thursday 06 January 2022 13:09 Do I read netcut? it should be netcat.
You are right! Thank you and will try later
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Synology - script doesn't work

Post by EddyG »

That is really strange. I did the same on my test system where domoticz also runs in a container.
I got the same errors when installing netcat.
Both nc and netcat are found in /bin/ in the docker container.
Your echo -n "11" | nc -n -w 1 192.168.0.99 6722 command runs fine in my container, of course I get an error about the non-existing IP or with a real IP that connection is refused.
You can check if those nc and netcat commands exists in the /bin/ directory in the container.
Remember (like I said before) when ever you stop the container or update the image the 2 command to install netcat have to be run again.
'netcat' is NOT part of the image. That is 1 of the disadvantages of running Domoticz in a docker container.
If you do have anything special (like you have with netcat / nc) than Domoticz in a container might not be a good idea.
Last edited by EddyG on Thursday 06 January 2022 13:26, edited 1 time in total.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Synology - script doesn't work

Post by EddyG »

When nc is not found then netcat is not found either. nc is just a link to netcat.

I already mentioned here that there is a way around it, see here: viewtopic.php?p=282919#p282919
But that is really complicated for people who are not familiar with Linux.
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Synology - script doesn't work

Post by EddyG »

Also an idea might be to look for a python script that will do the same as your script.
python3 is default included in the Domoticz container image.
User avatar
waltervl
Posts: 5907
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Synology - script doesn't work

Post by waltervl »

And here is the python equivalent (and doing much more): https://github.com/cryxli/sr201/blob/ma ... t/relay.py

usage

Code: Select all

python relay.py 192.168.0.99 close:1
to close relay 1

Code: Select all

python relay.py 192.168.0.99 open:1
to open relay 1
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
fabry91
Posts: 67
Joined: Sunday 09 December 2018 16:52
Target OS: NAS (Synology & others)
Domoticz version: 2022.2
Location: Italy
Contact:

Re: Synology - script doesn't work

Post by fabry91 »

Hello Eddy and Walter,

thank you very much for yours suggestion, I finally figured it out doing this:

- open a new terminal on the Domoticz container
- cd scripts
- execute the command

Code: Select all

apt-get update
apt-get install netcat
- test the script

Code: Select all

echo -n "11" | nc -n -w 1 192.168.0.99 6722
with the return of "10000000" for on and "00000000" for off, with succesfull switch on and off of the relay :D

So now in domoticz no error and can control perfectly the SR-201

I know that SR-201 can use python script too but the easiest way when we tested for the first time this type of relay was to use netcat.

@EddyG only thing is that, when I stop e start back the container the script continue to work, anyway better ;)

Thank you very very much for all of your time and effort! ;) ;) ;)
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: Synology - script doesn't work

Post by EddyG »

Glad that it worked, but you still might investigate some time in the python3 solution, because that is always present in the container image.
So netcat does not get lost when you update the container.
@waltervl unfortunately there is, for some reason, no link from python to python3 in the container, so python will not work, only python3.
User avatar
waltervl
Posts: 5907
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Synology - script doesn't work

Post by waltervl »

In the script there is a reference to python3 so it should work....

#!/usr/bin/python3
#
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest