Seeing a strange issue, buttons on 3 button page toggling the wrong button, select button 2 and button 3 turns on/off, select button 3 turns button 3 on/off. Button 1 works as expected. See behaviour after power cycle. On v1.0.0-beta1 of nxpanel.be and beta6 of the TFT. MQTT shows the following after power cycle when I swipe to page 10, select the first button and then tap button1, button2 and button3.
{“page”: {“format”: 6, “pid”: 10, “type”: “refresh”}}
{“refresh”:{“pid”:10,“name”:“Family Room”,“format”:6,buttons:[6,buttons:[{“bid”:1,“label”:“Heat”,“type”:10,“next”:11,“state”:3,“icon”:9}]}}
{“NxPanel”:“Done”}
{“page”: {“format”: 3, “pid”: 11, “type”: “refresh”}}
{“refresh”:{“pid”:11,“name”:“Hot Water”,“format”:3,buttons:[{“bid”:1,“label”:“1 Hour”,“type”:1,“icon”:14},{“bid”:2,“label”:“1.5 Hours”,“type”:1,“icon”:14},{“bid”:3,“label”:“2 Hours”,“type”:1,“icon”:14}]}}
{“NxPanel”:“Done”}
{“button”: {“pid”: 11, “bid”: 1, “state”: 1, “next”: 0}} UU
{“button”: {“pid”: 11, “bid”: 3, “state”: 1, “next”: 0}} UU
{“button”: {“pid”: 11, “bid”: 3, “state”: 0, “next”: 0}} UU
Script for page refresh attached.
import org.slf4j.LoggerFactory
def logger = LoggerFactory.getLogger("org.openhab.core.automation.nspanel")
/*
* YOU ONLY NEED TO EDIT THE SWICH PART BELOW
*/
/*
* 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("\"pid\"")
var i2 = str.indexOf(",",i+7)
var id = str.substring(i+7,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
* 13 - Fan
* 14 - Switch
* 15 - Talk
* state - button 0=off, 1=on (for toggles), or page format for links (type 10)
* next - id of next page from the section below
*
*/
/*
* EDIT BELOW HERE TO SET UP YOUR ROOMS
* 10 is the default start page, when your right swipe the home screen.
*/
// ensure you have a sync and a refresh for each, even if sync is empty.
case "10" :
movie = ir.getItem("MagicHome_1").state==ON?1:0
json = makePage(id,'Family Room',format)
json<<format<<',buttons:['
json<<makeButton(1,"Heat",10,9,3,11)
json<<"]}}"
events.sendCommand("nxpanel_command",json.toString())
break
case "11" :
// if (refresh) {
json = makePage(id,'Hot Water',format)
json<<makeButton(1,"1 Hour",1,14)
json<<makeButton(2,"1.5 Hours",1,14)
json<<makeButton(3,"2 Hours",1,14)
json<<"]}}"
// } else {
// json = '{ "sync": {} }'
// }
events.sendCommand("nxpanel_command",json.toString())
break
}