Ns Panel coding help

Hello, Developers I have designed HMI for NS panel in nextion I have two pages id page 0 and page 1 on page 0 it is simple touch me command and page 1 it is just light button the NS panel is connected perfectly connected with home assistant so the problem is the page 0 information is easily accessible in home assistant it giving me perfect result but when I go to page 1 and click the button it did not give me any response in home assistant like the page 1 is working fine in NS panel and in the logs but not accessible in device and integration let me send you the code and some pictures.

Code:

Set some variables for convenience

substitutions:
node_name: shawn-touchscreeen
device_name: permia

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:

Enable wireless updates

ota:

Enable Home Assistant API

api:
services:
# Service to play a song
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play:
rtttl: !lambda ‘return song_str;’
- service: upload_tft
then:
- lambda: ‘id(disp1)->upload_tft();’

A reboot button is always useful

button:

  • platform: restart
    name: Restart $device_name

Define some inputs

binary_sensor:

  • platform: gpio
    name: $device_name Left Button
    pin:
    number: 14
    inverted: true
    on_click:

    • switch.toggle: relay_1
  • platform: gpio
    name: $device_name Right Button
    pin:
    number: 27
    inverted: true
    on_click:

    • switch.toggle: relay_2
  • platform: nextion
    name: $device_name Touch me
    page_id: 0
    component_id: 0

  • platform: nextion
    name: $device_name Light
    page_id: 1
    component_id: 1

sensor:

  • platform: wifi_signal
    name: $device_name WiFi Signal
    update_interval: 60s

  • platform: ntc
    id: temperature
    sensor: resistance_sensor
    calibration:
    b_constant: 3950
    reference_temperature: 25°C
    reference_resistance: 10kOhm
    name: $device_name Temperature

  • platform: resistance
    id: resistance_sensor
    sensor: ntc_source
    configuration: DOWNSTREAM
    resistor: 11.2kOhm

  • platform: adc
    id: ntc_source
    pin: 38
    update_interval: 10s
    attenuation: 11db

Grab current temperature from Home Assistant

  • platform: homeassistant
    id: current_temperature
    entity_id: weather.home
    attribute: temperature
    on_value:

    Push it to the display

    then:
    - lambda: ‘id(disp1).set_component_text_printf(“temp”, "%.1f “”\xb0"“F”, x);’

Define some outputs

switch:

The two relays

  • platform: gpio
    name: $device_name Relay 1
    id: relay_1
    pin:
    number: 22
  • platform: gpio
    name: $device_name Relay 2
    id: relay_2
    pin:
    number: 19

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

number:
platform: template
name: $device_name Brightness
id: brightness
entity_category: config
unit_of_measurement: ‘%’
min_value: 0
max_value: 100
step: 1
initial_value: 30
set_action:
then:
- lambda: ‘id(disp1).set_backlight_brightness(x/100);’

Configure the internal bleeper

output:

  • platform: ledc
    id: buzzer_out
    pin:
    number: 21

Enable ringtone music support

rtttl:
id: buzzer
output: buzzer_out

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.0.124:8123/local/muhammad.tft

    A little fun…

    on_setup:
    then:
    - number.set:
    id: brightness
    value: 30
    - lambda: |-
    id(disp1).set_component_text_printf(
    “temp”, "%.1f “”\xb0"“F”, id(current_temperature).state
    );
    - rtttl.play: “twobits:d=4,o=5,b=220:c6,8g,8g,a,g,p,b,c6”

Picture:

you see in the picture the touch me button is on page 0 and light button is page 1 so page 0 button is active when I touched the touch me button but whenever I touched the page 1 light button it is not active maybe something issue with the code please can you give me some suitable direction how I can access the page 1 button in home assistant?

First , this is not easily readable… post this in a readable fashion… i.e. use the ‘formatted text’ button in the edit window or add 3 backquotes start/end
Then, seeing some of the comments, this seems to be coming from/through marcfager’s solution and you miss a few elements…have a look there too
e.g. I have something like this in my binary sensors:

  - platform: nextion
    name: $device_name Light 1 button
    page_id: 2
    component_id: 18
    on_click:
      - homeassistant.service:
          service: light.toggle
          data:
            entity_id: light.living_room_right_color

marcfager/nspanel-mf: Custom HMI controlled by ESPHome for the Sonoff NSPanel. Includes media player card and home screen with weather data and clock. More to come. (github.com)

Blockquote

Blockquote # Set some variables for convenience
substitutions:
node_name: shawn-touchscreeen
device_name: permia

Note: this may not be needed if the pull request has been merged.

Check Handle Nextion displays that are in Protocol Reparse Mode by masto · Pull Request #2956 · esphome/esphome · GitHub for current status.

external_components:

  • source: github://pr#2956
    components: [nextion]
    refresh: 1h

esphome:
name: $node_name
comment: $device_name

esp32:
board: esp32dev

wifi:
ssid: bibi
password: jupiter555

Enable logging

logger:

Enable wireless updates

ota:

Enable Home Assistant API

api:
services:
# Service to play a song
- service: play_rtttl
variables:
song_str: string
then:
- rtttl.play:
rtttl: !lambda ‘return song_str;’
- service: upload_tft
then:
- lambda: ‘id(disp1)->upload_tft();’

A reboot button is always useful

button:

  • platform: restart
    name: Restart $device_name

Define some inputs

binary_sensor:

  • platform: gpio
    name: $device_name Left Button
    pin:
    number: 14
    inverted: true
    on_click:

    • switch.toggle: relay_1
  • platform: gpio
    name: $device_name Right Button
    pin:
    number: 27
    inverted: true
    on_click:

    • switch.toggle: relay_2
  • platform: nextion
    name: $device_name Touch me
    page_id: 0
    component_id: 0

  • platform: nextion
    name: $device_name Ceiling
    page_id: 2
    component_id: 1
    on_click:

    • homeassistant.service:
      service: switch.toggle
      data:
      entity_id: switch.living_room_ceiling_2

sensor:

  • platform: wifi_signal
    name: $device_name WiFi Signal
    update_interval: 60s

  • platform: ntc
    id: temperature
    sensor: resistance_sensor
    calibration:
    b_constant: 3950
    reference_temperature: 25°C
    reference_resistance: 10kOhm
    name: $device_name Temperature

  • platform: resistance
    id: resistance_sensor
    sensor: ntc_source
    configuration: DOWNSTREAM
    resistor: 11.2kOhm

  • platform: adc
    id: ntc_source
    pin: 38
    update_interval: 10s
    attenuation: 11db

Grab current temperature from Home Assistant

  • platform: homeassistant
    id: current_temperature
    entity_id: weather.home
    attribute: temperature
    on_value:

    Push it to the display

    then:
    - lambda: ‘id(disp1).set_component_text_printf(“temp”, "%.1f “”\xb0"“F”, x);’

Define some outputs

switch:

The two relays

  • platform: gpio
    name: $device_name Relay 1
    id: relay_1
    pin:
    number: 22
  • platform: gpio
    name: $device_name Relay 2
    id: relay_2
    pin:
    number: 19

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

number:
platform: template
name: $device_name Brightness
id: brightness
entity_category: config
unit_of_measurement: ‘%’
min_value: 0
max_value: 100
step: 1
initial_value: 30
set_action:
then:
- lambda: ‘id(disp1).set_backlight_brightness(x/100);’

Configure the internal bleeper

output:

  • platform: ledc
    id: buzzer_out
    pin:
    number: 21

Enable ringtone music support

rtttl:
id: buzzer
output: buzzer_out

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.0.124:8123/local/muhammad.tft

    A little fun…

    on_setup:
    then:
    - number.set:
    id: brightness
    value: 30
    - lambda: |-
    id(disp1).set_component_text_printf(
    “temp”, "%.1f “”\xb0"“F”, id(current_temperature).state
    );
    - rtttl.play: “twobits:d=4,o=5,b=220:c6,8g,8g,a,g,p,b,c6”

> Blockquote

Blockquote

Blockquote