Thank you Joe - this pointed me to the desired direction
My code is maybe a little robust, but i'll share the results with you as well. Now I'm able to control this card with some different python scripts and am futureproof.
For statuses and writing these to variables:
- Code: Select all
# Script for getting statuses of ethernet Relay board
import urllib
# Input your data here:
BoardIP = '192.168.1.166'
User = 'admin'
Pass = '12345678'
RelayName = 'No1' # If you have more than 1 relay board
# Constants and global variables
SearchString2 = "img src"
Result = ''
variableOut = ''
Output = ''
a = 1
# Start extraction of data
urlReturned = urllib.urlopen('http://' + User + ':' + Pass + '@' + BoardIP + '/relay_en.cgi')
data_getStatuses = urlReturned.read()
for a in range(1, 9):
SearchString = 'saida' + str(a) + 'pluse'
ResultA = data_getStatuses[data_getStatuses.find(SearchString):data_getStatuses.find(SearchString)+150]
ResultB = ResultA[ResultA.find(SearchString2)+9:ResultA.find(SearchString2)+16]
if ResultB == "lighton":
Result = str(Result) + '1'
Output = "true"
else:
Result = str(Result) + '0'
Output = "false"
# Sending info to variables
variableOut = str(RelayName) + '_onStateRelay_' + str(a)
try:
var = indigo.variables[variableOut]
except:
indigo.variable.create(variableOut)
indigo.variable.updateValue(variableOut, Output)
# Relay states as list
# indigo.server.log(str(Result))
For changing single relay state:
- Code: Select all
# Script for setting status of ethernet Relay board one relay at a time
import requests
# Input your data here:
BoardIP = '192.168.1.166'
User = 'admin'
Pass = '12345678'
RelayNo = '1'
RelayCommand = 'on' # accepts on/off
# Constants and global variables
key1 = ''
value1 = ''
# Start execution of change
url = ('http://' + BoardIP + '/relay_en.cgi')
key1 = 'saida' + RelayNo + RelayCommand
value1 = RelayCommand
payload = {key1: value1}
r = requests.post(url, auth=(User, Pass), data=payload)
For changing relay states by list:
- Code: Select all
# Script for setting status of ethernet Relay board relay's by list
import requests
# Input your data here:
BoardIP = '192.168.1.166'
User = 'admin'
Pass = '12345678'
RelayList = '00000000' # 1- true, 0 - false, any other character - ignore, 1st relay is 1st position in list
# Constants and global variables
key1 = ''
value1 = ''
a = 1
state = ''
RelayCommand = ''
# Start execution of change
url = ('http://' + BoardIP + '/relay_en.cgi')
for a in range(0,8):
state = RelayList[a]
if state == '1':
RelayCommand = 'on'
if state == '0':
RelayCommand = 'off'
if state <> '1' and state <> '0':
RelayCommand = ''
key1 = 'saida' + str(a+1) + RelayCommand
value1 = RelayCommand
payload = {key1: value1}
r = requests.post(url, auth=(User, Pass), data=payload)