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

Hi Blackadder. Sorry I am very inexperiences, but do you have a photo or info on what pins to connect to 5V for the spaniel pro please?

This is used in the Esphome code for a Sonoff NS Panel, using Esphome 2023-11-6.

number:
  # Screen brightness
  - platform: template
    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);'
        - lambda: 'id(disp1).send_command_printf("Home.brightness.val=%i", int(x));'
        - lambda: 'id(disp1).send_command_printf("Settings.n0.val=%i", int(x));'
        - lambda: 'id(disp1).send_command_printf("Settings.bright.val=%i", int(x));'

It creates a “Brightness” slider control in Home Assistant that has an initial value of 30. When it’s moved, the control shows the value it is moved to and it sends that value to the NS Panel using the set_action: lines. This is all working correctly.

Using the touch screen on the NS Panel you can also set the screen brightness using a “Screen Brightness” slider control. I have managed to get the “Brightness” slider in Home Assistant to move the NS Panel “Screen Brightness” slider position and it’s value to match the Home Assistant “Brightness” position and value so they stay in sync.

What I have been unable to do after nearly 3 days of searching, reading and trying different methods is to make the “Brightness” control in Home Assistant change position and value to match the NS Panel “Screen Brightness” slider when that is moved. I don’t think the problem I’m having is just because it’s a Sonoff NS Panel I’m using it with. I think I’m just not using the correct method to do it, but I could be wrong.

Has anyone any suggestions on what I’m doing wrong and how to achieve this?

Typically after posting my question a couple of hours later I found an alternative way to do it!

In Home Assistant I created a helper input_number.test_slider. Then created an automation that is triggered when the input_number.test_slider is moved which sets the NS Panel Screen Brightness slider to the same value

alias: Test Slider NS Panel Brightness Change
description: Test Slider Changes NS Panel Screen Brightness
trigger:
  - platform: state
    entity_id:
      - input_number.test_slider
    from: null
condition: []
action:
  - service: number.set_value
    target:
      entity_id: number.nspanel_brightness
    data:
      value: |
        {{ states('input_number.test_slider')|int(0) }}
mode: singletype or paste code here

I created a second automation that is triggered by the NS Panel lightslider being moved which sets the input_number.test_slider to the same value

alias: NS Panel Brightness Change
description: NS Panel Screen Brightness Changes Test Slider
trigger:
  - platform: state
    entity_id:
      - sensor.nspanel_lightslider
    from: null
condition: []
action:
  - service: input_number.set_value
    target:
      entity_id: input_number.test_slider
    data:
      value: |
        {{ states('sensor.nspanel_lightslider')|int(0) }}
mode: singletype or paste code here

I tried to use number.nspanel.brightness as the trigger entity_id and for the value in the second automation but it didn’t work. So I had to create a new sensor in the Esphome code

sensor:
  # Gets the value of the Screen Brightness into HA
  # Uses On Release code in the Nextion Screen Brightness slider for it to work.
  - platform: nextion
    id: lightslider
    name: lightslider
    variable_name: lightslidertype or paste code here

In the Nextion Editor add this code to the Touch Release Event for the Screen Brightness slider to pass the brightness value to Home Assistant via the lightslider sensor

printh 91
prints "lightslider",0
printh 00
prints n0.val,0
printh FF FF FF

Moving either slider now changes the screen brightness and the other sliders value and position so they stay in sync.

The only remaining issue is that the lightslider sensor shows as “Unknown” in Home Assistant until the Screen Brightness slider is moved. Trying to check for “Unknown” using isnan doesn’t work and I haven’t been able to find a way that does work.

sensor:
  # Gets the value of the Screen Brightness into HA
  # Uses On Release code in the Nextion Screen Brightness slider for it to work.
  - platform: nextion
    id: lightslider
    name: lightslider
    variable_name: lightslider
    filters:
      - lambda: !lambda |-
          if (isnan(x)) return 30;
          return x;

Hopefully other people will find this useful.

Anyone here ever succeeded in using PSRAM from NSPanel?

Been using GitHub - joBr99/nspanel-lovelace-ui: Custom Firmware for NsPanel with the design of HomeAssistant's lovelace UI in mind, works with Tasmota. for quite a long time succesfully. Now the panel is not responding to touch much at all.
Is there a way to boot the system? (other than removing house fuses…)

Have you tried the reset button in the bottom of the panel?

image

Thanks! Totally forgot that there’s a reset button. Pressing that didn’t help, just resulted in “Waiting for content” screen.
The Tasmota gui is working and there’s a reset option, also: same thing.

Somehow HA has lost the device totally.

EDIT: Updated HACS, AppDaemon, restarted HA… at least. Now NSPanel entities are seen by the HA again. Just the panel GUI is still missing.
Now it seems that the AppDaemon stops working.

EDIT2: AppDaemon secrets.yaml location needed an update, this solved it AppDaemon won't start - complains about secrets.yaml - #21 by p-x

2 Likes

I was thinking of something like this so really glad to hear you’ve got it working. Could you give more detail of what you did, I’d really like to do the same. E.g. some photos of the implementation, which sensor etc? It would be much appreciated.

Does anyone know if its possible to enable a “button released” command?

I am using @jobraun Lovelace UI with Tasmota, my buttons are decoupled from the relays and all working fine but id like to use a long press to Dim & Brighten some lights - without the button released command i just end up in a continuous loop, Any ideas?

2 Likes

Hi @jobraun

Thanks for giving my home so much joy with your NSpanel code !

I’m having an issue with the latest update 2024.04. I’ve followed creating the scripts as suggested on

However, I get this on my screen for the forecast dates

Here’s my scripts:

template:
  - trigger:
      - platform: time_pattern
        hours: /1
    action:
      - service: weather.get_forecasts
        data:
          type: daily
        target:
          entity_id: weather.home
        response_variable: daily
    sensor:
      - name: Weather Forecast Daily
        unique_id: weather_forecast_daily
        state: "{{states('weather.home')}}"
        attributes:
          temperature: "{{state_attr('weather.home', 'temperature')}}"
          temperature_unit: "{{state_attr('weather.home', 'temperature_unit')}}"
          forecast: "{{daily['weather.home'].forecast}}"

and here is the other bit

  entities:
    - entity: weather.home
    - entity: sensor.weather_forecast_daily
      type: 0
    - entity: sensor.weather_forecast_daily
      type: 1
    - entity: sensor.weather_forecast_daily
      type: 2
    - entity: sensor.weather_forecast_daily
      type: 3
    - entity: sensor.ingham_imported_energy_cost
      name: $ Today
      icon: mdi:solar-power-variant

Any guidance on what I may need to change ?

All the best

Jason

Hi Jason,

Can I ask if your in Australia and using the BOM integration. As I have the same issue as yourself.

Hi Claire, yes in Oz, and no - just using the standard met.no forecast sensor that is installed by default by HASS.

I’m having the same issue. The main weather shows fine but none of the forecast. Hope that API gets updated soon.

I have this resolved now, the idea - smile slowly - first ensure your sensor is working. Note I changed the template to update each minute as seen below, will return this to hour later. So I can see changes, I commented out # forecast, and set the state, temperature, temperature_unit to a string.

#NSPANEL MOD for weather
- trigger:
    - platform: time_pattern
      minutes: /1
  action:
    - service: weather.get_forecasts
      data:
        type: daily
      target:
        entity_id: weather.bom                                         # change to your weather entity
      response_variable: daily
  sensor:
    - name: Weather Forecast Daily
      unique_id: weather_forecast_daily
      state: "{{states('weather.bom')}}"                                         # change to your weather entity in this line
      attributes:
        temperature: "{{state_attr('weather.bom', 'temperature')}}"              # change to your weather entity
        temperature_unit: "{{state_attr('weather.bom', 'temperature_unit')}}"      # change to your weather entity
        forecast: "{{ daily['weather.bom'].forecast }}"                             # change to your weather entity

When I could see the Entity in Dev Tools >> States as ‘sensor.weather_forecast_daily’ I then enabled states and Reloaded All YAML, when this showed correctly I enabled temperature and so on.

If you go to his Github ([BUG] HA 2024.4 - cannot display forecast properly · Issue #1209 · joBr99/nspanel-lovelace-ui · GitHub) you will see what the sensor should look like.

Then add the sensor to the panel and the world should be beautiful.

key: ssKey
statusIcon1:
  entity: switch.study_nsp_switch1
  altFont: True
  icon:
    "on": mdi:menu-up-outline
    "off": "text:"
statusIcon2:
  entity: switch.study_nsp_switch2
  altFont: True
  icon:
    "on": mdi:menu-up-outline
    "off": "text:"
entities:
  - entity: weather.bom
  - entity: sensor.weather_forecast_daily
    type: 0
  - entity: sensor.weather_forecast_daily
    type: 1
  - entity: sensor.weather_forecast_daily
    type: 2
  - entity: sensor.weather_forecast_daily
    type: 3
  - entity: sensor.study_nsp_temperature
    icon: mdi:home-thermometer-outline
alternativeLayout: false
defaultCard: navigate.studyKey
theme: !include /homeassistant/appdaemon/apps/nsp_theme.yaml
1 Like

OK - got it working on my end … and totally my fault …

I forgot to do the required directory change and update of Appdaemon stuff …

Once I did the below … all returned to normal

follow instructions in here

Thanks for the confidence to keep troubleshooting. My issue was also my fault. I already had a template entry in my config file and had double entries. Somehow I missed the error in studio code the first time around. DOH.

Hi,

there is now available 12VDC backplate for NSPanel: Smartavan 12VDC backplate for Sonoff NSPanel

2 Likes

Hello,

anyone here can help me out please ?

when adding this line: app_dir: /homeassistant/appdaemon/apps
to the appdaemon.yaml my nspanel stops working.
yes the nspanel files are in this folder but it doesn’t work.
Getting all kind of weird appdaemon errors like:

2024-04-21 18:52:15.802634 WARNING nspanel-1: Unexpected error running initialize() for nspanel-1
2024-04-21 18:52:15.803151 WARNING nspanel-1: ------------------------------------------------------------
2024-04-21 18:52:15.808501 WARNING nspanel-1: Traceback (most recent call last):
File “/usr/lib/python3.11/site-packages/appdaemon/app_management.py”, line 162, in initialize_app
await utils.run_in_executor(self, init)
File “/usr/lib/python3.11/site-packages/appdaemon/utils.py”, line 304, in run_in_executor
response = future.result()
^^^^^^^^^^^^^^^
File “/usr/lib/python3.11/concurrent/futures/thread.py”, line 58, in run
result = self.fn(*self.args, **self.kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/homeassistant/appdaemon/apps/nspanel-lovelace-ui/nspanel-lovelace-ui.py”, line 18, in initialize
apis.ha_api = self.get_plugin_api(“HASS”)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.11/site-packages/appdaemon/utils.py”, line 231, in inner_sync_wrapper
f = run_coroutine_threadsafe(self, coro(self, *args, **kwargs))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.11/site-packages/appdaemon/utils.py”, line 313, in run_coroutine_threadsafe
result = future.result(self.AD.internal_function_timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.11/concurrent/futures/_base.py”, line 456, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.11/concurrent/futures/_base.py”, line 401, in __get_result
raise self._exception
File “/usr/lib/python3.11/site-packages/appdaemon/adbase.py”, line 115, in get_plugin_api
return await self.AD.plugins.get_plugin_api(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.11/site-packages/appdaemon/plugin_management.py”, line 404, in get_plugin_api
mod = import(module_name, globals(), locals(), [module_name], 0)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/homeassistant/appdaemon/apps/omnikdatalogger/omnik/plugin_localproxy/hassapi.py”, line 6, in
class HASSAPI(LocalProxyPlugin):
File “/homeassistant/appdaemon/apps/omnikdatalogger/omnik/plugin_localproxy/init.py”, line 7, in init
cls.register(cls) # Called when a plugin class is imported
^^^^^^^^^^^^^^^^^

Hello Everyone,

I am a self confessed noob at templates and I know I have the wrong syntax below.

But can someone help me with the right coding to display the sunrise time on the screen. The string works in the developer tools.

      - type: cardEntities
        title: Weather
        entities:
          - entity: sensor.sun_next_rising
            name: Sunrise
            value: {{ as_timestamp(states.sun.sun.attributes.next_rising) | timestamp_custom ('%H:%M %p') }}