NxPanel - Replacement Firmware for Sonoff NSPanel

There should be a percentage bar on the display. it goes up at a steady speed, when 100% the unit will auto reboot.

I’ve never know it stop. but it’s possible if there were any serial issues. I would just try again. what is the last % it got to?

Major Update Coming Soon…

Install process for a new device will be;

  • Flash Tasmota
  • Copy nxpanel.be
  • InstallNxPanel (in tasmota console)

That’s it!

To install a new version you will need to do this;

  • Nothing.

It will auto update to current version itself if you enable it in settings.

Complete!

3 Likes

I have a strange problem with setting the button on OH
I see a change of state of the button
But when I refresh the unit I do not see the situation change
Although I see the command in OH

`

  • id: NXPanel_B1
    channelTypeUID: mqtt:switch
    label: NXPanelB1
    description: null
    configuration:
    stateTopic: tele/tasmota_7DDCCC/RESULT
    transformationPattern: JSONPATH:$.button.[?(@.pid==“10”)].[?(@.bid==“1”)].state
    off: “0”
    on: “1”

`

GenericMQTTThing_NxPanelCommand’ predicted to become {“sync”:{“pid”:10,buttons:[{“bid”:1,“state”:0}]}}

what are you seeing in the tasmota log on the panel, when this happens?
If it’s sending to the Nextion;

{“sync”:{“pid”:10,buttons:[{“bid”:1,“state”:0}]}}

I would expect that to turn button 1 off on that page, if the page was showing.

If you are talking about moving to the page after you’ve sent the message. Then you should be sending that state again, either in the refresh or sync message, you send in response to the page message you are sent as the page is made active.

This process seems to work fine for me.

Mapping an NxPanel event directly to the item, without Rules

This is very nice way to get the item updated directly from the mtqq messge without using a rule to map it? :slight_smile: I like that. It’s definitely worth bringing to the attention of other users!

Thank you @jonny211

Do you need to add a regex at the start to stop spam error messaged in logs? I had to do that for other RF item events. Maybe yours is a more sophisticated regex and works better.

Major Update

  • Direct TFT uploads, no Java conversion needed any more.
  • Auto updates, no need to manually flash at all.

Make sure your Tasmota is latest version with the tcpclient bug fix.

Install the current nxpanel.be file.

In the tasmota console type;

installnxpanel

That’s it. It should install the latest version. Moreover, if you enable auto update in the config page, it will keep on the latest version without you needing to do anything. It will do version check every day or so currently. You can force a version check by entering 9998 in alarm and red button. 9999, will reboot.

You can still flash manually if you prefer;

flashnextion http://www.whatever.com/nspanel.tft

Enable test auto update if you want the current ones until a stable release is made.

1 Like

Can someone explain this rule to me?

import org.slf4j.LoggerFactory

def logger = LoggerFactory.getLogger(“org.openhab.core.automation.nspanel”)

def str = event.getEvent()
if (str.indexOf('{“button”: ')!=0) {
return
}

// {“button”: {“pid”: 15, “bid”: 1, “state”: 1, “next”: 0}}

var i = str.indexOf(“"pid"”)
var i2 = str.indexOf(“,”,i+7)
var pid = str.substring(i+7,i2) as int
i = str.indexOf(“"bid"”)
i2 = str.indexOf(“,”,i+7)
var bid = str.substring(i+7,i2) as int
i = str.indexOf(“"state"”)
i2 = str.indexOf(“,”,i+9)
var state = str.substring(i+9,i2) as int

if (pid==10 && bid==1) {
events.sendCommand(“my_room_light”,state==1?“ON”:“OFF”)
}
else if (pid==10 && bid==2) {
//
}

I’m getting this error message

2022-02-13 22:20:39.666 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘5f3b7c9005’ failed: javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: org.openhab.core.items.events.ItemStateChangedEvent.getEvent() is applicable for argument types: () values:
Possible solutions: getAt(java.lang.String), getClass(), getTopic(), getType(), every()

I think you added the rule to the wrong thing. It’s not the item, it’s the channel you add it to directly. it’s trying to call method of the event, as thought it was a channel event. since you are triggering it off an item, it’s an item event. and that does not have the same methods which the rule is expecting.

This is my trigger for that rule

Hi Mike,

with Major Update the flash process is workig, for whatever reason, thanks!

I understand. And the software can do it. I still struggle with the syntax in mqtt, though.
I´d be happy if you could create a simple example fo the status screen as JSON payload. From there I can adjust it to my needs.
I am confused by (favorite, status, refresh, etc)

 mosquitto_pub -t "cmnd/nspanel/nxpanel" -m '{"refresh":{"pid":17,"name":"Info Page","status":[{"id":1,"text":"Door","value":"Open"},{"id":2,"text":"Temp","value":"4","icon":3}]}}'

I am confused as well :frowning:

A guide to how it works

Can you confirm a few things first.

Do you have a working rule that will return your button page for the first button screen “10”?

Refresh Event

As soon as you swipe from home, nxpanel will send;

{"page": {"format": 6, "pid": 10, "type": "refresh"}}

meaning, tell me how to draw a “8 Button Screen” (type 6) for that page with id 10.

Your rule (as described above in this thread) should then send the reply refresh message to tell nxpanel how to render the button page, such as;

{"refresh":{"pid":10,"name":"Lounge","format":6,buttons:[{"bid":1,"label":"Movie","type":1,"state":1,"icon":1},{"bid":2,"label":"Lounge","type":1,"state":0,"icon":1},{"bid":3,"label":"Hall","type":2,"icon":6},{"bid":4,"label":"Bedroom","type":10,"next":11,"state":5,"icon":5},{"bid":5,"label":"Temp","type":10,"next":12,"state":9,"icon":9},{"bid":6,"label":"Light","type":1,"icon":3},{"bid":7,"label":"Dimmer","type":10,"next":13,"state":8,"icon":3},{"bid":8,"label":"Status","type":10,"next":17,"state":15,"icon":16}]}}

At this point, you button screen should look fine.

Please confirm you get this far?

You should be clear on how this fundamental process works before continuing.

@Jens_Wensing asked about the status page. In the above example my button 8 links to the status page.

{"bid":8,"label":"Status","type":10,"next":17,"state":15,"icon":16}

This says;

  • type: 10, the button is a link to another screen
  • next:17, the page it links to has an id of 17
  • icon: 16, use the information icon on the label
  • state: 15, this is the page type, 15 is the status page

So, when you press this button, if will open the status page for id 17, this again (just like the button page) will make nxpanel send another request how to render that page;

{"page": {"format": 15, "pid": 17, "type": "refresh"}}

It’s asking you backend how to draw the status page for id 17. It’s send the 15 (status page), but it’s more for reference and not needed. You should know your id 17 is a status page and send appropriate json for that, without being told the 15.

Your rule, once again, will be passed in the 17 so it knows what to do, since 17 is a status page your rule will send back the json for that page, which will be something like this;

{"refresh":{"pid":17,"name":"Info Page","status":[{"id":1,"text":"Door","value":"Open"},{"id":2,"text":"Temp","value":"4","icon":3}]}}

This is the process for all pages.

  • You move to a page
  • NxPanel sends the page id request over mqtt
  • You backend rule get the message, via a rule listening to the channel
  • Based on the page id, the rule returns the json needed for that specific page to render

Sync event

The below, is for perfomance, you should do it. But make sure you fully understand the above first.

The only slight deviation from that process is the sync event. This is to make things faster. If you move to a screen (button screen) and that screen was last used to render page id (10, for example) and you want the button screen rendered as 10 again. It know that all the labels and icons are correct, so it doesnt need to ask the backend how to refresh the whole page. So instead of send a;

{"page": {"format": 6, "pid": 10, "type": "refresh"}}

It will send a

{"page": {"format": 6, "pid": 10, "type": "sync"}}

This means your backend doesn’t need to send everything about the page. The only things that would be visually different could be the on/off states of the button, so that’s all you’d need to send;

{"sync":{"pid":10,buttons:[{"bid":1,"state":1},{"bid":2,"state":0}]}}

This makes the page faster to sync. You could have just send a refresh like first time. That would have worked. But a sync will make it faster. You can only do this for the button pages as I assumed this would be the important pages. All other pages will never send a ‘sync’ they will always send a refresh so you will send a full refresh back.

3 Likes

Thank you.
Based on that information I will try to setup the first page.
Great job from your side!

For those not aware. There is a great command line tool which lets you send mqtt on the fly. It’s very handy when testing things out before you have your rules 100%

 mosquitto_pub -t "cmnd/nspanel/nxpanel" -m '{"refresh":{"pid":17,"name":"Info Page","status":[{"id":1,"text":"Door","value":"Open"},{"id":2,"text":"Temp","value":"4","icon":3}]}}'

It lets you send commands nice and easy. If the status page was active as pid 17, the above would set the display on it.

Linking switches on the NxPanel to OH items without rules

This works great!

Create a new channel on your NSPanel like this;

  - id: nxpanel_movie_light
    channelTypeUID: mqtt:switch
    label: Movie Light - 10:1
    description: ""
    configuration:
      postCommand: true
      formatBeforePublish: '{"sync":{"pid":10,"bid":1,"state":%s}}'
      commandTopic: cmnd/nspanel/nxpanel
      transformationPattern: 'REGEX:(.*\"pid\": 10.*\"bid\": 1.*)∩JSONPATH:$.button.state'
      stateTopic: tele/nspanel/RESULT
      off: "0"
      on: "1"

Then, instead of creating a new item for it, just link it to the existing item used for the switch. They are now both in sync and work perfectly. Thanks to @jonny211 for pointing me in right direction for the nice solution! :slight_smile:

UPDATE 1: The above meoth does not work 100% for me yet. Still needs some investigating. I works great from a UI perspective, both OH item and NSPanel button control the the light perfecty, changing either keeps the other in sync. The issue is using the phyical switch, it does not push the state back right, see here for more details! :confused:

UPDATE 2: Sorted! With some excellent support from @rossko57. Create your NxPanel channel as described above. Add this channel to your existing switch item, ensuring you use the follow profile. The key points in making this work are; 1 - Using follow on NxPanel channel and, 2 - Setting Is Command on the channel too!

1 Like

The rule for sync two itme and work for me

rule “sync lights”
when
Item lamp_A changed or
Item lamp_B changed
then
if(lamp_A.state != newState) lamp_A.sendCommand(newState.toString)
if(lamp_B.state != newState) lamp_B.sendCommand(newState.toString)
end

glad it’s working for this :slight_smile: I find in OH there is often many ways to do the same thing, and it’s not always clear which is the best!

Version 1.0.1

This is the first release after the improved upgrade flashing was added, so the first test it works!! :slight_smile: No bugs please! lol

It will auto do it within 24hrs for those that have enabled auto updates and testing ones. You can force the update by typing 9998 Red, in any alarm page, or by typing autoflash in the tasmota console.

Feedback on how it worked, good or bad, would be nice.

The main change in this version is a fix to a long standing, but hard to track down , bug where some messages would get lost and an error appeared in console.

It’s getting very close to what I would say is a stable release now.

I will try and do some proper documentation after that.

How are people getting on in general? I appreciate it has been harder to set up without full documentation and during development.

I changed the .be file and now I can not sync the unit with OH
I get {“Command”:“Unknown”} in the console of tasmota