SainSmart iMatic relay board with RJ45
Moderator: leecollings
-
- Posts: 13
- Joined: Thursday 02 April 2015 18:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
SainSmart iMatic relay board with RJ45
Hi guys
Is there any way to control that board from Domoticz? (http://www.sainsmart.com/sainsmart-imat ... d-ios.html)
I bought it hoping it will allow HTTP GET requests but id doesn't
There are some clues about that relay board (8 channel but it's almost the same):
https://codecardinal.wordpress.com/2015 ... c-windows/
https://codecardinal.wordpress.com/2015 ... x-windows/
But I'm not a programmer and it doesn't tell me anything...
Is there any way to control that board from Domoticz? (http://www.sainsmart.com/sainsmart-imat ... d-ios.html)
I bought it hoping it will allow HTTP GET requests but id doesn't
There are some clues about that relay board (8 channel but it's almost the same):
https://codecardinal.wordpress.com/2015 ... c-windows/
https://codecardinal.wordpress.com/2015 ... x-windows/
But I'm not a programmer and it doesn't tell me anything...
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: SainSmart iMatic relay board with RJ45
First: welcome to this forum!
I think the Python script is perfectly usable with Domoticz.
Put the script on your Pi (domoticz folder > scripts).
Then create a virtual switch (create dummy hardware at Setup > Hardware), then go to 'Switches' tab and click on 'Manual switch'. Choose the dummy hardware from dropdown. Then fill in a name and choose on/off. Protocol doesn't matter because it is virtual.
Then when you have made the switch, click the 'Edit' button and at the 'On action', fill in something like this:
For the 'Off action' you fill in almost the same, but this time the off command:
(not sure if zero means off, but it probably does)
Hope you can get it working that way
Edit: Looked at the Python script again, but i think his blog messes up the code. The '&', '<' and ' " ' are replaced by HTML alternatives.
Try this version that i corrected:
relay.py
Be sure to change the IP to that of your board.
I think the Python script is perfectly usable with Domoticz.
Put the script on your Pi (domoticz folder > scripts).
Then create a virtual switch (create dummy hardware at Setup > Hardware), then go to 'Switches' tab and click on 'Manual switch'. Choose the dummy hardware from dropdown. Then fill in a name and choose on/off. Protocol doesn't matter because it is virtual.
Then when you have made the switch, click the 'Edit' button and at the 'On action', fill in something like this:
Code: Select all
script://path_to_script/relay.py 8 1
Code: Select all
script://path_to_script/relay.py 8 0
Hope you can get it working that way
Edit: Looked at the Python script again, but i think his blog messes up the code. The '&', '<' and ' " ' are replaced by HTML alternatives.
Try this version that i corrected:
relay.py
Code: Select all
from socket import *
import sys
if len(sys.argv) != 3:
sys.exit(2)
relay = str(sys.argv[1])
state = str(sys.argv[2])
data_send = "FD0220"
if int(relay) <= 8:
data_send += "0" + relay
if int(state) == 0:
data_send += "00"
elif int(state) == 1:
data_send += "01"
elif int(relay) == 9:
data_send += "F8"
if int(state) == 0:
data_send += "80"
elif int(state) == 1:
data_send += "88"
data_send += "5D"
s = socket(AF_INET, SOCK_STREAM)
s.connect(("192.168.1.4", 30000))
s.send(data_send.decode('hex'))
data = s.recv(4)
print(data.encode('hex'))
Last edited by ThinkPad on Thursday 02 April 2015 19:57, edited 3 times in total.
Reason: Added fixed script
Reason: Added fixed script
I am not active on this forum anymore.
-
- Posts: 13
- Joined: Thursday 02 April 2015 18:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: SainSmart iMatic relay board with RJ45
Thx for quick response! I'll check it right away:)
AND I'm sorry I did not greeted before Hi everyone!
AND I'm sorry I did not greeted before Hi everyone!
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: SainSmart iMatic relay board with RJ45
Haha it was not meant like: you didn't welcome yourself!
I saw this was your first post here, so i wanted to welcome you here
By the way i don't have this relay board, so can't help trying. Just translating/helping what i see on the (second) page you gave me.
I saw this was your first post here, so i wanted to welcome you here
By the way i don't have this relay board, so can't help trying. Just translating/helping what i see on the (second) page you gave me.
I am not active on this forum anymore.
-
- Posts: 13
- Joined: Thursday 02 April 2015 18:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: SainSmart iMatic relay board with RJ45
Ok... I realized, that I didn't have python @ my raspberry (I've got it now ) but when I'm trying to run that script error appears:
Code: Select all
pi@raspberrypi ~/domoticz/scripts $ sudo python relay.py 8 1
File "relay.py", line 1
Script started on czw, 2 kwi 2015, 20:25:47
^
SyntaxError: invalid syntax
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: SainSmart iMatic relay board with RJ45
Can't help you with that unfortunately. My coding skills are insufficient.
Maybe someone with better coding skills comes by and is able to help.
Maybe someone with better coding skills comes by and is able to help.
I am not active on this forum anymore.
-
- Posts: 13
- Joined: Thursday 02 April 2015 18:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: SainSmart iMatic relay board with RJ45
Thx a lot
Sth new appeared
Sth new appeared
Code: Select all
File "test.py", line 14
data_send += "00"
^
IndentationError: expected an indented block
-
- Posts: 13
- Joined: Thursday 02 April 2015 18:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: SainSmart iMatic relay board with RJ45
Ok it's alive ! I'll send details in the moment.
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: SainSmart iMatic relay board with RJ45
Nice, please share the script so someone else can benefit from it
I am not active on this forum anymore.
-
- Posts: 13
- Joined: Thursday 02 April 2015 18:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: SainSmart iMatic relay board with RJ45
Ok so mainly it was wrong some tabs and spaces...
I've added working one as attachment.
But I have another problem
When I'm using that in Domoticz it generates error:
It was Error 32256, but afer I've changed attributes of the script file to 755 (chmod +x file.py) it changed to error 512...
It works @ console without any problem.
I've added working one as attachment.
But I have another problem
When I'm using that in Domoticz it generates error:
Code: Select all
2015-04-02 22:43:59.154 Error: Error executing script command (/home/pi/domoticz/scripts/test.py). returned: 512
It works @ console without any problem.
- Attachments
-
- relay.zip
- (427 Bytes) Downloaded 310 times
-
- Posts: 13
- Joined: Thursday 02 April 2015 18:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: SainSmart iMatic relay board with RJ45
Ok, I think, that I've found a source of the problem. I assume that Domoticz runs python scripts @ Python 3. That script works only with Python 2. For a programmer it wont be a problem to fix it I hope that some of u can help?
When I'm trying to run that script @ Python 3, I get an error:
When I'm trying to run that script @ Python 3, I get an error:
Code: Select all
Traceback (most recent call last):
File "/home/pi/domoticz/scripts/test.py", line 29, in <module>
s.send(data_send.decode('hex'))
AttributeError: 'str' object has no attribute 'decode'
-
- Posts: 13
- Joined: Thursday 02 April 2015 18:50
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: SainSmart iMatic relay board with RJ45
Ok, I made it It's woring now. I'll post later to explain everything.
-
- Posts: 890
- Joined: Tuesday 30 September 2014 8:49
- Target OS: Linux
- Domoticz version: beta
- Location: The Netherlands
- Contact:
Re: SainSmart iMatic relay board with RJ45
Can you please explain how you got it working, and post the script here?
I think other users who maybe have/will buy the same board are interested in it!
I think other users who maybe have/will buy the same board are interested in it!
I am not active on this forum anymore.
-
- Posts: 1
- Joined: Wednesday 08 April 2015 16:33
- Target OS: -
- Domoticz version:
- Contact:
Re: SainSmart iMatic relay board with RJ45
Hi,
I'm the guy from the blog!
The code is indeed for Python =< v2.7
I have updated the blog with a new link to the code which has a more proper format, that fixes the indent and the html fuck ups.
In case someone needs this code for v3 and up, personal message me and I'll give it a try.
I'm the guy from the blog!
The code is indeed for Python =< v2.7
I have updated the blog with a new link to the code which has a more proper format, that fixes the indent and the html fuck ups.
In case someone needs this code for v3 and up, personal message me and I'll give it a try.
-
- Posts: 16
- Joined: Tuesday 23 February 2016 14:04
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: SainSmart iMatic relay board with RJ45
I have the "error 512" problem. Can anyone help me?
Re: SainSmart iMatic relay board with RJ45
Hi,
I'm going to buy Imatic relay with 8 relay onboard.
Can you confirm it will work with Domoticz?
Thank you.
I'm going to buy Imatic relay with 8 relay onboard.
Can you confirm it will work with Domoticz?
Thank you.
-
- Posts: 4
- Joined: Saturday 21 November 2015 4:21
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2.3530
- Location: San Francico, U.S.
- Contact:
Re: SainSmart iMatic relay board with RJ45
I was finally able to get the 16 relay module
I am not much of a coder but I was able to cobble together some working code from other sources. For some reason the code I found worked great running from SSH but when I tried to run it as an On/Off Action it wouldn't run. After a lot of trials I figured out that for some reason I could not pass two arguments through the On/Off action.(Probably just something I was doing wrong). So I simply made two python scripts one for On and one for Off
I also couldn't decipher their code but I was able to use it to make a list of the commands for on and off so my script uses a list instead of code to generate the on/off commands.
To use these put these in your:
/home/pi/domoticz/scripts/python folder
SSH into that folder and run
sudo chmod +x relayOn.py
sudo chmod +x relayOff.py
Create a Dummy Swith
Under On/Off Action point to the files like this, changing the argument to the relay number you want to control:
Not the most elegant code, but it works for me, I hope it works for others.
working with Domoticz. I am not much of a coder but I was able to cobble together some working code from other sources. For some reason the code I found worked great running from SSH but when I tried to run it as an On/Off Action it wouldn't run. After a lot of trials I figured out that for some reason I could not pass two arguments through the On/Off action.(Probably just something I was doing wrong). So I simply made two python scripts one for On and one for Off
I also couldn't decipher their code but I was able to use it to make a list of the commands for on and off so my script uses a list instead of code to generate the on/off commands.
To use these put these in your:
/home/pi/domoticz/scripts/python folder
SSH into that folder and run
sudo chmod +x relayOn.py
sudo chmod +x relayOff.py
Create a Dummy Swith
Under On/Off Action point to the files like this, changing the argument to the relay number you want to control:
Not the most elegant code, but it works for me, I hope it works for others.
Who is online
Users browsing this forum: No registered users and 1 guest