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

sorry i forgot to check on the size… yes it sounds like it, i removed everything i could , the buzzer etc. then add back as i trim my code. do as much in the tft as possible like buttons which have 2 state images without having to assign them in the yaml etc & do as much with automations within HA instead of the yaml. it’s a real shame on the memory limitations.

edit: don’t forget to clean build files after removing components as it will remove unnecessary libs etc

edit 2: mine is definitely 68.4%, i just checked. maybe something else is going on.

Mine is currently 68.7% (?) and I can still OTA update it.
This time I just compiled to binary to check the size, but it worked fine when I OTA updated it a few hours ago.

image

nice :+1: mine doesn’t like it above :rofl:

mine is only 64.8%… :frowning:

may it is another problem?

i think yes. do you want to post your config and tft. i can try to having a look later.

I’ve found your config very useful and I’ve put together a radio player page similar to yours. I’ve three devices (two are Sonos, the other is a Google home) I want to use and so I’ve put together the following page that includes 3 buttons to select the device I want the page to work for (it’s a work in progress and I’ll tidy it eventually). I’ve a few issues I wonder if you can help with. I’ll explain my approach first.

Display

Selecting which device is done by tapping on the media buttons which updates an HA helper input_select.media_device which I use to track what I’ve selected. The bg colour of the selected media is yellow and can be changed when tapped (or when updated in HA). Then, when any of the radio buttons is tapped an automation is triggered in HA to action the request (exactly as you did).

I use Node Red for my automations and I’ve set up two, one for the radio selection and one for the volume selection as shown below (as an aside, I don’t know how I’d do it using HA standard automations). I reset the booleans in Node Red rather than my nspanel yaml. Hopefully they’re reasonably clear.

This works (and this approach means I can easily add buttons to Lovelace to do the same) but there are a few issues I’d like to iron out:

  • I can’t use the media_player.media_play_pause service for play/pause, it doesn’t work for any of my devices. I have to use media_player.volume_mute which is a bit naff!
  • I can’t get any song titles etc for any of my devices.
  • When the page is opened on the nspanel, the current device selection doesn’t update automatically. I have to have a periodic updater (I use every 1s) to update the page. [This is actually a general issue I have on my pages; I’ve an ever growing set of nested if then elses in this every 1s section to ensure a page shows current information as soon as it’s displayed. It’d be more efficient if I could force an update of a page on its selection.]

hey pedro, I’m out for a few hours but will be back later. i will see if i can help you in any way then :relaxed:

1 Like

Is the size of the file only a problem OTA? Or is it irrelevant when i update the files from usb?

if you have “OTA” in the yaml then esphome partitions a section off for the ota.

Can someone point me in the right direction.

I would like to use esphome for my nspanel. I flashed it. I used several nspanel.yaml files and several tft files.
upload and connecting to HA works fine.
When I press a button (not the two at the bottom, not gpio) HA sees and on AND off action. seems logical for binary_sensor. How can I use them for On and Off button. preferably with changing the icon on the panel.

I used lovejoy777, I used MarKWattTech and ofcourse Marcfager. all with the same effect.
I get empty buttons on my panel and no switches in HA only sensors.

thanks to all the hard workers ho are sharing there work

Thanks in advance

Here’s an example of changing an icon depending on the state:

# Front light setup
  - platform: homeassistant
    id: FrontLight
    entity_id: $FrontLight_entity_id
    on_value:
      then:
        - wait_until:
            switch.is_on: nextion_init
        - lambda: |-
            int BGimg = $TableLight_on_icon;
            if (id(FrontLight).state == "off") {
              BGimg=$TableLight_off_icon;
            }
            id(disp1).send_command_printf("Home.FrontLight.pic=%i", BGimg);

The $s are from substitutions but are the ids of the relevant images in Nextion.

How do I change the font color based on a sensor?
I have a HA sensor that gives me two possible states 63488 or 65535 and I figured I could push that in to the pco attribute of a text field

I wrote this:

  # Thermostat selected room heating color, fetched from HA
  - platform: homeassistant
    id: selected_thermostat_heating
    entity_id: sensor.ns_kitchen_selected_room_heating
    on_value:
      then:
        - wait_until:
            switch.is_on: nextion_init
        - lambda: id(disp1).set_component_text_printf("Thermostat.temp.pco", "%s", id(selected_thermostat_heating).state);

I got this warning:

/config/esphome/ns-kitchen.yaml: In lambda function:
/config/esphome/ns-kitchen.yaml:561:103: warning: format '%s' expects argument of type 'char*', but argument 4 has type 'double' [-Wformat=]
         - lambda: id(disp1).set_component_text_printf("Thermostat.temp.pco", "%s", id(selected_thermostat_heating).state);

And the panel got unstable and couldn’t even maintain the main screen so I had to revert back.
What should the ESP-Home code be?

thanks for your quick reply. this looks like it would solve one off the issues. I think I would first have to change the binary_sensor to a switch. I my yaml file I only have sensors. Ithink I can change the pic in the HMI (tft) file to a Dual-state button. How do I tell HA it is a button (switch)

The pco attribute isn’t a text field. Look at what I did above for BGimg. Replace it with, say, TXTpco and set it to 63488 or 65535 depending on the the state value of your entity. Then use my lambda call but updated with your page and variable.

All mine are binary sensors, here’s one for example:

  - platform: nextion
    name: $device_name Front Window light OnOff
    page_id: 0
    component_id: $FrontLight_component_id
    on_release:
      then:
        - homeassistant.service:
            service: switch.toggle
            data:
              entity_id: $FrontLight_entity_id

pedro my artist and song names don’t work when i use my radio channel buttons to open the url’s, i have a Google mini as my media player and the artist and title get displayed if i ask the mini to play it, but with the button url it doesn’t :sob: in my GitHub readme it explains it. as for you not updating without calling for the update i don’t know, i use on_value with all mine so they just update automatically whenever there is a change.

edit: sorry I’ve never used node_red either.

edit2: i also don’t get mute working on mine but pause/play does :rofl: i think it’s a little hit and miss with what is supported with esphome, HA & your media player. obviously all 3 have to work together :woman_shrugging:

@PedroKTFC

1 Like

your example looks so simple. :slight_smile:
I changed entity_id: to an existing light in HA. that should do the trick I guess. But still nogo.
I changed 1 button to on_release ( in my yaml it was on_click)
I added then:

Buttons on the Lights page

#Change ME - Button 1 and 2

  • platform: nextion
    name: $device_name Light 0 button
    page_id: 2
    component_id: 17
    on_click:
    then:
    - homeassistant.service:
    service: switch.toggle
    data:
    entity_id: light.kantoor_plafond_lampen # Your light for button 1

  • platform: nextion
    name: $device_name Light 1 button
    page_id: 2
    component_id: 18
    on_release:
    then:
    - homeassistant.service:
    service: switch.toggle
    data:
    entity_id: light.lamp_hal_1ste_verdieping # Your light for button 2

In the logging esphome I see:

[14:58:45][D][nextion:439]: Got touch page=2 component=17 type=PRESS
[14:58:45][D][binary_sensor:036]: ‘nspanel1 Light 0 button’: Sending state ON
[14:58:45][D][nextion:439]: Got touch page=2 component=17 type=RELEASE
[14:58:45][D][binary_sensor:036]: ‘nspanel1 Light 0 button’: Sending state OFF
[14:58:45][D][nextion:439]: Got touch page=2 component=18 type=PRESS
[14:58:45][D][binary_sensor:036]: ‘nspanel1 Light 1 button’: Sending state ON
[14:58:45][D][nextion:439]: Got touch page=2 component=18 type=RELEASE

I am missing something. all help is appreciated

ahum, AH log says: 2022-04-03 15:03:58 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.kantoor_plafond_lampen
2022-04-03 15:03:59 WARNING (MainThread) [homeassistant.helpers.service] Unable to find referenced entities light.lamp_hal_1ste_verdieping

the entities exist. they are integrated by hubitat.

Try going into HA, go to Developer Tools, at the top click on SERVICES.

Then try and use the toggle service on your entity. In the UI mode you simply have to start typing “toggle” to get the service and then you choose your entity. Then click on the call service button which should toggle your light. There’s an option to go between yaml and UI mode which shows you how HA is seeing things. This should enable you to track down the precise naming you should be using.

1 Like

you are the best. this helped me so much.
I had to use light.toggle instead of switch.toggle.

thank again

1 Like

light.toggle not switch.toggle. your using switch.toggle on a light entity.