It’s almost compete. I hope to have a working version of a beta release at the weekend.
For now here is an almost compete version in which you can actually configure your setup!!
You need a thing channel and a rule;
- id: nxpanel_command
channelTypeUID: mqtt:string
label: NxPanel Command
description: ""
configuration:
commandTopic: cmnd/nspanel/nxpanel
- id: nxpanel_page_trigger
channelTypeUID: mqtt:trigger
label: NxPanel Page Trigger
description: ""
configuration:
stateTopic: tele/nspanel/RESULT
import org.slf4j.LoggerFactory
def logger = LoggerFactory.getLogger("org.openhab.core.automation.nspanel")
/*
* Utility functions
*/
def makeButton(bid,label,type,icon=null,state=null,next=null) {
var str = ""<<((bid==1)?"":",")
str<<'{"bid":'<<bid<<',"label":"'<<label<<'","type":'<<type
if (next!=null) {
str<<',"next":'<<next
}
if (state!=null) {
str<<',"state":'<<state
}
if (icon!=null) {
str<<',"icon":'<<icon
}
str<<'}'
return str
}
def makePage(pid,name,format) {
var str = new StringBuilder('{"refresh":')
str<<'{"pid":'<<pid<<',"name":"'<<name<<'","format":'<<format<<',buttons:['
return str
}
def str = event.getEvent()
if (str.indexOf('{"page":')!=0) {
logger.info("ignore: "+str)
return
}
/*
* Get data from the page message
* (would be good to use JsonSluper here but currently can't access)
*/
var i = str.indexOf("\"id\"")
var i2 = str.indexOf(",",i+6)
var id = str.substring(i+6,i2)
i = str.indexOf("\"format\"")
i2 = str.indexOf(",",i+10)
var format = str.substring(i+10,i2)
// check if a full refresh or just a status update
var refresh = str.indexOf("refresh")>0
var json
switch (id) {
/*
* MakePage has these params;
* pid - you unique id for the page (max 99)
* name - 25 chars of description
* format - The style of page (will be set from what calls it, but this is to validate)
* 1 - home
* 2 - 2 buttons
* 3 - 3 buttons
* 4 - 4 buttons
* 5 - 6 buttons
* 6 - 8 buttons
* 7 - dimmer Brightness
* 8 - dimmer Color
* 9 - Thermostat
* 10 - Alert 1
* 11 - Alert 2
* 12 - Alarm
* 13 - Media Player
* 14 - Media Playlist
* 15 - Status Panel
*
* 10 is the root button page from the home screen
* it's set to be an 8 button panel for now, but you'll be able to change
*
* MakeButton has these params;
* bid - number of button (1-8), keep in correct order, can leave blank
* label - the label under the button (8 chars max)
* type:
* 0 - Unused
* 1 - Toggle
* 2 - Push
* 3 - Dimmer (press on/off, long press for advanced)
* 4 - Dimmer RGB (press on/off, long press for advanced)
* 10 - Page Link
* icon: (can add more on request!)
* 0 - Blank
* 1 - Bulb
* 2 - Dimmer 1
* 3 - Dimmer 2
* 4 - Vaccum
* 5 - Bed
* 6 - House
* 7 - Sofa
* 8 - Bell
* 9 - Heat
* 10 - Curtains
* 11 - Music
* 12 - Binary
* state - button 0=off, 1=on (for toggles), or page format for links (type 10)
* next - id of next page from the section below
*
*/
case "10" :
movie = ir.getItem("movie_room_lights").state==ON?1:0
if (refresh) {
json = makePage(10,'Lounge',format)
json<<makeButton(1,"Movie",1,1,movie)
json<<makeButton(2,"Cabin",1,1,0)
json<<makeButton(3,"Hall",2,6)
json<<makeButton(4,"Bedroom",10,5,5,11)
json<<makeButton(5,"Temp",10,9,9,12)
json<<makeButton(6,"Light",1,3)
json<<"]}}"
print json
print json.length()
events.sendCommand("nxpanel_command",json.toString())
}
break
case "11" :
if (refresh) {
json = makePage(10,'Hall',format)
json<<makeButton(1,"A",1,4)
json<<makeButton(2,"B",1,5)
json<<makeButton(3,"C",1,6)
json<<makeButton(4,"D",2,7)
json<<makeButton(5,"E",2,8)
json<<makeButton(6,"F",2,9)
json<<"]}}"
print json
print json.length()
events.sendCommand("nxpanel_command",json.toString())
}
break
case "12" :
if (refresh) {
// TODO
}
break
}
The above is just a little 2 page example to get the idea.
Make sure you are on latest nxpanel.be & nxpanel.tft
How do you think that is?