Updated (EN) Customization (markdown)
@@ -298,3 +298,72 @@ button:
|
|||||||
id(timer_sleep).execute(id(wakeup_page_name).state.c_str(), int(id(timeout_sleep).state));
|
id(timer_sleep).execute(id(wakeup_page_name).state.c_str(), int(id(timeout_sleep).state));
|
||||||
id(timer_dim).execute(id(wakeup_page_name).state.c_str(), int(id(timeout_dim).state));
|
id(timer_dim).execute(id(wakeup_page_name).state.c_str(), int(id(timeout_dim).state));
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Set display as a light
|
||||||
|
> Requires v4.1 or higher
|
||||||
|
|
||||||
|
You can set your display as a light in Home Assistant, so you can control the brightness and turn on/off just like any other light, and even use this in your automation to control when your panel is on with the same automation you use for your lights:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
light:
|
||||||
|
# Add the display as a light in Home Assistant
|
||||||
|
- name: ${device_name} Display
|
||||||
|
id: display_light
|
||||||
|
icon: mdi:tablet-dashboard
|
||||||
|
platform: monochromatic
|
||||||
|
output: display_output
|
||||||
|
default_transition_length: 0s
|
||||||
|
on_turn_on:
|
||||||
|
then:
|
||||||
|
- lambda: |-
|
||||||
|
ESP_LOGV("light.display_light", "Turn-on");
|
||||||
|
if (id(current_page).state == "screensaver") id(disp1).goto_page(id(wakeup_page_name).state.c_str());
|
||||||
|
id(timer_reset_all).execute(id(wakeup_page_name).state.c_str());
|
||||||
|
on_turn_off:
|
||||||
|
then:
|
||||||
|
- lambda: |-
|
||||||
|
ESP_LOGV("light.display_light", "Turn-off");
|
||||||
|
id(disp1).goto_page("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);
|
||||||
|
uint current_brightness = int(round(id(display_light).current_values.is_on() ? (id(display_light).current_values.get_brightness() * 100.0f) : 0.0));
|
||||||
|
ESP_LOGV("output.display_output", "current_brightness: %i%%", current_brightness);
|
||||||
|
id(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", page.c_str());
|
||||||
|
ESP_LOGV("script.page_changed(custom)", "is_on(): %i", id(display_light).current_values.is_on() ? 1 : 0);
|
||||||
|
if (page == "screensaver" and id(display_light).current_values.is_on()) {
|
||||||
|
auto call = id(display_light).turn_off();
|
||||||
|
call.perform();
|
||||||
|
} else if (page != "screensaver" and (not id(display_light).current_values.is_on())) {
|
||||||
|
auto call = id(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_LOGD("script.set_brightness(custom)", "brightness: %i", brightness);
|
||||||
|
if (id(current_page).state != "screensaver" and brightness > 0) {
|
||||||
|
auto call = id(display_light).turn_on();
|
||||||
|
call.set_brightness(static_cast<float>(id(display_last_brightness)) / 100.0f);
|
||||||
|
call.perform();
|
||||||
|
} else {
|
||||||
|
auto call = id(display_light).turn_off();
|
||||||
|
call.perform();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user