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.