diff --git a/esphome/nspanel_esphome_core.yaml b/esphome/nspanel_esphome_core.yaml index ba48037..6a6366f 100644 --- a/esphome/nspanel_esphome_core.yaml +++ b/esphome/nspanel_esphome_core.yaml @@ -1608,6 +1608,24 @@ switch: entity_category: config optimistic: true restore_mode: ALWAYS_OFF + on_turn_on: + lambda: |- + esphome::api::CustomAPIDevice ha_event; + ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint", { + {"device_name", device_name->state.c_str()}, + {"type", "notification_changed"}, + {"component", "notification_unread"}, + {"action", "turn_on"} + }); + on_turn_off: + lambda: |- + esphome::api::CustomAPIDevice ha_event; + ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint", { + {"device_name", device_name->state.c_str()}, + {"type", "notification_changed"}, + {"component", "notification_unread"}, + {"action", "turn_off"} + }); ##### Notification sound ##### - name: Notification sound @@ -1738,10 +1756,28 @@ text_sensor: - id: notification_label name: Notification Label platform: template + on_value: + lambda: |- + esphome::api::CustomAPIDevice ha_event; + ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint", { + {"device_name", device_name->state.c_str()}, + {"type", "notification_changed"}, + {"component", "notification_label"}, + {"action", "new_value"} + }); - id: notification_text name: Notification Text platform: template + on_value: + lambda: |- + esphome::api::CustomAPIDevice ha_event; + ha_event.fire_homeassistant_event("esphome.nspanel_ha_blueprint", { + {"device_name", device_name->state.c_str()}, + {"type", "notification_changed"}, + {"component", "notification_text"}, + {"action", "new_value"} + }); ##### NSPanel event - Execute actions from ESPHome - NO push to HA ##### - id: disp1_local_event diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 16575bf..cdcc1c2 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -3287,19 +3287,6 @@ trigger_variables: else ("sensor." ~ device_name ~ "_device_name") }} - left_button: > - {{ - nspanel_entities | selectattr(None, "search", "binary_sensor.*_left_button") | list | last - if nspanel_entities | selectattr(None, "search", "binary_sensor.*_left_button") | list | count > 0 - else ("binary_sensor." ~ device_name ~ "_left_button") - }} - right_button: > - {{ - nspanel_entities | selectattr(None, "search", "binary_sensor.*_right_button") | list | last - if nspanel_entities | selectattr(None, "search", "binary_sensor.*_right_button") | list | count > 0 - else ("binary_sensor." ~ device_name ~ "_right_button") - }} - relay01_entity: > {{ nspanel_entities | selectattr(None, "search", "switch.*_relay_1") | list | last @@ -3313,12 +3300,6 @@ trigger_variables: else ("switch." ~ device_name ~ "_relay_2") }} - blueprint_entity: > - {{ - nspanel_entities | selectattr(None, "search", "binary_sensor.*_blueprint") | list | last - if nspanel_entities | selectattr(None, "search", "binary_sensor.*_blueprint") | list | count > 0 - else ("binary_sensor." ~ device_name ~ "_blueprint") - }} currentpage: > {{ nspanel_entities | selectattr(None, "search", "sensor.*_current_page") | list | last @@ -3331,12 +3312,6 @@ trigger_variables: if nspanel_entities | selectattr(None, "search", "sensor.*_detailed_entity") | list | count > 0 else ("sensor." ~ device_name ~ "_detailed_entity") }} - nextion_inited: > - {{ - nspanel_entities | selectattr(None, "search", "binary_sensor.*_nextion_display") | list | last - if nspanel_entities | selectattr(None, "search", "binary_sensor.*_nextion_display") | list | count > 0 - else ("binary_sensor." ~ device_name ~ "_nextion_display") - }} nspaneltemp: > {{ @@ -3345,20 +3320,6 @@ trigger_variables: else ("sensor." ~ device_name ~ "_temperature") }} - notification_text: > - {{ - nspanel_entities | selectattr(None, "search", "sensor.*_notification_text") | list | last - if nspanel_entities | selectattr(None, "search", "sensor.*_notification_text") | list | count > 0 - else ("sensor." ~ device_name ~ "_notification_text") - }} - - notification_unread: > - {{ - nspanel_entities | selectattr(None, "search", "switch.*_notification_unread") | list | last - if nspanel_entities | selectattr(None, "search", "switch.*_notification_unread") | list | count > 0 - else ("switch." ~ device_name ~ "_notification_unread") - }} - thermostat_embedded: > {{ nspanel_entities | selectattr(None, "search", "climate.*_thermostat") | list | last @@ -3849,14 +3810,6 @@ trigger: entity_id: !input 'home_value04' id: home_values_state - ##### Trigger - Home - Notification ####################################################################################################################### - - platform: template - value_template: '{{ states(notification_text) }}' - id: notification_changed - - platform: template - value_template: '{{ states(notification_unread) }}' - id: notification_changed - ##### Trigger - Home - Custom buttons - State change ################################################################################################################# ##### Custom button 01 ##### - platform: event @@ -8202,6 +8155,8 @@ action: notification_icon_color_normal: !input home_button04_icon_color01 notification_icon_color_unread: !input home_button04_icon_color02 bt_notific_icon: !input home_button04_icon + notification_text: 'sensor.{{ nspanel_name }}_notification_text' + notification_unread: 'switch.{{ nspanel_name }}_notification_unread' notification_text_state: '{{ states(notification_text) if has_value(notification_text) else "" }}' notification_unread_state: '{{ states(notification_unread) | default(true) }}' notification_visible: '{{ notification_text_state is string and notification_text_state | length > 0 }}' @@ -10314,6 +10269,13 @@ action: continue_on_error: true # yamllint enable rule:line-length + ##### Notification changed ##### + - alias: Notification changed + conditions: + - '{{ nspanel_event.type == "notification_changed"}}' + sequence: + - *refresh_page_home_notification_button + ##### Other events ##### - alias: Other events conditions: @@ -10353,6 +10315,8 @@ action: - automation_reloaded - ha_started sequence: + - variables: + nextion_inited: 'binary_sensor.{{ nspanel_name }}_nextion_display' - delay: > # Prevents all panels updating simultaneously in large systems {% set entities_list = states.binary_sensor | selectattr("entity_id", "search", "nextion_display") | map(attribute="entity_id") | list %} {{ (4 * entities_list.index(nextion_inited)) if (entities_list | count > 0 and nextion_inited in entities_list) else 0 }} @@ -10649,14 +10613,6 @@ action: sequence: - *display_home_page_status_bar - ##### Home page - Notification changed ###### - - alias: Home page - Notification changed - conditions: - - condition: trigger - id: notification_changed - sequence: - - *variables_home_page_notify_button - ##### HW BUTTON - state ##### - alias: Hardware button - State conditions: