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

That’s what I am doing! Mock-up is ready and have already created some buttons and a more extensive music player.

Need to fix my issue with flashing the screen so I can test it.

10 Likes

Hi there,
Is it possible to turn on the NSPanel screen with a motion sensor ?

Oh WOW, please share this when you are ready. Love it

1 Like

I don’t understand everything you’re saying, but yes, that’s the cable I was referring to.

Some people disconnect it to take the board out, or just dislodge it in the process of moving things around. Flex connectors are fiddly. If the panel connects to ESPHome, but the screen doesn’t turn on at all, it’s one of the possible problems to check.

Yes, depending on how you set it up.

For example, I’m going down the ESP home route and using a modified version of https://github.com/marcfager/nspanel-mf

I can set the brightness to 100% when motion is triggered. It will automatically power down again after some time.

1 Like

Getting closer to getting my panel fixed so I can test it (the initial aligning) and will upload the working hmi/tft and config to GitHub after. Now running into a problem that the NSpanel disconnects during the tft upload so the upload fails and the thing appears to reboot:

10:51:35][D][sensor:125]: 'ntc_source': Sending state 1.58800 V with 2 decimals of accuracy
[10:51:35][D][resistance:037]: 'resistance_sensor' - Resistance 10388.8Ω
[10:51:35][D][sensor:125]: 'resistance_sensor': Sending state 10388.78613 Ω with 1 decimals of accuracy
[10:51:35][D][ntc:026]: 'Woonkamer NSPanel Temperature' - Temperature: 24.1°C
[10:51:35][D][sensor:125]: 'Woonkamer NSPanel Temperature': Sending state 24.14409 °C with 1 decimals of accuracy
[10:51:40][D][nextion_upload:169]: Connected
[10:51:40][D][nextion_upload:175]: Requesting URL: http://10.13.7.105:8123/local/nspanel_woonkamer.tft
[10:51:40][D][nextion_upload:209]: Updating Nextion NX4832F035_011C...
[10:51:41][D][nextion_upload:235]: Waiting for upgrade response
[10:51:41][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:41][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:41][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:41][D][nextion_upload:239]: Upgrade response is  4
[10:51:41][D][nextion_upload:242]: Available 0 : 0x00
[10:51:41][D][nextion_upload:242]: Available 1 : 0x00
[10:51:41][D][nextion_upload:242]: Available 2 : 0x00
[10:51:41][D][nextion_upload:242]: Available 3 : 0x05
[10:51:41][D][nextion_upload:246]: preparation for tft update done
[10:51:41][D][nextion_upload:283]: Allocating buffer size 65536, Heap size is 235460
[10:51:41][D][nextion_upload:305]: Updating tft from "http://10.13.7.105:8123/local/nspanel_woonkamer.tft" with a file size of 777652 using 65536 chunksize, Heap Size 167008
[10:51:41][D][nextion_upload:044]: Requesting range: bytes=0-16383
[10:51:42][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:42][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:42][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:43][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:43][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:43][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:43][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:43][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:43][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:43][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:43][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:43][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:43][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:44][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:44][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:44][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:44][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:44][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:44][E][uart:015]: Reading from UART timed out at byte 0!
[10:51:44][D][nextion_upload:117]: Nextion reported new range 526344
[10:51:44][D][nextion_upload:316]: Heap Size 171524, Bytes left 251308
[10:51:44][D][nextion_upload:044]: Requesting range: bytes=526344-591879
[10:51:50][D][nextion_upload:316]: Heap Size 178372, Bytes left 185772
[10:51:50][D][nextion_upload:044]: Requesting range: bytes=591880-657415
[10:51:56][D][nextion_upload:316]: Heap Size 178368, Bytes left 120236
[10:51:56][D][nextion_upload:044]: Requesting range: bytes=657416-722951
INFO nspanel-woonkamer.local: Ping timed out!
INFO Disconnected from ESPHome API for nspanel-woonkamer.local
WARNING Disconnected from API
WARNING Can't connect to ESPHome API for nspanel-woonkamer.local: Hello timed out
INFO Trying to reconnect to nspanel-woonkamer.local in the background
INFO Successfully connected to nspanel-woonkamer.local
[10:52:14][C][uart.arduino_esp32:105]: UART Bus:
[10:52:14][C][uart.arduino_esp32:106]:   TX Pin: GPIO16
[10:52:14][C][uart.arduino_esp32:107]:   RX Pin: GPIO17
[10:52:14][C][uart.arduino_esp32:109]:   RX Buffer Size: 256
[10:52:14][C][uart.arduino_esp32:111]:   Baud Rate: 115200 baud
[10:52:14][C][uart.arduino_esp32:112]:   Data Bits: 8
[10:52:14][C][uart.arduino_esp32:113]:   Parity: NONE
[10:52:14][C][uart.arduino_esp32:114]:   Stop bits: 1
[10:52:14][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Woonkamer NSPanel Left Button'
[10:52:14][C][gpio.binary_sensor:016]:   Pin: GPIO14
[10:52:14][C][gpio.binary_sensor:015]: GPIO Binary Sensor 'Woonkamer NSPanel Right Button'
[10:52:14][C][gpio.binary_sensor:016]:   Pin: GPIO27
[10:52:14][C][switch.gpio:048]: GPIO Switch 'Woonkamer NSPanel Relay 1'
[10:52:14][C][switch.gpio:049]:   Pin: GPIO22
[10:52:14][C][switch.gpio:071]:   Restore Mode: Restore (Defaults to OFF)
[10:52:14][C][switch.gpio:048]: GPIO Switch 'Woonkamer NSPanel Relay 2'
[10:52:14][C][switch.gpio:049]:   Pin: GPIO19
[10:52:14][C][switch.gpio:071]:   Restore Mode: Restore (Defaults to OFF)
[10:52:14][C][switch.gpio:048]: GPIO Switch 'screen_power'
[10:52:14][C][switch.gpio:049]:   Pin: GPIO4
[10:52:14][C][switch.gpio:071]:   Restore Mode: Always ON
[10:52:14][C][template.number:049]: Template Number 'Woonkamer NSPanel Brightness'
[10:52:14][C][template.number:049]:   Unit of Measurement: '%'
[10:52:14][C][template.number:050]:   Optimistic: NO
[10:52:15][C][template.number:051]:   Update Interval: 60.0s
[10:52:15][C][ledc.output:118]: LEDC Output:
[10:52:15][C][ledc.output:119]:   Pin GPIO21
[10:52:15][C][ledc.output:120]:   LEDC Channel: 0
[10:52:15][C][ledc.output:121]:   Frequency: 1000.0 Hz
[10:52:15][C][restart.button:017]: Restart Button 'Restart Woonkamer NSPanel'
[10:52:15][C][ntc:014]: NTC Sensor 'Woonkamer NSPanel Temperature'
[10:52:15][C][ntc:014]:   Device Class: 'temperature'
[10:52:15][C][ntc:014]:   State Class: 'measurement'
[10:52:15][C][ntc:014]:   Unit of Measurement: '°C'
[10:52:15][C][ntc:014]:   Accuracy Decimals: 1
[10:52:15][C][resistance:010]: Resistance Sensor 'resistance_sensor'
[10:52:15][C][resistance:010]:   State Class: 'measurement'
[10:52:15][C][resistance:010]:   Unit of Measurement: 'Ω'
[10:52:15][C][resistance:010]:   Accuracy Decimals: 1
[10:52:15][C][resistance:010]:   Icon: 'mdi:flash'
[10:52:15][C][resistance:011]:   Configuration: DOWNSTREAM
[10:52:15][C][resistance:012]:   Resistor: 11200.00Ω
[10:52:15][C][resistance:013]:   Reference Voltage: 3.3V
[10:52:15][C][adc:057]: ADC Sensor 'ntc_source'
[10:52:15][C][adc:057]:   Device Class: 'voltage'
[10:52:15][C][adc:057]:   State Class: 'measurement'
[10:52:15][C][adc:057]:   Unit of Measurement: 'V'
[10:52:15][C][adc:057]:   Accuracy Decimals: 2
[10:52:15][C][adc:067]:   Pin: GPIO38
[10:52:15][C][adc:082]:  Attenuation: 11db (max 3.9V)

I have an odd problem with the Esphome code causing the Nspanel not to boot after flashing it. It has happened with 3 different types of code entries. So far I have got round it by coming up with alternative ways of getting the pages to work but the latest problem is the final straw and I need to find out why it is happening as I have wasted far too much time trying to get it to work and finding alternative ways.

The latest example is with showing the current temperature of my Wiser radiator valves. Using the Nextion editor I have created a page with 6 text boxes on it that will show the temperature of a each room. The temperatures are pulled from Home Assistant by using 6 sensor entries in the Esphome code. I have tried each of the 6 code entries individually and they work correctly and show the temperate of that room in the text box on the page on the Nspanel. But I can only have any combination of code for 3 rooms active in Esphome. If I have 4 or more room code entries the Nspanel will not boot after flashing!

I have tried all combinations of the rooms code and if makes no difference which combination is used. Any combination of 3 rooms will work. As soon as you have 4 it will not boot.

Example of the Esphome sensor entries code is below :-

binary_sensor:
# Rooms Boost Buttons - Dining Room
  - platform: nextion
    name: $device_name Cancel button
    page_id: 9
    component_id: 23
    on_click:
      - homeassistant.service:
          service: climate.set_hvac_mode
          data:
            hvac_mode: auto
            entity_id: climate.wiser_dining_room

  - platform: nextion
    name: $device_name Boost 30 button
    page_id: 9
    component_id: 17
    on_click:
      - homeassistant.service:
          service: wiser.boost_heating
          data:
            time_period: '30'
            entity_id: climate.wiser_dining_room

  - platform: nextion
    name: $device_name Boost 60 button
    page_id: 9
    component_id: 20
    on_click:
      - homeassistant.service:
          service: wiser.boost_heating
          data:
            time_period: '60'
            entity_id: climate.wiser_dining_room

#  - platform: nextion
#    name: $device_name Boost 120 button
#    page_id: 9
#    component_id: 21
#    on_click:
#      - homeassistant.service:
#          service: wiser.boost_heating
#          data:
#            time_period: '120'
#            entity_id: climate.wiser_dining_room

#  - platform: nextion
#    name: $device_name Boost 180 button
#    page_id: 9
#    component_id: 22
#    on_click:
#      - homeassistant.service:
#          service: wiser.boost_heating
#          data:
#            time_period: '180'
#            entity_id: climate.wiser_dining_room

#  - platform: nextion
#    name: $device_name Boost Advance button
#    page_id: 9
#    component_id: 2
#    on_click:
#      - homeassistant.service:
#          service: wiser.boost_heating
#          data:
#            time_period: '30'
#            entity_id: climate.wiser_dining_room

With only the 3 sections active it works. If I uncomment any of other sections as well the Nspanel will not boot up.

Can anyone explain what I am doing wrong?

Thanks.

Here is my NSPanel. Graphics are not ready, but all works.

What do you think?

4 Likes

looking great… nice work…
i only hope that the Nextion Editor is going to be much easier to work with

I’ve just changed my sleep method to use the built in sleep instead of the button or the screensaver page. The big button was a pain when editing and the screensaver page only works if you have one page as far as I can see. If you’re on a different page, it’s always going to go back to the home screen. Not a big problem but I didn’t want to build in an issue.

So, I used the sleep method. It works fine apart form one thing. I have a motion sensor that switches the screen back on. In Node-RED, I have an nspanel_send_command with:

{"cmd":"click wake_button,0"}

That obviously won’t work now as the screen is asleep and won’t accept the command, and there is no button to click.

Does anyone know a way round this?

what if you would make a black screen as sleep screen, and whenever the Motion triggers you got the desired page, would that be a work around?!

Or maybe dim it to 0% and wake it up to full brightness in a lambda:

  • lambda: ‘id(disp1).set_backlight_brightness(x/100);’
    Something like this.

Or send a command sleep ==0 is wake up

  • lambda: ‘id(disp1).send_command_printf("%s", cmd.c_str());’

My take on the NSPanel plus me asking for some help…
I’ve tried to create something with the main purpose of easy control of lights in all rooms but with the possibility to go deeper into each room to control basically everything. Plus dynamic pages that pop up on special events: Knock on door, coffee brew, deactivate alarm…

Help is about the fact that I can’t add any more components to the code because that causes the ESP to not boot up. The code compiles and gets uploaded but it then just gets stuck with a flashing first page. Very annoying since I’ve come so far with the project. Flash memory is about 65% use but it feels like it has to much to initiate at boot up so it just gives up. Anyone has any ideas of what the root cause could be?

Code is uploaded on Github:
https://github.com/lillaeriika/NSPanel

7 Likes

Yes, I have also found it easiest just to use the built-in Nextion sleep command following the details on the topic in in the Nextion Instruction Set and the Nextion Sunday Blog series.

Some tips I’ve found on getting sleeping & waking to work properly:

  • Read the Nextion Instruction Set descriptions for System Variables ussp, thsp (currently not working on NSPanels), thup and usup, in particular taking note of setting thup=1 (to wake on touch) and usup=0 (to NOT wake on serial coms).
  • Even when the Nextion is in sleep mode with usup=0, it will wake by sending sleep=0ÿÿÿ (the ESPHome send_command() adds the ÿÿÿ termination to all Nextion Instructions for you). You just have to make sure you send that instruction first BEFORE you send the next commands you want to send, and include a short delay (to allow the Nextion to wake up).
  • There doesn’t seem to be a Nextion Event that you can use to reset things as the device wakes up. I’ve found it helps to set everything to be prepared for waking up (such as higher screen brightness etc.) immediately before calling sleep=1 in my Nextion Event code.
  • It helps if you have your own controlled way of putting the Nextion to sleep (rather than its internal time out settings or just sending sleep=1 from HA/ESPH) so as to ensure you have set it up to wake up in a controlled manner (given the previous point). (thsp isn’t working on NSPanels at the moment, but I don’t think I use it even it were - controlled sleeping is a better option.)

I have my own NSPanels working very well with sleeping (to black screen), progressive screen dimming while there is inaction, waking from sleep, and control of variable-speed update loops if you want to check out my HA Community posting or my code files on GitHub.

(edit)… and here is a motion automation to wake up the NSP from usup=0 sleep (I’ve edited in the notes about termination and the need for a delay I originally forgot to mention above):

# Wake NSP on motion
- alias: "Motion wake NSP1"
  trigger:
    - platform: state
      entity_id: binary_sensor.lounge_motion
      to: "on"
  condition:  # << Useful if you have a way to check the NSP isn't already in use
    - condition: state
      entity_id: sensor.nsp1_trigger
      state: "0.00"  # << indicates sleeping for Nextion Handler
  action:
    - service: esphome.nsp1_send_command
      data:
        cmd: sleep=0  #<< the ESPHome 'send_command()' will add the required termination string (0xFF, 0xFF, 0xFF = ÿÿÿ")
    - delay: 0.5  # <<<< note short delay to allow Nextion to wake up
    - service: esphome.nsp1_send_command
      data:
        cmd: page 0
1 Like

… and here is the Nextion Sunday Blog that covered sleeping that I referred to above (it took a bit of Googling to find it again)

and the Nextion Instruction Set is here - see notes on System Variables nos. 7, 8, 9 and particularly 17.

The EU model does not fit in the default 60mm flush-mounted box.

So i designed and 3D printed a surface mount enclosure what will fit on the 60mm flush-mounted box.

https://www.thingiverse.com/thing:5256325

2 Likes

Help is about the fact that I can’t add any more components to the code because that causes the ESP to not boot up.

I couldn’t find the HMI file on the GitHub link you posted (only the TFT) - did I miss something?
Without that the first suggestion would be to check the number of components you have (given it seemed you are dynamically cramming a lot of components into one page?), and if it exceeds the 250 limitation noted in the Nextion documentation:

There is a hard limit of 250 components allowed per page…

Why not make the box tilted if you 3d printed it?
Just having it 10-15% angle would make a more pleasant I believe.

Sorry I forgot to upload the HMI file. It’s up there now. It’s actually not that many buttons on the first page. It’s basically just what you see. Maybe 15 buttons. I dynamically change the value of the buttons though so there is a lot of code in the yaml file that executes on button presses or if a light is changed.

I don’t think the HMI file is the issue. I think it is quite small to what it could be. It’s as soon as i add code or components to the YAML file that the ESP stops booting. As I said when I go over the “limit” for what it can handle during boot it sometimes starts working if i just remove logging and try to reboot again. So I have a very strong feeling that the ESP has too much to handle in the yaml file during boot. Is there any way to sequence the boot process so it doesn’t try to do everything at the same time? Is there any settings connected to the boot process that could help me? I don’t know, I’m just guessing.

Edit: I’ve done some more investigation. Working theory right now is that I was using retained messages on my MQTT channels in Openhab. I thought that would be a good idea so a newly started panel would get the latest value on all components. But thinking about it I don’t think the ESP likes receiving data from 20 mqtt topics on boot plus a lot of code that is supposed to execute for each received message. At the same time it is trying to initialize every ESP component as well. Looks like I can add some more stuff for the moment at least.

1 Like

I’m having a real issue just getting the built-in sleep working. I’ve gone back to the simplest configuration I can imagine: 2 pages, each with different background colours so easily distinguishable, with a button on each which goes to the other page. I’ve tried to make the second page the start up page and the display to sleep after 15 seconds. This configuration works in the Nextion debugger prefectly but:

  • The start page is always the first (albeit with a cycle from the last to the first when I reload the tft file)
  • I sit and wait and wait but the screen never sleeps

My Program.s is trivial:

thsp=15  //Sleep after this many secs without touch
thup=1     //Enables(1) touch to wake device
ussp=15  //Sleep after this many secs without serial port activity
usup=0     //Disable(0) wake on serial data - NB*** will still wake if command string "sleep=1ÿÿÿ" is sent over serial
page Last   //Power on start page (255 = last page)

My nspanel.yaml is bare bones:

# Set some variables for convenience
substitutions:
  node_name: nspanel
  device_name: NSPanel

# Note: this may not be needed if the pull request has been merged.
# Check https://github.com/esphome/esphome/pull/2956 for current status.
external_components:
  - source: github://pr#2956
    components: [nextion]
    refresh: 1h

esphome:
  name: $node_name
  comment: $device_name

esp32:
  board: esp32dev

# Enable logging
logger:
  baud_rate: 0
  level: DEBUG
  logs:
    sensor: WARN
    resistance: WARN
    text_sensor: WARN
    ntc: WARN

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    password: !secret wifi_password

captive_portal:

# Enable wireless updates
ota:

# Enable Home Assistant API
api:
  services:
    # Service to upload the tft file
    - service: upload_tft
      then:
        - lambda: 'id(disp1)->upload_tft();'

switch:
  # Pin 4 always needs to be on to power up the display
  - platform: gpio
    id: screen_power
    entity_category: config
    pin:
      number: 4
      inverted: true
    restore_mode: ALWAYS_ON

# Configure UART for communicating with the screen
uart:
  id: tf_uart
  tx_pin: 16
  rx_pin: 17
  baud_rate: 115200

# Configure the screen itself
display:
  - platform: nextion
    id: disp1
    uart_id: tf_uart
    tft_url: http://192.168.x.y:8123/local/tft/nspanel.tft

Anyone else having a similar issue? Am I missing something?

Try a more controlled approach to sleeping (& waking) by setting sleep=1 in a timer (that will ultimately control a lot of the sequencing and scheduling of your code on the page - I call mine UPDATE_LOOP).
Start simply by adding a timer to your page and set its attributes (in the panel with the table of attributes for the selected component) e.g.,:
UPDATE_LOOP.tim 15000 (ms = the 15 secs you’re trying just to get going).
UPDATE_LOOP.en 1 (to make sure the timer is enabled and will start when you open the page).
Then in the ‘Event’ panel for the timer enter:
sleep=1
Check that this very basic set up works first (in the simulator, then on the physical device), and that it wakes up again on touch (with your thsp=1 setting) but does not wake from serial communications (with your usup=0, unless you send sleep=0).

If that all works properly, then add a variable with a counter to your loop, and only put the device to sleep when the counter crosses a trigger value.
Then you can start managing this timer control loop with events that change the counter and change the looping interval (*.tim) (and you can add more things into the loop that happen conditionally such as sleeping, dimming, getting data updates, managing the rate of data flow, applying data updates to UI attributes etc. as your project needs).

I’m sure there are other approaches, but this one is working well for me. (I found that if I didn’t control how the Nextion was put to sleep that I couldn’t control how it woke up again, which was giving me unpredictable and laggy responses after waking again).

1 Like