Skip to content

Commit

Permalink
Home page values update with same engine as chips
Browse files Browse the repository at this point in the history
Solves #963
  • Loading branch information
edwardtfn committed Dec 16, 2023
1 parent 17115e0 commit d29c638
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 59 deletions.
9 changes: 4 additions & 5 deletions advanced/esphome/nspanel_esphome_core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,8 @@ api:
disp1->send_command_printf("%stext.picc=%u", id.c_str(), bg_pic);
disp1->send_command_printf("%sicon.picc=%u", id.c_str(), bg_pic);
disp1->send_command_printf("%sicon.font=%" PRIu32, id.c_str(), icon_font);
disp1->send_command_printf("%sbri.pco=%u", id.c_str(), txt_color);
disp1->send_command_printf("%stext.pco=%u", id.c_str(), txt_color);
disp1->set_component_foreground_color(btnbri.c_str(), txt_color);
disp1->set_component_foreground_color(btntext.c_str(), txt_color);
set_component_color->execute(btnicon.c_str(), icon_color);
disp1->set_component_text_printf(btnicon.c_str(), "%s", icon.c_str());
display_wrapped_text->execute(btntext.c_str(), label.c_str(), 10);
Expand All @@ -529,7 +529,6 @@ api:
ESP_LOGW(TAG, "Skipping button `%s.%s` as page has changed to %s.", page.c_str(), id.c_str(), current_page->state.c_str());
}
##### SERVICE TO WAKE UP THE DISPLAY #####
- service: wake_up
variables:
Expand Down Expand Up @@ -670,12 +669,12 @@ api:
// on/off button
if (supported_features & 128 and state == "off") //TURN_ON
{
disp1->set_component_color("bt_on_off", 65535);
disp1->set_component_foreground_color("bt_on_off", 65535);
disp1->show_component("bt_on_off");
}
else if (supported_features & 256 and state != "off") //TURN_OFF
{
disp1->set_component_color("bt_on_off", 10597);
disp1->set_component_foreground_color("bt_on_off", 10597);
disp1->show_component("bt_on_off");
}
else disp1->hide_component("bt_on_off");
Expand Down
96 changes: 42 additions & 54 deletions nspanel_blueprint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6405,27 +6405,24 @@ trigger:
##### Trigger - Home - Values - State change #################################################################################################################

##### HOME Value 01 - Trigger 'home_value01_state' #####
- platform: state
entity_id: !input 'home_value01'
not_to:
- unknown
- unavailable
- platform: event
event_type: state_changed
event_data:
entity_id: !input 'home_value01'
id: home_value01_state

##### HOME Value 02 - Trigger 'home_value02_state' #####
- platform: state
entity_id: !input 'home_value02'
not_to:
- unknown
- unavailable
- platform: event
event_type: state_changed
event_data:
entity_id: !input 'home_value02'
id: home_value02_state

##### HOME Value 03 - Trigger 'home_value03_state' #####
- platform: state
entity_id: !input 'home_value03'
not_to:
- unknown
- unavailable
- platform: event
event_type: state_changed
event_data:
entity_id: !input 'home_value03'
id: home_value03_state

##### Trigger - Home - Custom buttons - State change #################################################################################################################
Expand Down Expand Up @@ -6774,14 +6771,15 @@ action:
if entity_icon_color is sequence and entity_icon_color | count == 3
else entity_icon_color
}}
entity_state_is_number: '{{ is_number(entity_state) }}'
entity:
id: '{{ entity_id }}'
valid: '{{ entity_id_is_valid }}'
has_value: '{{ has_value(entity_id) if entity_id_is_valid else false }}'
state: '{{ entity_state }}'
state_is_number: '{{ is_number(entity_state) }}'
state_is_number: '{{ entity_state_is_number }}'
domain: '{{ entity_domain }}'
unit_of_measurement: '{{ state_attr(entity_id, "unit_of_measurement") | default(None) if entity_id_is_valid else None }}'
unit_of_measurement: '{{ state_attr(entity_id, "unit_of_measurement") | default(None) if entity_id_is_valid and entity_state_is_number else None }}'
friendly_name: >
{{
overlap.frendly_name
Expand Down Expand Up @@ -7504,55 +7502,45 @@ action:
- &display_value
if: '{{ repeat.item.entity is string and repeat.item.entity is match "sensor." and has_value(repeat.item.entity) }}'
then:
- if: '{{ repeat.item.icon | length > 0 }}'
- variables:
entity_id: '{{ repeat.item.entity }}'
overlap:
icon: '{{ repeat.item.icon }}'
icon_color: '{{ repeat.item.icon_color_rgb }}'
- *variable_entity
- if: '{{ entity.has_value }}'
then:
### ICON Font Color ###
- *delay-default
- service: '{{ nextion.command.set_component_color }}'
data:
component: '{{ repeat.item.page }}.{{ repeat.item.component }}_icon'
foreground: '{{ [ repeat.item.icon_color_rgb ] if is_number(repeat.item.icon_color_rgb) else repeat.item.icon_color_rgb }}'
foreground: '{{ entity.icon_color }}'
continue_on_error: true
### ICON Font ###
- *delay-default
- service: '{{ nextion.command.text_printf }}'
data:
component: '{{ repeat.item.page }}.{{ repeat.item.component }}_icon'
message: >
{% if repeat.item.icon is string and repeat.item.icon | length > 0 %}
{{
all_icons[repeat.item.icon.split(":")[1]] | default(all_icons.unknown)
if repeat.item.icon.split(":") | count > 0
else repeat.item.icon
}}
{% elif state_attr(repeat.item.entity, "icon") | default("") not in ["unavailable", "unknown", "", None] %}
{{ all_icons[state_attr(repeat.item.entity, "icon").split(":")[1]] | default(all_icons.unknown) }}
{% else %}{{ all_icons.blank }}
{% endif %}
message: '{{ entity.icon }}'
continue_on_error: true
### Show value ###
- variables:
repeat_item_state: '{{ states(entity.entity_id, rounded=true) | default("unavailable") }}'
### LABEL Font Color ###
- *delay-default
- service: '{{ nextion.command.set_component_color }}'
data:
component: '{{ repeat.item.page }}.{{ repeat.item.component }}{{ "_state" if repeat.item.page == page.home }}'
foreground: '{{ [ repeat.item.label_color_rgb ] if is_number(repeat.item.label_color_rgb) else repeat.item.label_color_rgb }}'
continue_on_error: true
### LABEL Font ###
- *delay-default
- service: '{{ nextion.command.text_printf }}'
data:
component: '{{ repeat.item.page }}.{{ repeat.item.component }}{{ "_state" if repeat.item.page == page.home }}'
message: '{{ repeat_item_state ~ entity.unit_of_measurement }}'
continue_on_error: true
- variables:
repeat_item_state: '{{ states(repeat.item.entity, rounded=true) | default("unavailable") }}'
repeat_item_state_available: '{{ repeat_item_state not in ["unavailable", "unknown", "", None] }}'
- condition: '{{ repeat_item_state_available }}'
### LABEL Font Color ###
- *delay-default
- service: '{{ nextion.command.set_component_color }}'
data:
component: '{{ repeat.item.page }}.{{ repeat.item.component }}{{ "_state" if repeat.item.page == page.home }}'
foreground: '{{ [ repeat.item.label_color_rgb ] if is_number(repeat.item.label_color_rgb) else repeat.item.label_color_rgb }}'
continue_on_error: true
### LABEL Font ###
- *delay-default
- service: '{{ nextion.command.text_printf }}'
data:
component: '{{ repeat.item.page }}.{{ repeat.item.component }}{{ "_state" if repeat.item.page == page.home }}'
message: >
{{
(repeat_item_state ~ (state_attr(repeat.item.entity, "unit_of_measurement") | default("") if state_attr(repeat.item.entity, "unit_of_measurement") is string else ""))
if is_number(repeat_item_state)
else repeat_item_state
}}
continue_on_error: true

## BUTTON PAGES 01 - 04 ##
- alias: Button pages
Expand Down Expand Up @@ -9715,7 +9703,7 @@ action:
sequence:
- *variables-home_page_values
- repeat:
for_each: '{{ home_page_values | selectattr("entity", "defined") | selectattr("entity", "eq", trigger.entity_id) | list }}'
for_each: '{{ home_page_values | selectattr("entity", "defined") | selectattr("entity", "eq", trigger.event.data.entity_id) | list }}'
sequence:
- *display_value

Expand Down

0 comments on commit d29c638

Please sign in to comment.