Use ESPHome to dimand/or turn on/off nextion display

Is there any option to from and ESPHome perspective turn on/off and/or dim the screen?

Now my display is “always” on.

There are options in nextion itsself to dim the screen but this is don with a command “dim” which can be bound to a slider/button. But that is not what I want. I would like to “send a command” to it from my ESPhome connected…

Ok, some extra info. I can send a value to the nextion:

[15:23:56][D][homeassistant.text_sensor:016]: 'sensor.nextiondim_text': Got state '80'
[15:23:56][D][text_sensor:015]: 'dim_text': Sending state '80'
[15:23:58][D][homeassistant.text_sensor:016]: 'sensor.nextiondim_text': Got state '10'
[15:23:58][D][text_sensor:015]: 'dim_text': Sending state '10'

I want the nextion to “dim” to the sent value. I use the syntax:

text_sensor:
  - platform: homeassistant
    id: dim_text
    entity_id: sensor.nextiondim_text
display:
  - platform: nextion
    lambda: |-
      it.send_command_printf("dim=id(dim_text)");

But I cannot see the display dim… Anyone knows what to put in the nextion editor to have the nextion “react” on that value?

Ok, think I need this:?

display:
  - platform: nextion
    lambda: |-
      it.set_component_value("va0", id(dim_text).state);
      
text_sensor:
  - platform: homeassistant
    id: dim_text
    entity_id: sensor.nextiondim_text

But cant get my head around the declaration of the variable in:
it.set_component_value("va0", id(dim_text).state);

how do I declare “dim_text” as an integer?

I’m trying to do the same thing, any news?

You can use the nextion::sleep() function to set screen to sleep/wake_up

on ...
  - lambda: !lambda |-
      id(my_nextion).sleep(true);   // turn screen off or
      id(my_nextion).sleep(false);  // turn screen on

You can find all the available functions via the Nextion API reference ESPHome: /opt/build/esphome/esphome/components/nextion/nextion.h File Reference

1 Like

I finally understood how the Esphome API works…I predict weeks of late night sleeping :joy:
Thank you very much!