Hello,
Just installed OpenHAB 2.2 TO test out the compatibility with two pcs DaenetIP3,
I got from them a very basic code and showing how to control the bords with openHAB.
I went medieval on the code as i know nothing about the code for this,
When i was youger starder career as programer but live game le lemons so went wet lemonade
To make the long storry short
The scenario is like I have Digital and Analog INPUTS that can control the DIGITAL OUTPUTS (relays)
But over that i wanna control the Digital Outputs from openHAB, and still see the status from them,
The boards have custom firmware that will allow Digital and Analog Inputs, and Also control thru http requests.
the issue is that the command are like INVERTING SIGNAL one pus on DI will turn on Relay, second Push will turn OFF, same with http request h***/192.168.1.12/command.html?P=admin&AS0=1& will tur ON if relays was OFF nad turn OFF if it was turned ON.
I want to make a switch on my very basic UI, that will turn on or off the relays:
the issue is that i have to check if relay is on or off and depending on status i have to send command or not:
like this i send command to relay0 h***/192.168.1.12/command.html?P=admin&AS0=1& (ON or OFF)
like this i get status h***/192.168.1.12/command.html?P=admin&AS0=?& (0-is OFF, 1 is ON)
As a short instroduction the orifinal files look like this:
items:
//CurrentState receives whole XML without change
String CurrentState "" {
http="<[h***/88.87.18.249:6767/command.html?P=admin&AS0=?&CV0=?&BV0=?&:3000:REGEX((.*))]"
}
String DI ""
String AI ""
Switch DO "DO" {
http=">[ON:GET:h***/88.87.18.249:6767/command.html?P=admin&AS0=1&] >[OFF:GET:h***/88.87.18.249:6767/command.html?P=admin&AS0=0&]"
}
rules:
// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.eclipse.smarthome.model.sitemap.*
rule "CurrentStateXML"
when
Item CurrentState received update
then
var int as0startpos = CurrentState.state.toString.indexOf("AS0=")
var int as0endpos = CurrentState.state.toString.indexOf(";", as0startpos)
var String as0 = CurrentState.state.toString.substring(as0startpos+"AS0=".length, as0endpos)
if(as0 == "1")
DO.postUpdate(ON)
else
DO.postUpdate(OFF)
var int bv0startpos = CurrentState.state.toString.indexOf("BV0=")
var int bv0endpos = CurrentState.state.toString.indexOf(";", bv0startpos)
var String bv0 = CurrentState.state.toString.substring(bv0startpos+"BV0=".length, bv0endpos)
DI.postUpdate(bv0.toString)
var int cv0startpos = CurrentState.state.toString.indexOf("CV0=")
var int cv0endpos = CurrentState.state.toString.indexOf(";", cv0startpos)
var String cv0 = CurrentState.state.toString.substring(cv0startpos+"CV0=".length, cv0endpos)
AI.postUpdate(cv0.toString)
end
sitemap:
sitemap daenetip3 label="DAEnetIP3" {
Frame label="Digital Input PortB.0" {
Text item=DI label="State: [MAP(daenetip3.map):%s]" icon="digital_in"
}
Frame label="Analog Input PortC.0" {
Text item=AI label="Value: [%s]" icon="analog_in"
}
Frame label="Digital Output PortA.0" {
Switch item=DO label="State" icon="light"
}
}
The board has 12 Relay / Board
IP for boards are : .11 and .12
Example of code i writen to control succesfully al 24 relays on the two Boards looks like this:
sitemap
sitemap DaenetIP3 label="IP3" {
Frame label="100" {
Switch item=D1O00 label="100" icon="light"
Switch item=D1O01 label="101" icon="light"
Switch item=D1O02 label="102" icon="light"
Switch item=D1O03 label="103" icon="light"
Switch item=D1O04 label="104" icon="light"
Switch item=D1O05 label="105" icon="light"
Switch item=D1O06 label="106" icon="light"
Switch item=D1O07 label="107" icon="light"
Switch item=D1O08 label="108" icon="light"
Switch item=D1O09 label="109" icon="light"
Switch item=D1O10 label="110" icon="light"
Switch item=D1O11 label="111" icon="light"
}
Frame label="200" {
Switch item=D2O00 label="200" icon="light"
Switch item=D2O01 label="201" icon="light"
Switch item=D2O02 label="202" icon="light"
Switch item=D2O03 label="203" icon="light"
Switch item=D2O04 label="204" icon="light"
Switch item=D2O05 label="205" icon="light"
Switch item=D2O06 label="206" icon="light"
Switch item=D2O07 label="207" icon="light"
Switch item=D2O08 label="208" icon="light"
Switch item=D2O09 label="209" icon="light"
Switch item=D2O10 label="210" icon="light"
Switch item=D2O11 label="211" icon="light"
}
}
rules: will not put all of them - i told you is medieval:
// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.eclipse.smarthome.model.sitemap.*
rule "CurrentState100"
when
Item CurrentState100 received update
then
var int as1startpos = CurrentState100.state.toString.indexOf("AS0=")
var int as1endpos = CurrentState100.state.toString.indexOf(";", as1startpos)
var String as1 = CurrentState100.state.toString.substring(as1startpos+"AS0=".length, as1endpos)
if(as1 == "1")
D1O00.postUpdate(ON)
else
D1O00.postUpdate(OFF)
end
rule "CurrentState101"
when
Item CurrentState101 received update
then
var int as1startpos = CurrentState101.state.toString.indexOf("AS1=")
var int as1endpos = CurrentState101.state.toString.indexOf(";", as1startpos)
var String as1 = CurrentState101.state.toString.substring(as1startpos+"AS1=".length, as1endpos)
if(as1 == "1")
D1O01.postUpdate(ON)
else
D1O01.postUpdate(OFF)
end
And items:
//CurrentState receives whole XML without change
String CurrentState100 "" { http="<[h***/192.168.1.11/command.html?P=admin&AS0=?&:3000:REGEX((.*))]" }
String CurrentState101 "" { http="<[h***/192.168.1.11/command.html?P=admin&AS1=?&:3000:REGEX((.*))]" }
String CurrentState102 "" { http="<[h***/192.168.1.11/command.html?P=admin&AS2=?&:3000:REGEX((.*))]" }
String CurrentState103 "" { http="<[h***/192.168.1.11/command.html?P=admin&AS3=?&:3000:REGEX((.*))]" }
String CurrentState104 "" { http="<[h***/192.168.1.11/command.html?P=admin&AS4=?&:3000:REGEX((.*))]" }
String CurrentState105 "" { http="<[h***/192.168.1.11/command.html?P=admin&AS5=?&:3000:REGEX((.*))]" }
String CurrentState106 "" { http="<[h***/192.168.1.11/command.html?P=admin&AS6=?&:3000:REGEX((.*))]" }
String CurrentState107 "" { http="<[h***/192.168.1.11/command.html?P=admin&AS7=?&:3000:REGEX((.*))]" }
String CurrentState108 "" { http="<[h***/192.168.1.11/command.html?P=admin&AS8=?&:3000:REGEX((.*))]" }
String CurrentState109 "" { http="<[h***/192.168.1.11/command.html?P=admin&AS9=?&:3000:REGEX((.*))]" }
String CurrentState110 "" { http="<[h***/192.168.1.11/command.html?P=admin&ASA=?&:3000:REGEX((.*))]" }
String CurrentState111 "" { http="<[h***/192.168.1.11/command.html?P=admin&ASB=?&:3000:REGEX((.*))]" }
String CurrentState200 "" { http="<[h***/192.168.1.12/command.html?P=admin&AS0=?&:3000:REGEX((.*))]" }
String CurrentState201 "" { http="<[h***/192.168.1.12/command.html?P=admin&AS1=?&:3000:REGEX((.*))]" }
String CurrentState202 "" { http="<[h***/192.168.1.12/command.html?P=admin&AS2=?&:3000:REGEX((.*))]" }
String CurrentState203 "" { http="<[h***/192.168.1.12/command.html?P=admin&AS3=?&:3000:REGEX((.*))]" }
String CurrentState204 "" { http="<[h***/192.168.1.12/command.html?P=admin&AS4=?&:3000:REGEX((.*))]" }
String CurrentState205 "" { http="<[h***/192.168.1.12/command.html?P=admin&AS5=?&:3000:REGEX((.*))]" }
String CurrentState206 "" { http="<[h***/192.168.1.12/command.html?P=admin&AS6=?&:3000:REGEX((.*))]" }
String CurrentState207 "" { http="<[h***/192.168.1.12/command.html?P=admin&AS7=?&:3000:REGEX((.*))]" }
String CurrentState208 "" { http="<[h***/192.168.1.12/command.html?P=admin&AS8=?&:3000:REGEX((.*))]" }
String CurrentState209 "" { http="<[h***/192.168.1.12/command.html?P=admin&AS9=?&:3000:REGEX((.*))]" }
String CurrentState210 "" { http="<[h***/192.168.1.12/command.html?P=admin&ASA=?&:3000:REGEX((.*))]" }
String CurrentState211 "" { http="<[h***/192.168.1.12/command.html?P=admin&ASB=?&:3000:REGEX((.*))]" }
Switch D1O00 "D1O00" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&AS0=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&AS0=1&]" }
Switch D1O01 "D1O01" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&AS1=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&AS1=1&]" }
Switch D1O02 "D1O02" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&AS2=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&AS2=1&]" }
Switch D1O03 "D1O03" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&AS3=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&AS3=1&]" }
Switch D1O04 "D1O04" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&AS4=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&AS4=1&]" }
Switch D1O05 "D1O05" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&AS5=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&AS5=1&]" }
Switch D1O06 "D1O06" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&AS6=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&AS6=1&]" }
Switch D1O07 "D1O07" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&AS7=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&AS7=1&]" }
Switch D1O08 "D1O08" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&AS8=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&AS8=1&]" }
Switch D1O09 "D1O09" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&AS9=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&AS9=1&]" }
Switch D1O10 "D1O10" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&ASA=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&ASA=1&]" }
Switch D1O11 "D1O11" { http=">[ON:GET:h***/192.168.1.11/command.html?P=admin&ASB=1&] >[OFF:GET:h***/192.168.1.11/command.html?P=admin&ASB=1&]" }
Switch D2O00 "D2O00" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&AS0=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&AS0=1&]" }
Switch D2O01 "D2O01" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&AS1=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&AS1=1&]" }
Switch D2O02 "D2O02" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&AS2=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&AS2=1&]" }
Switch D2O03 "D2O03" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&AS3=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&AS3=1&]" }
Switch D2O04 "D2O04" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&AS4=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&AS4=1&]" }
Switch D2O05 "D2O05" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&AS5=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&AS5=1&]" }
Switch D2O06 "D2O06" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&AS6=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&AS6=1&]" }
Switch D2O07 "D2O07" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&AS7=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&AS7=1&]" }
Switch D2O08 "D2O08" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&AS8=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&AS8=1&]" }
Switch D2O09 "D2O09" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&AS9=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&AS9=1&]" }
Switch D2O10 "D2O10" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&ASA=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&ASA=1&]" }
Switch D2O11 "D2O11" { http=">[ON:GET:h***/192.168.1.12/command.html?P=admin&ASB=1&] >[OFF:GET:h***/192.168.1.12/command.html?P=admin&ASB=1&]" }