Adding Somfy blinds to domoticz using 433.92 crystal Topic is solved

433Mhz opensource Receiver & Transmitter.

Moderators: leecollings, Stuntteam

Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

Hi all,

I got my Somfy sunblinds working with a cheap crystal using a 433.92Mhz crystal on Gpio ports using this script: https://github.com/alxlaxv/SomPi
If i use the command line i can use my sunblinds. They wil close and open perfectly.

Code: Select all

pi@raspberrypi:~/domoticz/scripts/SomPi $ ./controller.py Overkapping open
pi@raspberrypi:~/domoticz/scripts/SomPi $ ./controller.py Overkapping close
Now i want to use the command in domoticz but i cant get it to work.
Add Switch.jpg
Add Switch.jpg (34.78 KiB) Viewed 1981 times
Capture.jpg
Capture.jpg (39.55 KiB) Viewed 1981 times
I get the error :
Error executing script command (/home/pi/domoticz/scripts/SomPi/controller.py). returned: 256
My guess is that my line is not correct in the domoticz switch.

I hope you can figure out my bad english :lol:
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by FireWizard »

Hi,

@Havym

You wrote:
Error executing script command (/home/pi/domoticz/scripts/SomPi/controller.py). returned: 256
My guess is that my line is not correct in the domoticz switch.
You have 2 options for the script.

1. Use relative path:
In this case it is assumed that the script is installed in ~/domoticz/scripts
On action would be: script://your_script

2. Use absolute path:
The on action would be e.g.: script:///home/pi/domoticz/scripts/your_script.

Mind the difference in 2 // and 3 ///.

You seem to use option 1 (Relative path)
So your script should be: script://SomPi/controller.py parameter1 parameter2
So 2 // and I think your script is correct.

Be aware that the script is owned by the same user, as that Domoticz is running.
Usely Domoticz runs as root.
Also you should set the eXecute bit for the script.
Check that you see a x if you do: ls -l controller.py.

If this doesn't help you can you post the script.

See also: https://www.domoticz.com/forum/viewtopic.php?t=17285
And: https://www.domoticz.com/forum/viewtopi ... 41#p231841

Regards
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

Thanks for your reply.
I'm a Noob with scripts so i had to read your answer 5 times.

Both ways gives me the 256 error so i think my problem is in the script.
My problem is the same as mentioned in https://www.domoticz.com/forum/viewtopic.php?t=17285 like you referred to me.
The script uses a txt file in a subfolder..

Its not my script but here you can find it https://github.com/alxlaxv/SomPi

-rwxr-xr-x 1 pi pi 4516 Apr 13 16:03 controller.py
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by FireWizard »

Hi,

Could you try to run your script as root user: sudo /home/pi/domoticz/scripts/SomPi/controller.py Overkapping open, or close

What do you see?

Regards
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

FireWizard wrote: Monday 13 April 2020 19:32 Could you try to run your script as root user: sudo /home/pi/domoticz/scripts/SomPi/controller.py Overkapping open, or close

Code: Select all

pi@raspberrypi:~ $  sudo /home/pi/domoticz/scripts/SomPi/controller.py Overkapping close
Action       : close
Room         : Overkapping
Traceback (most recent call last):
  File "/home/pi/domoticz/scripts/SomPi/controller.py", line 164, in <module>
    send(sys.argv[1], sys.argv[2])
  File "/home/pi/domoticz/scripts/SomPi/controller.py", line 43, in send
    with open("remotes/" + room + ".txt", 'r') as file:
IOError: [Errno 2] No such file or directory: 'remotes/Overkapping.txt'
Run in subfolder:

Code: Select all

pi@raspberrypi:~/domoticz/scripts/SomPi $ sudo ./controller.py Overkapping close
Action       : close
Room         : Overkapping
Remote       : 0x267043
Button       : 0x04
Rolling code : 232
Frame        : 0xA7 0x40 0x00 0xE8 0x26 0x70 0x43
With cks     : 0xA7 0x4B 0x00 0xE8 0x26 0x70 0x43
Obfuscated   : 0xA7 0xEC 0xEC 0x04 0x22 0x52 0x11
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by FireWizard »

Hi,

One other try.

Go to the /home/pi/domoticz/scripts/ folder and run sudo SomPi/controller.py Overkapping close

Please publish the result.
I expect the same result as with: sudo /home/pi/domoticz/scripts/SomPi/controller.py Overkapping close

If so, do the following:

Move your file controller.py from the /home/pi/domoticz/scripts/SomPi/ to the /home/pi/domoticz/scripts/ folder.
So one folder higher.

Regards
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

FireWizard wrote: Tuesday 14 April 2020 16:04 Go to the /home/pi/domoticz/scripts/ folder and run sudo SomPi/controller.py Overkapping close
Please publish the result.
I expect the same result as with: sudo /home/pi/domoticz/scripts/SomPi/controller.py Overkapping close
Hi, your right, same result:

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ sudo SomPi/controller.py Overkapping close
Action       : close
Room         : Overkapping
Traceback (most recent call last):
  File "SomPi/controller.py", line 164, in <module>
    send(sys.argv[1], sys.argv[2])
  File "SomPi/controller.py", line 43, in send
    with open("remotes/" + room + ".txt", 'r') as file:
IOError: [Errno 2] No such file or directory: 'remotes/Overkapping.txt'
FireWizard wrote: Tuesday 14 April 2020 16:04 If so, do the following:

Move your file controller.py from the /home/pi/domoticz/scripts/SomPi/ to the /home/pi/domoticz/scripts/ folder.
So one folder higher.

Regards
When controller.py and subfolder remotes is moved to the scripts folder and i use 'sudo controller.py Overkapping close' it shows

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ sudo controller.py Overkapping close
sudo: controller.py: command not found
When i use 'sudo ./controller.py Overkapping close' it works
Same as in subfolder SomPi using ./controller.py

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ sudo ./controller.py Overkapping close
Action       : close
Room         : Overkapping
Remote       : 0x267043
Button       : 0x04
Rolling code : 243
Frame        : 0xA7 0x40 0x00 0xF3 0x26 0x70 0x43
With cks     : 0xA7 0x41 0x00 0xF3 0x26 0x70 0x43
Obfuscated   : 0xA7 0xE6 0xE6 0x15 0x33 0x43 0x00
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by FireWizard »

Hi,
@Havym

That is correct.

In all unixes and linux you have to precede the command (in this case controller.py) with ./, unless the folder is in your path.
The folder /home/pi/domoticz/scripts is not in your path, so every command you want to run in this folder you have to precede with ./.

What is happening, if you replace in Domoticz "Aan actie:" with: script://controller.py Overkapping open
and
"Uit actie:" with script://controller.py Overkapping close

Regards
Last edited by FireWizard on Saturday 30 May 2020 23:03, edited 1 time in total.
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

I tried making a dummy switch with these command and got the error again in domoticz

Code: Select all

2020-04-16 12:14:19.440 Error: Error executing script command (/home/pi/domoticz/scripts/controller.py). returned: 256
And in command line:

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ ./controller.py Overkapping close
Action       : close
Room         : Overkapping
Remote       : 0x267043
Button       : 0x04
Rolling code : 244
Frame        : 0xA7 0x40 0x00 0xF4 0x26 0x70 0x43
With cks     : 0xA7 0x46 0x00 0xF4 0x26 0x70 0x43
Obfuscated   : 0xA7 0xE1 0xE1 0x15 0x33 0x43 0x00
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

Unfortunately it still doesn't work. Can i put this command in another file and run the new file?
Maybe you can tell me how the script should look like. I cant do it myself.
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by FireWizard »

Hi,

Sorry for my late reply, because of some other obligations.

I think you suffer from the same issue , that I had some time ago.

See: https://www.domoticz.com/forum/viewtopi ... tt#p233291

I suggest the following:

1. Make the script file owned by root and group root:

Code: Select all

sudo chown root.root controller.py
2. Now set the SetUID bit, make it executable for all and writable only by root:

Code: Select all

sudo chmod 4755 controller.py
Keep in mind if this script will allow any input or editing of files, this will also be done as root.

The SetUID bit makes a script or binary always run as the owner of the file/binary.

Fount at: https://askubuntu.com/questions/167847/ ... o-password

Regards
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

No problem about your late reply. Sometimes life keeps up busy. But maybe you forgot about me :roll:

Maybe i should mention it before but domoticz is run by user pi and not by root.
But i tried the things you mentioned but it still doenst work.
Using command line with sudo /home/pi/domoticz/scripts/SomPi/controller.py Overkapping close i get these results:

Code: Select all

pi@raspberrypi:~ $ sudo /home/pi/domoticz/scripts/controller.py Overkapping close
Action       : close
Room         : Overkapping
Traceback (most recent call last):
  File "/home/pi/domoticz/scripts/controller.py", line 164, in <module>
    send(sys.argv[1], sys.argv[2])
  File "/home/pi/domoticz/scripts/controller.py", line 43, in send
    with open("remotes/" + room + ".txt", 'r') as file:
IOError: [Errno 2] No such file or directory: 'remotes/Overkapping.txt'
And in domoticz

Code: Select all

Error executing script command (/home/pi/domoticz/scripts/controller.py). returned: 256

Code: Select all

-rwsr-xr-x 1 root root  4516 Apr 13 16:03 controller.py
The funny thing is... i run the same kind of script for my 433Mhz Klik aan Klik uit with codesend

Code: Select all

-rwxr-xr-x 1 pi pi 20104 Oct  7  2019 codesend
Is it because my controller.py is a python script file?
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

I managed to got it working from /home/pi/domoticz/scripts/controller.py

Code: Select all

pi@raspberrypi:~ $ sudo /home/pi/domoticz/scripts/controller.py Overkapping close
Action       : close
Room         : Overkapping
Remote       : 0x267043
Button       : 0x04
Rolling code : 263
Frame        : 0xA7 0x40 0x01 0x07 0x26 0x70 0x43
With cks     : 0xA7 0x4B 0x01 0x07 0x26 0x70 0x43
Obfuscated   : 0xA7 0xEC 0xED 0xEA 0xCC 0xBC 0xFF
I had to remove the folder 'remotes' to the right place in /home/pi

But still when its executed in domoticz i get error 256
Is it because of the reply from the script that it doenst work in domoticz?

I tried making overkappingclose.sh file to execute and it works in command line but not in domoticz. Same result 256

Code: Select all

#!/bin/bash
/usr/bin/python2 /home/pi/domoticz/scripts/controller.py Overkapping close
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by FireWizard »

Hi,

@Havym

You wrote:
Maybe i should mention it before but domoticz is run by user pi and not by root.
I have been focused on the fact that Domoticz runs as root, which is the case by default.
That changes the way we have to think and you can forget all previous links and suggestions.

I overlooked also an important error message:
IOError: [Errno 2] No such file or directory: 'remotes/Overkapping.txt'
I see also: -rwsr-xr-x 1 root root 4516 Apr 13 16:03 controller.py

I advise you to remove the setuid permission, as the controller.py is owned by root. Having setuid permission on root owned files opens your system to intrusion.

Code: Select all

sudo chmod 755 controller.py
And you can also change the ownership back to the pi user

Code: Select all

sudo chown pi.pi controller.py
Having done these things, have a look at: https://www.domoticz.com/forum/viewtopic.php?t=7465
The answer is probably there.

You need an intermediate script.

Change the script in Domoticz for ON to: ///home/pi/domoticz/scripts/controllerON.sh

Create a script in the scripts directory, called controllerON.sh

Contents controllerON.sh:

Code: Select all

#!/bin/sh
python controller.py Overkapping open > /dev/null 2>&1 &
exit 0
And the same with the script for OFF: ///home/pi/domoticz/scripts/controllerOFF.sh

Contents of controllerOFF.sh:

Code: Select all

#!/bin/sh
python controller.py Overkapping close > /dev/null 2>&1 &
exit 0
I hope you have success, but at least I wish you a nice weekend.

Regards
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

Thank you for your help. I found this topic before but didn't understand what to do. Thanks to you i do.
But still...

Here are my findings.

When i run in command line: sudo /home/pi/domoticz/scripts/overkappingclose.sh
or just /home/pi/domoticz/scripts/overkappingclose.sh the screen closes.

I updated the switch in domoticz with these: script:///home/pi/domoticz/scripts/overkappingclose.sh and nothing happens.
The logs gives no error but nothing happens.

Code: Select all

2020-04-19 19:35:58.340 Status: User: Admin initiated a switch command (153/Zonnescherm/On)
2020-04-19 19:35:58.545 Status: Executing script: /home/pi/domoticz/scripts/overkappingclose.sh
Ill keep on trying some other stuff. I dont know what i am doing wrong. Or i am just stupid :|
Maybe i can try to program the screen by a .sh file.... :?:

Piece of my domoticz config:

Code: Select all

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
DESC="Domoticz Home Automation System"
NAME=domoticz
USERNAME=pi
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

DAEMON=/home/$USERNAME/domoticz/$NAME
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by FireWizard »

@Havym

Hi,

One more check.

All files are now owned by user pi and group pi?
All scripts are executable?

Let's follow the procedure as described in the Wiki.

https://www.domoticz.com/wiki/Scripting_in_Domoticz

So,

Lets create a file called exec.sh:
User pi and group pi Make it executable
Contents:

Code: Select all

#! /bin/sh
/usr/bin/python /home/pi/domoticz/scripts/$1.py $2 $3 > /dev/null 2>&1 &
In Domoticz use the following command for On action:

Code: Select all

script://exec.sh controller Overkapping open
and for Off action:

Code: Select all

script://exec.sh controller Overkapping close
Let's try.

Regards
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

Code: Select all

pi@raspberrypi:~/domoticz/scripts $ ls -l exec.sh
-rwxr-xr-x 1 pi pi 84 Apr 19 22:04 exec.sh
Domoticz log:

Code: Select all

2020-04-19 22:09:17.348 Status: User: Admin initiated a switch command (153/Zonnescherm/Off)
2020-04-19 22:09:17.578 Status: Executing script: /home/pi/domoticz/scripts/exec.sh
Still nothing happens

When run in command line it works.

Code: Select all

pi@raspberrypi:~ $ /home/pi/domoticz/scripts/exec.sh controller Overkapping close
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by FireWizard »

Hi

There must be something else, but what?

Let me think, what to do.

Regards
User avatar
FireWizard
Posts: 1747
Joined: Tuesday 25 December 2018 12:11
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Voorthuizen (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by FireWizard »

Hi,

Can you modify the exec.sh file as follows:

Code: Select all

#!/bin/sh
NOW=$(date +"%Y-%m-%d")
LOGFILE=/home/pi/controller.$NOW.log
echo $(date +"%Y-%m-%d %H:%M:%S") controller | tee -a $LOGFILE
/usr/bin/python /home/pi/domoticz/scripts/$1.py $2 $3 > /dev/null 2>&1 &
This will create a log file in your /home/pi directory.

Please try again and post the results

Regards
Havym
Posts: 29
Joined: Tuesday 08 October 2019 12:54
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Enschede (NL)
Contact:

Re: Adding Somfy blinds to domoticz using 433.92 crystal

Post by Havym »

Hi,

Here are the results when executed in domoticz. The first one was the one function and the second the off function.

Code: Select all

2020-04-19 23:57:36 controller
2020-04-19 23:57:43 controller
By command line the same:

Code: Select all

pi@raspberrypi:~ $ /home/pi/domoticz/scripts/exec.sh Overkapping close
2020-04-20 00:02:00 controller
Same as in the log file.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest