-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathnspanel_esphome_page_button.yaml
More file actions
81 lines (71 loc) · 3.14 KB
/
nspanel_esphome_page_button.yaml
File metadata and controls
81 lines (71 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#####################################################################################################
##### NSPanel Easy - https://github.com/edwardtfn/NSPanel-Easy #####
#####################################################################################################
##### ESPHOME Page button #####
##### PLEASE only make changes if it is necessary and also the required knowledge is available. #####
##### For normal use with the Blueprint, no changes are necessary. #####
#####################################################################################################
---
substitutions:
PAGE_BUTTON_ID: 33
page_button_color_idle: 16904
page_button_color_pressed: 15483
page_button_color_unavail: 10565
page_button_color_ring: 21162
TAG_PAGE_BUTTON: nspanel.page.button
esphome:
platformio_options:
build_flags:
- -D NSPANEL_EASY_PAGE_BUTTON
script:
- id: !extend event_from_display # Defined by hw_display
then:
- lambda: |-
if (params_count == 0 || params[0] != "button") return;
// CSV Format: button,<action>
// params[0]=page, params[1]=action (action to perform)
if (params_count != 2) {
ESP_LOGW("${TAG_PAGE_BUTTON}", "Bad params");
return;
}
if (detailed_entity == nullptr or detailed_entity->state.empty()) {
ESP_LOGW("${TAG_PAGE_BUTTON}", "No detailed entity");
return;
}
const std::string& action = params[1];
ESP_LOGV("${TAG_PAGE_BUTTON}", "Button action: %s", action.c_str());
if (action != "press") {
ESP_LOGW("${TAG_PAGE_BUTTON}", "Unsupported action: %s", action.c_str());
return;
}
const HomeAssistantEntity entity = extractHomeAssistantEntity(detailed_entity->state);
if (entity.domain == "invalid") {
ESP_LOGW("${TAG_PAGE_BUTTON}", "Invalid entity: %s", detailed_entity->state.c_str());
return;
}
if (entity.domain != "button" && entity.domain != "input_button") {
ESP_LOGW("${TAG_PAGE_BUTTON}", "Unsupported entity domain for button page: %s", entity.domain.c_str());
return;
}
const std::string service = entity.domain + "." + action;
fire_ha_event("action_call", {
{"action", service.c_str()},
{"entity", detailed_entity->state.c_str()}
});
- id: !extend page_change
then:
- lambda: |-
if (new_page_id == get_page_id("button"))
page_button->execute();
- id: page_button
mode: single
then:
- lambda: |-
disp1->set_component_value("color_idle", ${page_button_color_idle});
disp1->set_component_value("color_pressed", ${page_button_color_pressed});
disp1->set_component_value("color_unavail", ${page_button_color_unavail});
disp1->set_component_value("color_ring", ${page_button_color_ring});
- id: !extend stop_page_constructors
then:
- lambda: page_button->stop();
...