Merge pull request #676 from deejaybeam/dev

upd: set_entity-service
This commit is contained in:
Chris
2023-04-14 23:23:01 +02:00
committed by GitHub
2 changed files with 27 additions and 18 deletions

View File

@@ -2383,6 +2383,7 @@ variables:
show_all: "esphome.{{ nspanel_name }}_send_command_show_all"
tft_upload: "esphome.{{ nspanel_name }}_upload_tft"
set_button: "esphome.{{ nspanel_name }}_set_button"
set_entity: "esphome.{{ nspanel_name }}_set_entity"
icons:
battery: "\U0000F2A1" #F2A1
blank: "\U0000FFFF" #blank macbook bug
@@ -4815,30 +4816,18 @@ action:
{% if repeat.item.icon is string and repeat.item.icon | length > 0 %}{{ nextion.icons.all[repeat.item.icon.split(':')[1]] | default(repeat.item.icon) }}
{% elif state_attr(repeat.item.entity, 'icon') | default('') not in ['unavailable', 'unknown', '', None] %}{{ nextion.icons.all[state_attr(repeat.item.entity, 'icon').split(':')[1]] | default(None) }}
{% endif %}
- if: "{{ repeat_item_icon is string and repeat_item_icon | length > 0 }}"
then:
- *delay-default
- service: "{{ nextion.commands.text_printf }}"
data:
component: "{{ repeat.item.component }}_pic"
message: "{{ repeat_item_icon }}"
continue_on_error: true
- *delay-default
- service: "{{ nextion.commands.text_printf }}"
- service: "{{ nextion.commands.set_entity }}"
data:
component: "{{ repeat.item.component }}_label"
message: >-
ent_id: "{{ repeat.item.component }}"
ent_icon: "{{ repeat_item_icon }}"
ent_label: >-
{%- if repeat.item.name | length > 0 -%} {{ repeat.item.name }}
{%- elif repeat_item_state in ['unavailable', 'unknown', None] -%} {{ repeat.item.entity }}
{%- else -%} {{ state_attr(repeat.item.entity, 'friendly_name') | default(mui[language].no_name) }}
{%- endif -%}
ent_value: "{{ repeat_item_state ~ ((state_attr(repeat.item.entity, 'unit_of_measurement') | default('')) if state_attr(repeat.item.entity, 'unit_of_measurement') else '') }}"
continue_on_error: true
- *delay-default
- service: "{{ nextion.commands.text_printf }}"
data:
component: "{{ repeat.item.component }}"
message: "{{ repeat_item_state ~ ((state_attr(repeat.item.entity, 'unit_of_measurement') | default('')) if state_attr(repeat.item.entity, 'unit_of_measurement') else '') }}"
continue_on_error: true
## PAGE CLIMATE ##
- alias: Climate page

View File

@@ -355,6 +355,26 @@ api:
} else {
id(disp1).set_component_text_printf(btnbri.c_str(), " ");
}
#### Service to set the entities ####
- service: set_entity
variables:
ent_id: string
ent_icon: string
ent_label: string
ent_value: string
then:
- wait_until:
switch.is_on: nextion_init
- lambda: |-
// ESP_LOGD("nextion", "set entity %s", ent_id.c_str());
std::string enticon = ent_id.c_str() + std::string("_pic");
std::string entlabel = ent_id.c_str() + std::string("_label");
id(disp1).set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str());
if (strcmp(ent_icon.c_str(), "0") != 0) {
id(disp1).set_component_text_printf(enticon.c_str(), "%s", ent_icon.c_str());
}
id(disp1).set_component_text_printf(entlabel.c_str(), "%s", ent_label.c_str());
id(disp1).set_component_text_printf(ent_id.c_str(), "%s", ent_value.c_str());
##### START - GLOBALS CONFIGURATION #####
globals: