Closed ChaoticAlex closed 3 weeks ago
Could you please try this?
##Add the display as a light in Home Assistant start
light:
# Add the display as a light in Home Assistant
- name: Display
id: display_light
icon: mdi:tablet-dashboard
platform: monochromatic
output: display_output
default_transition_length: 0s
on_turn_on:
then:
- lambda: |-
ESP_LOGD("light.display_light", "Turn-on");
if (current_page->state == "screensaver") disp1->goto_page(wakeup_page_name->state.c_str());
timer_reset_all->execute();
on_turn_off:
then:
- lambda: |-
ESP_LOGD("light.display_light", "Turn-off");
goto_page->execute("screensaver");
output:
# Output required by `display_light` to send the commands to Nextion
- id: display_output
platform: template
type: float
write_action:
- lambda: |-
ESP_LOGV("output.display_output", "state: %f", state);
const uint8_t current_brightness = int(round(display_light->current_values.is_on() ? (display_light->current_values.get_brightness() * 100.0f) : 0.0));
ESP_LOGV("output.display_output", "current_brightness: %i%%", current_brightness);
set_brightness->execute(current_brightness);
script:
# Updates the existing `page_changed` script to update the `display_light` status when a page changes
- id: !extend page_changed
then:
- lambda: |-
ESP_LOGV("script.page_changed(custom)", "page: %s", current_page->state.c_str());
ESP_LOGV("script.page_changed(custom)", "is_on(): %s", YESNO(display_light->current_values.is_on()));
if (current_page->state == "screensaver" and display_light->current_values.is_on()) {
ESP_LOGV("script.page_changed(custom)", "Turning off light.");
auto call = display_light->turn_off();
call.perform();
} else if (current_page->state != "screensaver" and (not display_light->current_values.is_on())) {
ESP_LOGV("script.page_changed(custom)", "Turning on light.");
auto call = display_light->turn_on();
call.perform();
}
# Updates the existing `set_brightness` script to update the `display_light` status when a new brightness level is set
- id: !extend set_brightness
then:
- lambda: |-
ESP_LOGV("script.set_brightness(custom)", "brightness: %.0f%%", brightness);
uint8_t current_light_brightness = int(round(display_light->current_values.is_on() ? (display_light->current_values.get_brightness() * 100.0f) : 0.0));
ESP_LOGV("script.set_brightness(custom)", "current_light_brightness: %i%%", current_light_brightness);
if (brightness != current_light_brightness) {
if (current_page->state != "screensaver" and brightness > 0) {
ESP_LOGV("script.set_brightness(custom)", "Adjusting light brightness to %.3f%%", brightness / 100.0f);
auto call = display_light->turn_on();
call.set_brightness(brightness / 100.0f);
call.perform();
} else if (display_light->current_values.is_on()) {
ESP_LOGV("script.set_brightness(custom)", "Turning off light.");
auto call = display_light->turn_off();
call.set_brightness(0);
call.perform();
}
}
If this works I will update the docs.
Could you please try this?
##Add the display as a light in Home Assistant start light: # Add the display as a light in Home Assistant - name: Display id: display_light icon: mdi:tablet-dashboard platform: monochromatic output: display_output default_transition_length: 0s on_turn_on: then: - lambda: |- ESP_LOGD("light.display_light", "Turn-on"); if (current_page->state == "screensaver") disp1->goto_page(wakeup_page_name->state.c_str()); timer_reset_all->execute(); on_turn_off: then: - lambda: |- ESP_LOGD("light.display_light", "Turn-off"); goto_page->execute("screensaver"); output: # Output required by `display_light` to send the commands to Nextion - id: display_output platform: template type: float write_action: - lambda: |- ESP_LOGV("output.display_output", "state: %f", state); const uint8_t current_brightness = int(round(display_light->current_values.is_on() ? (display_light->current_values.get_brightness() * 100.0f) : 0.0)); ESP_LOGV("output.display_output", "current_brightness: %i%%", current_brightness); set_brightness->execute(current_brightness); script: # Updates the existing `page_changed` script to update the `display_light` status when a page changes - id: !extend page_changed then: - lambda: |- ESP_LOGV("script.page_changed(custom)", "page: %s", current_page->state.c_str()); ESP_LOGV("script.page_changed(custom)", "is_on(): %s", YESNO(display_light->current_values.is_on())); if (current_page->state == "screensaver" and display_light->current_values.is_on()) { ESP_LOGV("script.page_changed(custom)", "Turning off light."); auto call = display_light->turn_off(); call.perform(); } else if (current_page->state != "screensaver" and (not display_light->current_values.is_on())) { ESP_LOGV("script.page_changed(custom)", "Turning on light."); auto call = display_light->turn_on(); call.perform(); } # Updates the existing `set_brightness` script to update the `display_light` status when a new brightness level is set - id: !extend set_brightness then: - lambda: |- ESP_LOGV("script.set_brightness(custom)", "brightness: %.0f%%", brightness); uint8_t current_light_brightness = int(round(display_light->current_values.is_on() ? (display_light->current_values.get_brightness() * 100.0f) : 0.0)); ESP_LOGV("script.set_brightness(custom)", "current_light_brightness: %i%%", current_light_brightness); if (brightness != current_light_brightness) { if (current_page->state != "screensaver" and brightness > 0) { ESP_LOGV("script.set_brightness(custom)", "Adjusting light brightness to %.3f%%", brightness / 100.0f); auto call = display_light->turn_on(); call.set_brightness(brightness / 100.0f); call.perform(); } else if (display_light->current_values.is_on()) { ESP_LOGV("script.set_brightness(custom)", "Turning off light."); auto call = display_light->turn_off(); call.set_brightness(0); call.perform(); } }
If this works I will update the docs.
Sorry for the late reply. I spent the afternoon testing the new configuration on my NSPlane, and they are working very well. Thanks! I think this Issue can be closed.
TFT Version
4.3.5 and later
ESPHome Version
4.3.5 and later
Blueprint Version
4.3.5 and later
Panel Model
EU
What is the bug?
When the page is in screensaver mode, if you open the screen, it will immediately revert back to screensaver mode. Additionally, because I'm using the 'Set display as a light' option, when the 'Display Brightness Sleep' value is set to 0, the screen will automatically turn off after opening it. When the 'Display Brightness Sleep' is set to a non-zero value, the screen brightness will apply the 'Display Brightness Sleep' value. Only when the screen is clicked will the brightness momentarily apply the 'Display Brightness' value, after which it will immediately revert back to the value set for 'Display Brightness Sleep'.
Steps to Reproduce
1.Use the "Set display as a light" setting. 2.Wait for the interface to change to screensaver after the update. 3.Try different combinations of Display Brightness Sleep and Display Brightness values and operate them. 4.Observe the changes in screen brightness.
Your Panel's YAML
ESPHome Logs
No response
Home Assistant Logs
No response