Sonoff NSPanel by ITead - Smart Scene Wall Switch based on ESP32 and custom Nextion Touch Screen Panel Display (non-Pro variant)

This is amazing! I’d love to see someone configuring it as an external alarm code panel for HA. Like he did with a Pi Zero a couple of years ago: DIY Alarm Control Panel for Home Assistant - Hackster.io

Unfortunately it would exceed my technical skills by far to investigate on my own.

Hi,

I wanted to share my further work on the same code I shared earlier. In addition to the home screen with temperature and weather widget and the music page, I have added the following:

  • When the device boots up, it shows a HA logo on the screen. When the ESP has connected to WiFi, the IP is printed (to easier add device to HA if not yet added and to make troubleshooting easier). When the screen is fully set up from HA, all elements are allowed to populate the global elements on the screen during a short delay period. That way the home screen is ready when it is showed. Before adding this functionality, the Home screen appeared but with no data for a certain amount of time. I also delayed all elements to wait for the screen being ready before populating it to prevent empty positions (when items are populated on the screen before the screen is ready).
  • On the right side, there is now a page to control 8 lights. Six different light types are available with both on and off state. Both the state and the lights name are pulled from HA automatically.
  • I added a page to be used when the alarm is turned on. This page shows an armed symbol and prevents the screen from being used. I think it is a more elegant feature than just turning the display off. :slight_smile:
  • Notifications can be sent from HA to the display. The NSPanel plays a tone and displays the notification.

Code, HMI file and HMI project file

9 Likes

@marcfager - wanted to highlight two really smart features you have.

    # Service to control the visible page from Home Assistant
    - service: set_page
      variables:
        page: int
      then:
        - lambda: id(disp1).send_command_printf("page %i", page);

Very neat idea!

    # Service to send a command directly to the display. Useful for testing
    - service: send_command
      variables:
        cmd: string
      then:
        - lambda: 'id(disp1).send_command_printf("%s", cmd.c_str());'

This will be very handy, no more compiling and uploading to test!

[edit] do you have an example of what the cmd string might look like. Only had time to test the contents of a send method but those didn’t work. Need more experimenting.

[editx2] ok so sending commands to the display require Nextion instructions.

Eg. page0.bright.pic=1

Self imposed constraint?

I don’t know C++, merely copy/paste yaml, and I bumble my way through. On Sunday I wasted six hours banging my head against a wall!

Give it a go, start with what others have done. But not all at once. Try each little section to gain understanding and confidence.

You can do it mate.

Thank you! but the credit for the second one goes to @masto - I copied it from his example on GitHub :blush:

haha, nice one. And this how I do it everyday. Sometimes it works and sometimes it needs some more time. I’ll have to order one of these devices.

1 Like

Love the various new HMI GUIs . Some great looking ones. As I have zero design skills I’ve gone another path. I’m using the stock HMI with ESPHome. But as the nspanel component doesn’t yet implement all the widgets/thermostat I’ve very mildly modded a local copy that allows it to essentially pass through the JSON received from the panel. I can then catch that in the ESPhome log, decode and handle the GUI instruction with lambda sections in ESPhome. I can then return the necessary JSON commands through the component to update the panel in return.

The documentation from blakadder for Tasmota is absolutely invaluable - and the ability to see how both tasmota and the ESPHome nspanel component drive the screen already.

So far I have :-

  • nspanel component setting Temperature, Date, Time, WiFi, Relay indicators as standard
  • Weather updating via wttr.in (as per Tasmota) with https json request direct from the NSPanel
  • 2-Way sync of thermostat with HA (Set temperature + On/Off)
  • Widgets implemented :-
    • 2-Way sync for single Outlet
    • 2-way sync for Bulb with brightness
    • 2-way sync for RGB LED strip (inc RGB+Brightness)

I recorded a quick demo
Have thrown my (very much work in progress!) yaml on pastebin

10 Likes

Today the amazing folks on the Unofficial Nextion Discord discovered how to fix the problem of EU panels having their touch position offset if you’re using a custom TFT. Put this incantation into Program.s (at the top of the Nextion Editor):

lcd_dev fffb 0002 0000 0020

and everything should be good.

@gijsje @krulbel … I tried to tag folks who mentioned they were having this problem, but I feel like there were others I missed.

11 Likes

Could you make a backup of your panel with esphome and share it so you can recover the original HMI? In euphoria I forgot to backup the original tft I would be grateful

Its in the discord channel

EU: Discord

I still need to understand what you’ve done but I can already says that it’s amazing!! Thank you so much

Would you be kind enough to pass me the link to the file? I tried searching but I’m not very familiar with discord :pensive:

direct link:
https://cdn.discordapp.com/attachments/538814618106331139/925351768852951050/ns-panel.tft

5 Likes

thank you for passing me the link

have errors when compiling on dev-esphome:
Compiling .pioenvs\nspanel1\src\esphome\components\web_server\web_server.cpp.o</s> <s>src\esphome\components\json\json_util.cpp: In function 'std::__cxx11::string esphome::json::build_json(const json_build_t&)':</s> <s>src\esphome\components\json\json_util.cpp:28:3: error: 'DynamicJsonDocument' was not declared in this scope</s> <s> DynamicJsonDocument json_document(free_heap);</s> <s> ^</s> <s>src\esphome\components\json\json_util.cpp:29:21: error: 'json_document' was not declared in this scope</s> <s> JsonObject root = json_document.to<JsonObject>();</s> <s> ^</s> <s>src\esphome\components\json\json_util.cpp:29:48: error: expected primary-expression before '>' token</s> <s> JsonObject root = json_document.to<JsonObject>();</s> <s> ^</s> <s>src\esphome\components\json\json_util.cpp:29:50: error: expected primary-expression before ')' token</s> <s> JsonObject root = json_document.to<JsonObject>();</s> <s> ^</s> <s>src\esphome\components\json\json_util.cpp:30:9: error: use of deleted function 'ArduinoJson::JsonObject::JsonObject(const ArduinoJson::JsonObject&)'</s> <s> f(root);</s> <s> ^

as i understand: i need to downgrage to ArduinoJson v5, but i don’t know how?

P.s. changed code to ArduinoJson v6, but now have another problem: panel restarts after few seconds from main screen opened…
P.s.2 maybe it’s because it deleted weather section and wifi-indicator from my code? problem is when state changed from UI Panel - it’s reboot…

Yes, to make it work, you need to create a local version of the nspanel component.

From jesserockz github esphome/esphome/components/nspanel at nspanel/component · jesserockz/esphome · GitHub

copy the 3 files (init.py nspanel.cpp and nspanel.h) into a directory in your ESPHome YAML directory “component/nspanel/”

In the local nspanel.cpp file find the line

 "json::parse_json(message, [this, type, message](JsonObject root) { this->process_command_(type, root, message); });"

(currently line 100) and comment it out.

This disables the nspanel component from trying to handle the responses from the panel, and simply allows it to log them.

You will also need to delete the line

lambda: 'id(nspanel1).send_wifi_state_();'

from the screen power switch section of my NSP yaml - it will cause another error, but didn’t accomplish what I needed so easier to delete.

Obviously once you’re using the local version you wont benefit from any additional functionality or bugfixes applied to the component moving forward. Ideally a “on_json_message” trigger could be added to the component in the future to achieve the same thing.

This is all very much work in progress currently and mostly I wanted to see the potential of the original panel GUI,

2 Likes

My panel is coming on quite nicely. But one problem I can’t get my head round is that the display disappears on the right hand side. I have the correct profile in the Nextion editor and it looks fine in the debugger but it’s almost like the image is too big.

Long time lurker, first time poster! I’ve purchased three of these units for my new house in AUS - and these truly are game changers.

I’m no UI designer, and only just started playing with both Tasmota and ESPHome, love both, and both will def have their uses.

Decided to run ESPHome on these rather than Tasmota, personal opinion is these might be better suited to ESPHome where tasmota is better for the standalone sensors without the UI.

Anyways, here’s my latest iteration of the front page of my NSPanel.

Got a bit more work to do! Love the fact that I can QR code my guest-wifi details (if you hit the wifi button it switches to a new page with the code)! this has been something i’ve wanted at my front door for a long time!

Still got some work to do but am loving this thing!

8 Likes

The EU model is slightly covered by the bezel. I think you just need to design around it. Also see above for the touch calibration fix.

1 Like