I have a Sonoff NSPanel and I’m having absolutely no luck getting a slider to sync both ways.
I have managed to get it to sync from Home Assistant to Nextion, but I can’t get it to go the other way
I also had problems getting the slider sync right in two directions when using a Nextion display. The solution which worked for me:
Add an extra (hidden) helper button on the HMI panel and also define a binary sensor for this button in your YAML file.
In the Touch Release Event of the slider in the HMI panel generate a ‘fake’ press event on the helper button with a printh statement like printh 65 00 03 01 FF FF FF where the 00 is the pagenum, 03 the id off the helper button. Both these numbers must be the hex representation of the decimal ID values you see in the Nextion editor for the page id and button id. (You can see the actual hex values if you press this helper button in the debug mode of the editor).
In your YAML file add an on_press event for the helper button where you do a manual update of your slider sensor to get the current nextion slider value, the YAML code:
binary_sensor:
- platform: nextion
page_id: XX <--- your Nextion page num
component_id: YY <--- your Nextion helper button ID
id: slider_helper
on_press:
then:
- lambda: !lambda |-
id(slider_helper).publish_state(false); // Reset state helper
id(my_slider).update(); // Get slider value from Nextion panel
I can see that an event is being sent to ESPHome now for the helper button when I move the slider, but the slider_helper button turns to an ON state and never changes back, and the slider in Home Assistant doesn’t update
Yes the button on the panel looks like it stays “ON”, however that doesn’t bother me, in my ‘production’ version this helper button is made invisible .
There is no direct link between HA and the panel, so now you have the correct value off the panel slider available in your ESP, you have to update the HA value via some lines of code in your ESPHome slider component. In my case it is a slider for the brightness so here is the code I use to update the slider in HA (and of course also the lamp brightness itself ).
sensor:
- platform: nextion
id: p3_studylamp_slider
component_name: study.slider
on_value:
then:
- homeassistant.service:
service: light.turn_on
data:
entity_id: light.study_lamp_rgbww_light
brightness: !lambda return int(x); // <--- the slider value as integer (in HA brightness is defined as an integer between 0 and 255)
I know this issue has been resolved, but I was just following instructions from @jsuanet and realized that you don’t need that extra hidden button at all. Slider in Nextion can report press and release events to ESPHome, if you check appropriate checkboxes in Nextion Editor. So you can just update sensor value on release of the slider itself.
Dear all,
I think I landed on the right topic… however I’m struggling to make it work and really find the right way of syncing the slider helper in HA with the brightness value in ESPHome Nextion.
Can anyone share the HMI nextion file as well as the yaml… I think I’m missing something that I’m unable to understand from a piece of code.
You can take a look at my NSPanel code here: https://github.com/ilyavolodin/NSPanel it has two sliders for controlling lights brightness and temperature that sync both ways.
I tried to use the slider, but don’t understand why it doesn’t works. Can anybody help?
I use the HMI-File from @ivolodin . In the log on ESP-Home i see the value changed when i slide on the screen. But i can’t implement this value in HA (first i will use a number helper for trying)
Thanks for your good post, you are a very modest man, when I looked at the github page as suggested, you also have a color wheel in your code, I have gone and pondered how to make it, I will try to understand your code, and then adapt it to my needs, again thank you for sharing with the rest of us.
I have a fan component on another ESP module that I’d like to control with a slider on a Sonoff NSP.
The fan is in Homeassistant and has 3 speeds so the slider would have 4 positions - 0, 33, 66, 100