DaenetIP3 - Basic UI - Master LIGHT Switch ON / OFF

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 :slight_smile:
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***/ 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***/ (ON or OFF)
like this i get status h***/ (0-is OFF, 1 is ON)

As a short instroduction the orifinal files look like this:


//CurrentState receives whole XML without change
String CurrentState "" {

String DI ""
String AI ""
Switch DO "DO" { 
	http=">[ON:GET:h***/]	>[OFF:GET:h***/]" 


// 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"
	Item CurrentState received update
	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")
	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)
	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)


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 :slight_smile:

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"
	Item CurrentState100 received update
	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")

rule "CurrentState101"
	Item CurrentState101 received update
	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")

And items:

//CurrentState receives whole XML without change

String CurrentState100 "" { http="<[h***/*))]" }
String CurrentState101 "" { http="<[h***/*))]" }
String CurrentState102 "" { http="<[h***/*))]" }
String CurrentState103 "" { http="<[h***/*))]" }
String CurrentState104 "" { http="<[h***/*))]" }
String CurrentState105 "" { http="<[h***/*))]" }
String CurrentState106 "" { http="<[h***/*))]" }
String CurrentState107 "" { http="<[h***/*))]" }
String CurrentState108 "" { http="<[h***/*))]" }
String CurrentState109 "" { http="<[h***/*))]" }
String CurrentState110 "" { http="<[h***/*))]" }
String CurrentState111 "" { http="<[h***/*))]" }
String CurrentState200 "" { http="<[h***/*))]" }
String CurrentState201 "" { http="<[h***/*))]" }
String CurrentState202 "" { http="<[h***/*))]" }
String CurrentState203 "" { http="<[h***/*))]" }
String CurrentState204 "" { http="<[h***/*))]" }
String CurrentState205 "" { http="<[h***/*))]" }
String CurrentState206 "" { http="<[h***/*))]" }
String CurrentState207 "" { http="<[h***/*))]" }
String CurrentState208 "" { http="<[h***/*))]" }
String CurrentState209 "" { http="<[h***/*))]" }
String CurrentState210 "" { http="<[h***/*))]" }
String CurrentState211 "" { http="<[h***/*))]" }

Switch D1O00 "D1O00" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O01 "D1O01" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O02 "D1O02" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O03 "D1O03" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O04 "D1O04" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O05 "D1O05" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O06 "D1O06" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O07 "D1O07" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O08 "D1O08" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O09 "D1O09" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O10 "D1O10" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D1O11 "D1O11" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O00 "D2O00" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O01 "D2O01" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O02 "D2O02" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O03 "D2O03" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O04 "D2O04" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O05 "D2O05" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O06 "D2O06" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O07 "D2O07" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O08 "D2O08" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O09 "D2O09" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O10 "D2O10" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }
Switch D2O11 "D2O11" { http=">[ON:GET:h***/]	>[OFF:GET:h***/]"  }

  • On OH 2.2 you no longer need to nor should you import anything from org.openhab or org.eclipse.smarthome. The org.openhab.core packages no longer exist and all of the classes that you need that used to be there are imported automatically for you.

  • You should not import using *. You should import only those classes you use by name.

  • CurrentStateXML looks OK, though if the data is really XML then it might be more straight forward to use the XPath transform. You can move the CurrentState http request to a caching config (see https://docs.openhab.org/addons/bindings/http1/readme.html#example-of-how-to-configure-an-http-cache-item) and then you can populate DI and AI and DO without the Rule.