diff --git a/ReleaseNotes.md b/ReleaseNotes.md index e6e280a..419d8b3 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -26,6 +26,7 @@ Since in this update lots of input to the blueprint changed, we highly recommend ## Breaking changes 1. New requirement: Home Assistant 2023.5.0 or later 2. Exisiting users will have o select again the language for the panel, otherwise the automation will throw an error in the log related to the previous language selection. +3. Removed entity `sensor.xxxxx_settings_entity` and service `esphome.xxxxx_set_settings_entity`   ## Overview of all changes @@ -33,6 +34,8 @@ Since in this update lots of input to the blueprint changed, we highly recommend 2. Support to sensor display precision from Home Assistant (#880) 3. Filtered device list (#881) 4. New language selector (#882) +5. Removed `settings_entity` +   ## Details of all changes @@ -61,6 +64,11 @@ Althougt this is not visible for users at the first view, it will enable the use => If you are an existing users, please remember to select your language again after the update, as the previous selection will be invalid.   +### 5. Removed `settings_entity` +The entity `sensor.xxxxx_settings_entity` was previously used by ESPHome to to transfer information about the selected entity on the settings page to the Blueprint, enabling the transfer of settings from different instances of the blueprint with the use of service `esphome.xxxxx_set_settings_entity`. This mechanism was a bit fragile and not user friendly. +With this version the information about the entity shown will be part of the `sensor.xxxxx_nspanel_event` and the settings pages will be called with the service `esphome.xxxxx_open_entity_settings_page`. +Apart of a cleaner device page, this change should be transparent for most users. If you have made automations based on the removed elements, please update it using the new service. + ## Next topics we are currently working on See here: https://github.com/Blackymas/NSPanel_HA_Blueprint/labels/roadmap diff --git a/nspanel_blueprint.yaml b/nspanel_blueprint.yaml index 277636c..afa125c 100644 --- a/nspanel_blueprint.yaml +++ b/nspanel_blueprint.yaml @@ -3459,7 +3459,6 @@ trigger_variables: relay01_entity: 'switch.{{ nspanel_name }}_relay_1' relay02_entity: 'switch.{{ nspanel_name }}_relay_2' nspaneltemp: 'sensor.{{ nspanel_name }}_temperature' - settings_entity: 'sensor.{{ nspanel_name }}_settings_entity' reboot_button: 'button.{{ nspanel_name }}_restart' switch_sleep_mode: 'switch.{{ nspanel_name }}_sleep_mode' @@ -3526,7 +3525,7 @@ variables: notification_show: 'esphome.{{ nspanel_name }}_notification_show' notification_clear: 'esphome.{{ nspanel_name }}_notification_clear' play_rtttl: 'esphome.{{ nspanel_name }}_play_rtttl' - set_settings_entity: 'esphome.{{ nspanel_name }}_set_settings_entity' + open_entity_settings_page: 'esphome.{{ nspanel_name }}_open_entity_settings_page' hide: 'esphome.{{ nspanel_name }}_send_command_hide' show: 'esphome.{{ nspanel_name }}_send_command_show' show_all: 'esphome.{{ nspanel_name }}_send_command_show_all' @@ -3559,12 +3558,6 @@ variables: gauge: "\uE299" #E299 unknown: '{{ all_icons.unknown }}' #"\uE2D5" pic: - hvac: - button: - blank: "79" - "off": "80" - "on": "81" - unknown: "79" hardware: button: "off": "77" @@ -3578,10 +3571,6 @@ variables: button: "off": "101" "on": "102" - heating: - button: - "off": "82" - "on": "83" weather: sunny: '{{ "2" if sun_is_up else "15"}}' #some weather providers returns "sunny" for "clear-night" cloudy: "3" @@ -3615,8 +3604,8 @@ variables: settings: "settings" boot: "boot" screensaver: "screensaver" - light: "lightsettings" - cover: "coversettings" + light: "light" + cover: "cover" buttonpages: - "buttonpage01" - "buttonpage02" @@ -5357,13 +5346,6 @@ variables: trigger: ##### Trigger - General ################################################################################################################# - ##### settings_entity - Trigger 'settings_entity' ##### - - platform: event - event_type: state_changed - event_data: - entity_id: '{{ settings_entity }}' - id: settings_entity - ##### Reboot - Trigger 'nspanel_boot_init' ##### - platform: template value_template: '{{ is_state(nextion_inited, "on") | default(false) if nextion_inited is string else false }}' @@ -5990,50 +5972,6 @@ condition: action: - alias: Main choices choose: - ##### JUMP TO - settings page lightsettings /coversettings / climate (SETTINGS ENTITY CHANGED) ##### - - alias: 'Jump to light/cover/climate settings page' - conditions: - - condition: trigger - id: settings_entity - - '{{ trigger.event.data.new_state.state not in ["unavailable", "unknown", "", None] }}' - sequence: - - &variables-settings_entity - variables: - settings_entity_state: > - {{ - states(settings_entity) - if settings_entity is string and has_value(settings_entity) - else "unknown" - }} - settings_entity_dict: > - {{ - settings_entity_state - if settings_entity_state is mapping - else { "page": "home", "entity": "unknown" } - }} - settings_entity_domain: > - {{ - settings_entity_dict.entity.split(".")[0] - if - settings_entity_dict.entity is defined and - settings_entity_dict.entity is string and - settings_entity_dict.entity.split(".") | count > 0 - else "unknown" - }} - - if: '{{ settings_entity_domain in ["light", "cover", "climate"] }}' - then: - - service: '{{ nextion.command.printf }}' - data: - cmd: 'page {{ page[settings_entity_domain] }}' - continue_on_error: true - - &delay-default - delay: - milliseconds: '{{ delay_value }}' - - service: '{{ nextion.command.printf }}' # This can be moved to TFT on the 3 settings pages (and why not all pages?) and reduce the load from Blueprint comms - data: - cmd: 'dim=home.brightness.val' - continue_on_error: true - ##### DATE AND TIME ##### - alias: 'Date & Time' conditions: @@ -6055,7 +5993,9 @@ action: else ((page_home.general.date.label.color_rgb[0] //(2**3)) *(2**11))+((page_home.general.date.label.color_rgb[1] //(2**2)) *(2**5))+(page_home.general.date.label.color_rgb[2] //(2**3)) }} continue_on_error: true - - *delay-default + - &delay-default + delay: + milliseconds: '{{ delay_value }}' ### DATE Font ### - service: '{{ nextion.command.text_printf }}' data: @@ -6183,11 +6123,6 @@ action: - alias: Home page conditions: '{{ nspanel_event.page == page.home }}' sequence: &refresh_page_home - - service: '{{ nextion.command.set_settings_entity }}' - data: - entity: '{{ nspanel_event }}' - continue_on_error: true - ##### Weather Icon Home Page ##### - *delay-default - &refresh-page_home-weather_pic @@ -6963,10 +6898,6 @@ action: component: button08 - if: '{{ button_page_index >= 0 and button_page_index <= 3 }}' then: - - service: '{{ nextion.command.set_settings_entity }}' - data: - entity: '{{ nspanel_event }}' - continue_on_error: true ##### Button Page Label ##### - if: '{{ button_pages_labels[button_page_index].label | length > 0 }}' then: @@ -7135,252 +7066,129 @@ action: - service: '{{ nextion.command.show_all }}' continue_on_error: true - ## PAGE LIGHTSETTINGS ## + ## PAGE LIGHT ## - alias: Light settings page conditions: '{{ nspanel_event.page == page.light }}' - sequence: &refresh_page_lightsettings - - *variables-settings_entity - - if: '{{ settings_entity_domain == "light" }}' - then: - - service: '{{ nextion.command.text_printf }}' - data: - component: lightsettings.light_name - message: > - {{ - settings_entity_dict.name - if settings_entity_dict.name is defined and settings_entity_dict.name is string and settings_entity_dict.name | length > 0 - else - ( - state_attr(settings_entity_dict.entity, "friendly_name") - if state_attr(settings_entity_dict.entity, "friendly_name") | length > 0 - else - ( - "Light" ~ (": " ~ settings_entity_dict.component) - if settings_entity_dict.component is string and settings_entity_dict.component | length > 0 - ) - ) - }} - continue_on_error: true - ##### LIGHT ICON - ON / OFF ##### - - *delay-default - - service: '{{ nextion.command.text_printf }}' - data: - component: lightsettings.icon_state - message: > - {{ - all_icons[settings_entity_dict.icon.split(":")[1]] | default(settings_entity_dict.icon if settings_entity_dict.icon is defined and settings_entity_dict.icon is string else nextion.icon.domain.light) - if settings_entity_dict.icon not in ["unavailable", "unknown", "", None] and settings_entity_dict.icon | length > 0 - else nextion.icon.domain.light - }} - continue_on_error: true - - *delay-default - - service: '{{ nextion.command.font_color }}' - data: - component: lightsettings.icon_state - message: > - {{ - ( - settings_entity_dict.icon_color_rgb - if is_number(settings_entity_dict.icon_color_rgb) - else - ((settings_entity_dict.icon_color_rgb[0] //(2**3)) *(2**11))+ - ((settings_entity_dict.icon_color_rgb[1] //(2**2)) *(2**5))+ - (settings_entity_dict.icon_color_rgb[2] //(2**3)) - ) - if is_state(settings_entity_dict.entity, "on") - else nextion.color.grey_light - }} - continue_on_error: true - ##### LIGHT State ##### - - variables: - curr_brightness: '{{ (state_attr(settings_entity_dict.entity, "brightness") | int(0) * 100 / 255) | round(0) }}' - - *delay-default - - service: '{{ nextion.command.value }}' - data: - component: lightsettings.lightslider - message: '{{ curr_brightness }}' - continue_on_error: true - - *delay-default - - service: '{{ nextion.command.text_printf }}' - data: - component: lightsettings.light_value - message: '{{ curr_brightness }}%' - continue_on_error: true - - *delay-default - - service: '{{ nextion.command.text_printf }}' - data: - component: lightsettings.light_value_2 - message: '{{ curr_brightness }}%' - continue_on_error: true + sequence: &refresh_page_light + ##### LIGHT State ##### + - variables: + curr_brightness: '{{ (state_attr(nspanel_event.entity, "brightness") | int(0) * 100 / 255) | round(0) }}' + - *delay-default + - service: '{{ nextion.command.value }}' + data: + component: light.lightslider + message: '{{ curr_brightness }}' + continue_on_error: true + - *delay-default + - service: '{{ nextion.command.text_printf }}' + data: + component: light.light_value + message: '{{ curr_brightness }}%' + continue_on_error: true + - *delay-default + - service: '{{ nextion.command.text_printf }}' + data: + component: light.light_value_2 + message: '{{ curr_brightness }}%' + continue_on_error: true - ##### LIGHT Check Color_Temp Value is available when yes send some current Values ##### - - variables: - curr_color_temp: '{{ state_attr(settings_entity_dict.entity, "color_temp") }}' - - condition: '{{ is_number(curr_color_temp) }}' - - *delay-default - - service: '{{ nextion.command.text_printf }}' - data: - component: lightsettings.temp_value - message: '{{ curr_color_temp | round(0) }}' - continue_on_error: true - - *delay-default - - service: '{{ nextion.command.text_printf }}' - data: - component: lightsettings.temp_value_2 - message: '{{ curr_color_temp | round(0) }}' - continue_on_error: true - - *delay-default - - service: '{{ nextion.command.value }}' - data: - component: lightsettings.tempslider - message: '{{ curr_color_temp | round(0) }}' - continue_on_error: true + ##### LIGHT Check Color_Temp Value is available when yes send some current Values ##### + - variables: + curr_color_temp: '{{ state_attr(nspanel_event.entity, "color_temp") }}' + - condition: '{{ is_number(curr_color_temp) }}' + - *delay-default + - service: '{{ nextion.command.text_printf }}' + data: + component: light.temp_value + message: '{{ curr_color_temp | round(0) }}' + continue_on_error: true + - *delay-default + - service: '{{ nextion.command.text_printf }}' + data: + component: light.temp_value_2 + message: '{{ curr_color_temp | round(0) }}' + continue_on_error: true + - *delay-default + - service: '{{ nextion.command.value }}' + data: + component: light.tempslider + message: '{{ curr_color_temp | round(0) }}' + continue_on_error: true - ## PAGE COVERSETTINGS ## + ## PAGE COVER ## - alias: Cover settings page conditions: '{{ nspanel_event.page == page.cover }}' - sequence: &refresh_page_coversettings - ##### COVER - OPEN / CLOSE ##### - - *variables-settings_entity - - if: '{{ settings_entity_domain == "cover" }}' + sequence: &refresh_page_cover + ##### COVER State + - service: '{{ nextion.command.value }}' + data: + component: cover.coverslider + message: '{{ (state_attr(nspanel_event.entity, "current_position") | int ) | round(0) }}' + continue_on_error: true + - *delay-default + - service: '{{ nextion.command.text_printf }}' + data: + component: cover.cover_value + message: '{{ (state_attr(nspanel_event.entity, "current_position") | int ) | round(0) }} %' + continue_on_error: true + + ##### COVER Battery ICON Yes / NO ##### + - variables: + battery_level: > + {% if state_attr(nspanel_event.entity, "battery") | default("unavailable") not in ["unavailable", "unknown", "", None] %} + {{ state_attr(nspanel_event.entity, "battery") | default("unavailable") }} + {% elif expand(device_entities(device_id(nspanel_event.entity))) + | selectattr("attributes.device_class", "defined") + | selectattr("attributes.device_class", "eq", "battery") + | map(attribute="state") + | map("float") + | list + | count > 0 %} + {{ + expand(device_entities(device_id(nspanel_event.entity))) + | selectattr("attributes.device_class", "defined") + | selectattr("attributes.device_class", "eq", "battery") + | map(attribute="state") | map("float") + | list + | first + | round(0) + }} + {% elif has_value(nspanel_event.entity | replace("cover.","sensor.") ~ "_battery") %} + {{ states(nspanel_event.entity | replace("cover.","sensor.") ~ "_battery", rounded=true) | default("unavailable") }} + {% elif has_value(nspanel_event.entity | replace("cover.","sensor.") | replace("cover", "battery")) %} + {{ states(nspanel_event.entity | replace("cover.","sensor.") | replace("cover", "battery"), rounded=true) | default("unavailable") }} + {% else %} unavailable + {% endif %} + - if: '{{ is_number(battery_level) }}' then: - *delay-default - service: '{{ nextion.command.text_printf }}' data: - component: coversettings.icon_state - message: > - {{ - all_icons[settings_entity_dict.icon.split(":")[1]] | default(settings_entity_dict.icon if settings_entity_dict.icon is defined and settings_entity_dict.icon is string else nextion.icon.domain.cover) - if settings_entity_dict.icon not in ["unavailable", "unknown", "", None] and settings_entity_dict.icon | length > 0 - else nextion.icon.domain.cover - }} + component: cover.battery_value + message: '{{ battery_level }} %' continue_on_error: true + ### ICON Battery Font Color ### - *delay-default - service: '{{ nextion.command.font_color }}' data: - component: coversettings.icon_state - message: > - {{ - ( - settings_entity_dict.icon_color_rgb - if is_number(settings_entity_dict.icon_color_rgb) - else - ((settings_entity_dict.icon_color_rgb[0] //(2**3)) *(2**11))+ - ((settings_entity_dict.icon_color_rgb[1] //(2**2)) *(2**5))+ - (settings_entity_dict.icon_color_rgb[2] //(2**3)) - ) - if states(settings_entity_dict.entity) in ["open", "opening"] - else nextion.color.grey_light - }} + component: cover.battery_icon + message: '{{ nextion.color.grey_super_light }}' continue_on_error: true + ### ICON Battery Font ### - *delay-default - service: '{{ nextion.command.text_printf }}' data: - component: coversettings.cover_name - message: > - {{ - settings_entity_dict.name - if - settings_entity_dict.name is defined - and settings_entity_dict.name is string - and settings_entity_dict.name | length > 0 - else - ( - state_attr(settings_entity_dict.entity, "friendly_name") - if state_attr(settings_entity_dict.entity, "friendly_name") | length > 0 - else settings_entity_dict.entity - ) - }} + component: cover.battery_icon + message: '{{ all_icons["battery-medium"] }}' continue_on_error: true - ##### COVER State - - service: '{{ nextion.command.value }}' - data: - component: coversettings.coverslider - message: '{{ (state_attr(settings_entity_dict.entity, "current_position") | int ) | round(0) }}' - continue_on_error: true - - *delay-default - - service: '{{ nextion.command.text_printf }}' - data: - component: coversettings.cover_value - message: '{{ (state_attr(settings_entity_dict.entity, "current_position") | int ) | round(0) }} %' - continue_on_error: true - - ##### COVER Battery ICON Yes / NO ##### - - variables: - battery_level: > - {% if state_attr(settings_entity_dict.entity, "battery") | default("unavailable") not in ["unavailable", "unknown", "", None] %} - {{ state_attr(settings_entity_dict.entity, "battery") | default("unavailable") }} - {% elif expand(device_entities(device_id(settings_entity_dict.entity))) - | selectattr("attributes.device_class", "defined") - | selectattr("attributes.device_class", "eq", "battery") - | map(attribute="state") - | map("float") - | list - | count > 0 %} - {{ - expand(device_entities(device_id(settings_entity_dict.entity))) - | selectattr("attributes.device_class", "defined") - | selectattr("attributes.device_class", "eq", "battery") - | map(attribute="state") | map("float") - | list - | first - | round(0) - }} - {% elif has_value(settings_entity_dict.entity | replace("cover.","sensor.") ~ "_battery") %} - {{ states(settings_entity_dict.entity | replace("cover.","sensor.") ~ "_battery", rounded=true) | default("unavailable") }} - {% elif has_value(settings_entity_dict.entity | replace("cover.","sensor.") | replace("cover", "battery")) %} - {{ states(settings_entity_dict.entity | replace("cover.","sensor.") | replace("cover", "battery"), rounded=true) | default("unavailable") }} - {% else %} unavailable - {% endif %} - - if: '{{ is_number(battery_level) }}' - then: - - *delay-default - - service: '{{ nextion.command.text_printf }}' - data: - component: coversettings.battery_value - message: '{{ battery_level }} %' - continue_on_error: true - ### ICON Battery Font Color ### - - *delay-default - - service: '{{ nextion.command.font_color }}' - data: - component: coversettings.battery_icon - message: '{{ nextion.color.grey_super_light }}' - continue_on_error: true - ### ICON Battery Font ### - - *delay-default - - service: '{{ nextion.command.text_printf }}' - data: - component: coversettings.battery_icon - message: '{{ all_icons["battery-medium"] }}' - continue_on_error: true - ## PAGE CLIMATE ## - alias: Climate page conditions: '{{ nspanel_event.page == page.climate }}' sequence: &refresh_page_climate - - *variables-settings_entity - &variables-climate_entity variables: - settings_entity_dict: > - {% if settings_entity_dict.entity is not defined and settings_entity_dict.page == page.home and settings_entity_dict.component == 'climate' %} - { - 'page': '{{ settings_entity_dict.page }}', - 'entity': '{{ climate }}', - 'name': > - {{ - state_attr(climate, "friendly_name") | default(mui[language].no_name) - if - climate is string and - state_attr(climate, "friendly_name") is string and - state_attr(climate, "friendly_name") | length > 0 - else climate - }} - } - {% else %}{{ settings_entity_dict }} - {% endif %} - climate_entity: '{{ settings_entity_dict.entity if settings_entity_dict.entity is defined }}' + climate_entity: '{{ nspanel_event.entity if nspanel_event.entity is defined }}' settings_entity_domain: > {{ climate_entity.split(".")[0] @@ -7394,13 +7202,6 @@ action: - if: '{{ settings_entity_domain == "climate" }}' then: - ##### Page title ##### - - service: '{{ nextion.command.text_printf }}' - data: - component: climate.climate_label - message: '{{ settings_entity_dict.name }}' - continue_on_error: true - ##### Values ##### - &variables-climate_page variables: @@ -7574,9 +7375,9 @@ action: data: component: '{{ repeat.item.component }}' continue_on_error: true - else: + #else: ##### Return to Home page in case is not a climate entity ##### - - *jump_page_home + #- *jump_page_home ## ENTITY PAGES 01 - 04 ## - alias: Entity pages @@ -8089,67 +7890,46 @@ action: message: '{{ qrcode_value }}' continue_on_error: true - ## PAGE SETTINGS ## - #- alias: Settings page - # conditions: '{{ nspanel_event.page == page.settings }}' - # sequence: - - ## PAGE BOOT ## - #- alias: Boot page - # conditions: '{{ nspanel_event.page == page.boot }}' - # sequence: - - ## PAGE SCREENSAVER ## - #- alias: Screensaver page - # conditions: '{{ nspanel_event.page == page.screensaver }}' - # sequence: - - - alias: Page close # general - conditions: '{{ nspanel_event.component == "close" and nspanel_event.value == "release" }}' + - alias: light settings # rgb_color, brightness, color_temp + conditions: + - '{{ nspanel_event.page == page.light }}' + - '{{ nspanel_event.component in ["rgb_color", "brightness_pct", "color_temp"] }}' + - '{{ nspanel_event.entity is defined and nspanel_event.entity is string and nspanel_event.entity | length > 0 }}' sequence: - - *variables-settings_entity - - service: '{{ nextion.command.printf }}' - data: - cmd: 'page {{ settings_entity_dict.page if settings_entity_dict.page is defined else page.home }}' - continue_on_error: true - - - alias: lightsetting # rgb_color, brightness, color_temp - conditions: '{{ nspanel_event.component in ["rgb_color", "brightness_pct", "color_temp"] }}' - sequence: - - *variables-settings_entity - - condition: '{{ settings_entity_dict.entity is defined and settings_entity_dict.entity is string }}' - service: light.turn_on data: - entity_id: '{{ settings_entity_dict.entity }}' + entity_id: '{{ nspanel_event.entity }}' '{{ nspanel_event.component }}': '{{ nspanel_event.value }}' continue_on_error: true - alias: coversetting position - conditions: '{{ nspanel_event.component == "cover_position" }}' + conditions: + - '{{ nspanel_event.component == "cover_position" }}' + - '{{ nspanel_event.entity is defined and nspanel_event.entity is string and nspanel_event.entity | length > 0 }}' sequence: - - *variables-settings_entity - service: 'cover.set_cover_position' data: - entity_id: '{{ settings_entity_dict.entity }}' + entity_id: '{{ nspanel_event.entity }}' position: '{{ nspanel_event.value }}' continue_on_error: true - alias: coversetting open close stop - conditions: '{{ nspanel_event.component in ["open_cover", "close_cover", "stop_cover"] }}' + conditions: + - '{{ nspanel_event.component in ["open_cover", "close_cover", "stop_cover"] }}' + - '{{ nspanel_event.entity is defined and nspanel_event.entity is string and nspanel_event.entity | length > 0 }}' sequence: - - *variables-settings_entity - service: 'cover.{{ nspanel_event.component }}' data: - entity_id: '{{ settings_entity_dict.entity }}' + entity_id: '{{ nspanel_event.entity }}' continue_on_error: true - alias: climate climateslider conditions: - - '{{ nspanel_event.page in [page.climate, "climatesettings"] }}' + - '{{ nspanel_event.page == page.climate }}' - '{{ nspanel_event.component == "climate_position" }}' + - '{{ nspanel_event.entity is defined and nspanel_event.entity is string and nspanel_event.entity | length > 0 }}' sequence: - - *variables-settings_entity - - if: '{{ settings_entity_dict.entity is string and states(settings_entity_dict.entity) != "off" }}' + - if: '{{ not is_state(nspanel_event.entity, "off") }}' then: - variables: new_setpoint: '{{ nspanel_event.value | int(-999) }}' @@ -8157,7 +7937,7 @@ action: then: - service: climate.set_temperature data: - entity_id: '{{ settings_entity_dict.entity }}' + entity_id: '{{ nspanel_event.entity }}' temperature: '{{ new_setpoint / 10 }}' continue_on_error: true @@ -8166,10 +7946,9 @@ action: - '{{ nspanel_event.page == page.climate }}' - '{{ nspanel_event.component in ["button01", "button02", "button03", "button04", "button05", "button06", "button07"] }}' - '{{ nspanel_event.value == "release" }}' + - '{{ nspanel_event.entity is defined and nspanel_event.entity is string and nspanel_event.entity | length > 0 }}' sequence: - - *variables-settings_entity - *variables-climate_entity - - condition: '{{ settings_entity_domain == "climate" }}' - variables: new_hvac_mode: > {{ @@ -8278,32 +8057,41 @@ action: }} last_click_button: '{{ button_pages_buttons | selectattr("page", "defined") | selectattr("page", "eq", nspanel_event.page) | selectattr("component", "defined") | selectattr("component", "eq", nspanel_event.component) | list }}' - condition: '{{ last_click_button | count >= 0 and button_wait.page == nspanel_event.page }}' - - if: '{{ not wait.completed }}' + - variables: + last_click_button: '{{ last_click_button[0] }}' + entity_domain: > + {{ + last_click_button.entity.split(".")[0] | default("unknown") + if + last_click_button.entity is string and + last_click_button.entity | length > 0 and + last_click_button.entity.split(".") | count > 0 + else "unknown" + }} + - if: '{{ (not wait.completed and entity_domain in ["cover", "light"]) or entity_domain == "climate" }}' then: # Long press - - service: '{{ nextion.command.set_settings_entity }}' + - service: '{{ nextion.command.open_entity_settings_page }}' data: - entity: '{{ last_click_button[0] }}' + page: '{{ entity_domain }}' + page_label: '{{ last_click_button.name if last_click_button.name is string and last_click_button.name | length > 0 else state_attr(last_click_button.entity, "friendly_name") }}' + page_icon: > + {{ + all_icons[last_click_button.icon.split(":")[1]] | default(last_click_button.icon if last_click_button.icon is defined and last_click_button.icon is string else nextion.icon.domain[entity_domain]) + if last_click_button.icon not in ["unavailable", "unknown", "", None] and last_click_button.icon | length > 0 + else nextion.icon.domain[entity_domain] + }} + page_icon_color: > + {{ + last_click_button.icon_color_rgb + if is_number(last_click_button.icon_color_rgb) + else ((last_click_button.icon_color_rgb[0] //(2**3)) *(2**11))+((last_click_button.icon_color_rgb[1] //(2**2)) *(2**5))+(last_click_button.icon_color_rgb[2] //(2**3)) + }} + entity: '{{ last_click_button.entity }}' + back_page: '{{ nspanel_event.page }}' continue_on_error: true else: # Short press - - variables: - last_click_button: '{{ last_click_button[0] }}' - entity_domain: > - {{ - last_click_button.entity.split(".")[0] | default("unknown") - if - last_click_button.entity is string and - last_click_button.entity | length > 0 and - last_click_button.entity.split(".") | count > 0 - else "unknown" - }} - - condition: '{{ entity_domain not in ["unknown", "person", "binary_sensor", "sensor"] }}' - - if: '{{ entity_domain == "climate" }}' + - if: '{{ entity_domain not in ["unknown", "person", "binary_sensor", "sensor"] }}' then: - - service: '{{ nextion.command.set_settings_entity }}' - data: - entity: '{{ last_click_button }}' - continue_on_error: true - else: - if: '{{ last_click_button.confirm }}' then: - variables: @@ -8411,9 +8199,14 @@ action: - '{{ nspanel_event.value == "release" }}' - '{{ climate | length > 0 }} ' sequence: - - service: '{{ nextion.command.set_settings_entity }}' + - service: '{{ nextion.command.open_entity_settings_page }}' data: - entity: '{{ dict(nspanel_event.items(), entity=climate, name=state_attr(climate, "friendly_name")) }}' + page: 'climate' + page_label: '{{ state_attr(climate, "friendly_name") }}' + page_icon: '' + page_icon_color: -1 #No color set + entity: '{{ climate }}' + back_page: '{{ page.home }}' continue_on_error: true - alias: Jump to weather page @@ -8514,7 +8307,7 @@ action: - conditions: '{{ nspanel_event.page in page.entitypages }}' sequence: *refresh-entity_pages - ##### UPDATE BUTTONS PAGES - button page / lightsettings page / coversettings page ##### + ##### UPDATE BUTTONS PAGES - button page / light page / cover page ##### - alias: 'Buttons entity updated' conditions: - condition: trigger @@ -8579,12 +8372,12 @@ action: conditions: - '{{ nspanel_event.page == page.light }}' - '{{ trigger.entity_id is match "light." }}' - sequence: *refresh_page_lightsettings + sequence: *refresh_page_light - alias: 'Cover settings page' conditions: - '{{ nspanel_event.page == page.cover }}' - '{{ trigger.entity_id is match "cover." }}' - sequence: *refresh_page_coversettings + sequence: *refresh_page_cover - alias: 'Climate page' conditions: - '{{ nspanel_event.page == page.climate }}' @@ -8658,7 +8451,7 @@ action: sequence: - variables: climate_entity: '{{ trigger.event.data.entity_id }}' - hvac_modes: '{{ state_attr(climate_entity, "hvac_modes") if settings_entity_domain == "climate" }}' + hvac_modes: '{{ state_attr(climate_entity, "hvac_modes") }}' - *climate-update_slider - *climate-update_buttons @@ -8731,17 +8524,33 @@ action: sequence: - variables: button_context: '{{ page_home.hardware.buttons.left if trigger.id == "left_button_press" else page_home.hardware.buttons.right }}' + button_domain: > + {{ + button_context.entity.split(".")[0] | default("unknown") + if + button_context.entity is string and + button_context.entity | length > 0 and + button_context.entity.split(".") | count > 0 + else "unknown" + }} - wait_template: '{{ is_state(left_button if trigger.id == "left_button_press" else right_button, "off") }}' timeout: !input hold_delay continue_on_timeout: true - if: '{{ not wait.completed }}' then: # Hold - choose: - - conditions: '{{ button_context.hold_select == "Default" and button_context.entity | length > 0 }}' + - conditions: + - '{{ button_context.hold_select == "Default" and button_context.entity | length > 0 }}' + - '{{ button_domain in ["climate", "cover", "light"] }}' sequence: - - service: '{{ nextion.command.set_settings_entity }}' + - service: '{{ nextion.command.open_entity_settings_page }}' data: - entity: '{{ button_context }}' + page: '{{ button_domain }}' + page_label: '{{ button_context.name if button_context.name is string and button_context.name | length > 0 else state_attr(button_context.entity, "friendly_name") }}' + page_icon: '{{ nextion.icon.domain[button_domain] }}' + page_icon_color: -1 #No color set + entity: '{{ button_context.entity }}' + back_page: '{{ page.home }}' continue_on_error: true - conditions: '{{ button_context.hold_select == "Custom Action" and trigger.id == "left_button_press" }}' sequence: !input left_button_hold_custom_action @@ -8750,8 +8559,6 @@ action: else: # Single Click - condition: template value_template: '{{ button_context.entity | length > 0 }}' - - variables: - button_domain: '{{ (button_context.entity.split(".")[0] | default("unknown")) if button_context.entity | length > 0 else "unknown" }}' - service: > {% if button_domain in ["light", "switch", "cover", "input_boolean", "automation", "fan"] %} {{ button_domain }}.toggle diff --git a/nspanel_esphome.yaml b/nspanel_esphome.yaml index 2cb337e..0143c14 100644 --- a/nspanel_esphome.yaml +++ b/nspanel_esphome.yaml @@ -133,6 +133,7 @@ button: id: tft_update entity_category: config on_press: + - logger.log: "Button pressed: Update TFT display" - binary_sensor.template.publish: id: nextion_init state: false @@ -146,6 +147,7 @@ button: id: tft_reparse_off entity_category: config on_press: + - logger.log: "Button pressed: Exit reparse" - uart.write: id: tf_uart data: "DRAKJHSUYDGBNCJHGJKSHBDN" @@ -162,6 +164,7 @@ api: ##### SERVICE TO UPDATE THE HMI FILE ############## - service: upload_tft then: + - logger.log: "Service: upload_tft" - binary_sensor.template.publish: id: nextion_init state: false @@ -172,6 +175,7 @@ api: variables: url: string then: + - logger.log: "Service: upload_tft_url" - binary_sensor.template.publish: id: nextion_init state: false @@ -256,6 +260,7 @@ api: label: string text: string then: + - logger.log: "Service: notification_show" - wait_until: binary_sensor.is_on: nextion_init - lambda: |- @@ -274,6 +279,7 @@ api: ##### Service to clear the notification ##### - service: notification_clear then: + - logger.log: "Service: notification_clear" - wait_until: binary_sensor.is_on: nextion_init - lambda: |- @@ -281,15 +287,33 @@ api: id(notification_text).publish_state(""); - switch.turn_off: notification_unread - ##### Service to set entity-information for settings-page(s) - - service: set_settings_entity + ##### Service to open information for settings-page(s) + - service: open_entity_settings_page variables: + page: string + page_label: string + page_icon: string + page_icon_color: int entity: string + back_page: string then: - wait_until: binary_sensor.is_on: nextion_init - lambda: |- - id(settings_entity).publish_state(entity.c_str()); + std::string entity_component = page.c_str() + std::string(".entity"); + id(disp1).set_component_text_printf(entity_component.c_str(), "%s", entity.c_str()); + std::string cmd_page = std::string("page ") + page.c_str(); + id(disp1).send_command_printf(cmd_page.c_str()); + id(disp1).set_component_text_printf("page_label", "%s", page_label.c_str()); + id(disp1).set_component_text_printf("back_page", "%s", back_page.c_str()); + if ((page_icon.c_str() != std::string()) and (page_icon.c_str() != "") and (page != "climate")) + { + id(disp1).set_component_text_printf("icon_state", "%s", page_icon.c_str()); + } + if (page_icon_color >= 0 and page != "climate") + { + id(disp1).set_component_font_color("icon_state", page_icon_color); + } ##### Service to play a rtttl tones ##### # Example tones : https://codebender.cc/sketch:109888#RTTTL%20Songs.ino @@ -325,6 +349,12 @@ api: - wait_until: binary_sensor.is_on: nextion_init - lambda: |- + id(disp1).send_command_printf("climateslider.maxval=%i", total_steps); + id(disp1).set_component_value("temp_offset", temp_offset); + id(disp1).set_component_value("temp_step", temp_step); + id(disp1).set_component_text_printf("current_temp", "%.1f°", current_temp); + id(disp1).show_component("current_temp"); + id(disp1).show_component("current_icon"); if (target_temp > -999) { id(disp1).set_component_value("climateslider", slider_val); @@ -344,13 +374,6 @@ api: id(disp1).hide_component("decrease_temp"); id(disp1).hide_component("increase_temp"); } - - lambda: |- - id(disp1).send_command_printf("climateslider.maxval=%i", total_steps); - id(disp1).set_component_value("temp_offset", temp_offset); - id(disp1).set_component_value("temp_step", temp_step); - id(disp1).set_component_text_printf("current_temp", "%.1f°", current_temp); - id(disp1).show_component("current_temp"); - id(disp1).show_component("current_icon"); #### Service to set the buttons #### - service: set_button @@ -690,10 +713,6 @@ text_sensor: platform: template id: notification_text - - name: ${device_name} Settings Entity - platform: template - id: settings_entity - ##### NSPanel event sensor, the main action sensor - push to HA ##### - name: ${device_name} NSPanel event platform: nextion @@ -904,7 +923,7 @@ display: - logger.log: "Nextion start - Jump to page 8" - lambda: id(disp1).send_command_printf("page 8"); - logger.log: "Nextion start - Publish ESPHome version" - - lambda: id(disp1).set_component_text_printf("boot.esph_version", "%s", "3.4"); ### esphome-version ### + - lambda: id(disp1).set_component_text_printf("boot.esph_version", "%s", "3.5_dev"); ### esphome-version ### - logger.log: "Nextion start - Wait for Home Assistant API" - wait_until: api.connected diff --git a/nspanel_eu.HMI b/nspanel_eu.HMI index a93787a..fd916da 100644 Binary files a/nspanel_eu.HMI and b/nspanel_eu.HMI differ diff --git a/nspanel_eu.tft b/nspanel_eu.tft index 266010a..46d5b22 100644 Binary files a/nspanel_eu.tft and b/nspanel_eu.tft differ diff --git a/nspanel_eu_code/boot.txt b/nspanel_eu_code/boot.txt index 19e879f..a05580a 100644 --- a/nspanel_eu_code/boot.txt +++ b/nspanel_eu_code/boot.txt @@ -12,6 +12,7 @@ Page boot Events Preinitialize Event + dim=100 printh 92 prints "nspanelevent",0 printh 00 @@ -86,7 +87,7 @@ Text tft_version Dragging : 0 Send Component ID : disabled Associated Keyboard: none - Text : 3.4 + Text : 3.5_dev Max. Text Size : 8 Text esph_version diff --git a/nspanel_eu_code/cover.txt b/nspanel_eu_code/cover.txt new file mode 100644 index 0000000..b9006e4 --- /dev/null +++ b/nspanel_eu_code/cover.txt @@ -0,0 +1,291 @@ +Page cover + Attributes + ID : 0 + Scope : local + Dragging : 0 + Send Component ID : disabled + Locked : no + Swide up page ID : disabled + Swide down page ID : disabled + Swide left page ID : disabled + Swide right page ID: disabled + + Events + Preinitialize Event + dim=home.brightness.val + coversetting.txt="{\"page\": \"cover\", \"component\": \"currentpage\", \"value\": \"pagechange\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + + Touch Press Event + coversetting.txt="{\"page\": \"cover\", \"component\": \"touchevent\", \"value\": \"press\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "touchevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + + Touch Release Event + coversetting.txt="{\"page\": \"cover\", \"component\": \"touchevent\", \"value\": \"release\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "touchevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + +Variable (string) va1 + Attributes + ID : 9 + Scope : local + Text : newtxt + Max. Text Size: 10 + +Variable (string) coversetting + Attributes + ID : 15 + Scope : local + Text : + Max. Text Size: 255 + +Variable (string) entity + Attributes + ID : 16 + Scope : global + Text : + Max. Text Size: 100 + +Variable (string) back_page + Attributes + ID : 17 + Scope : local + Text : home + Max. Text Size: 15 + +Text battery_value + Attributes + ID : 1 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text cover_value + Attributes + ID : 2 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text page_label + Attributes + ID : 3 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 25 + +Text icon_state + Attributes + ID : 13 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text battery_icon + Attributes + ID : 14 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Picture cover_exit + Attributes + ID : 11 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Slider coverslider + Attributes + ID : 6 + Scope : local + Dragging : 0 + Send Component ID: disabled + Position : 0 + Upper range limit: 100 + Lower range limit: 0 + + Events + Touch Release Event + covx coverslider.val,va1.txt,0,0 + cover_value.txt=va1.txt+"%" + coversetting.txt="{\"page\": \"cover\", \"component\": \"cover_position\", \"value\": "+va1.txt+", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + +Button cover_open + Attributes + ID : 4 + Scope : local + Dragging : 0 + Send Component ID: disabled + State : unpressed + Text : + Max. Text Size : 10 + + Events + Touch Press Event + coversetting.txt="{\"page\": \"cover\", \"component\": \"open_cover\", \"value\": \"press\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + +Button cover_close + Attributes + ID : 5 + Scope : local + Dragging : 0 + Send Component ID: disabled + State : unpressed + Text : + Max. Text Size : 10 + + Events + Touch Press Event + coversetting.txt="{\"page\": \"cover\", \"component\": \"close_cover\", \"value\": \"press\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + +Button cover_stop + Attributes + ID : 10 + Scope : local + Dragging : 0 + Send Component ID: disabled + State : unpressed + Text : + Max. Text Size : 10 + + Events + Touch Press Event + coversetting.txt="{\"page\": \"cover\", \"component\": \"stop_cover\", \"value\": \"press\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + +Hotspot cover_back + Attributes + ID : 12 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + if(back_page.txt=="buttonpage01") + { + page buttonpage01 + }else if(back_page.txt=="buttonpage02") + { + page buttonpage02 + }else if(back_page.txt=="buttonpage03") + { + page buttonpage03 + }else if(back_page.txt=="buttonpage04") + { + page buttonpage04 + }else + { + page home + } + +Timer swipestore + Attributes + ID : 8 + Scope : local + Period (ms): 50 + Enabled : no + + Events + Timer Event + swipex=tch0 + swipey=tch1 + +TouchCap swipe + Attributes + ID : 7 + Scope: local + Value: 0 + + Events + Touch Press Event + swipestore.en=1 // Start swipestore timer + + Touch Release Event + swipestore.en=0 + // Touch has ended, x + if(tch0==0) + { + swipec=swipex-tch2 + // From Left to Right + if(swipec>swipedx) + { + //page + } + // Right to Left + swipec2=0-swipedx + if(swipec100) + { + //page + } + // Down to Up + swipec2=0-swipedy + if(swipec<-100) + { + //page + } + } + diff --git a/nspanel_eu_code/light.txt b/nspanel_eu_code/light.txt new file mode 100644 index 0000000..842b2d9 --- /dev/null +++ b/nspanel_eu_code/light.txt @@ -0,0 +1,692 @@ +Page light + Attributes + ID : 0 + Scope : local + Dragging : 0 + Send Component ID : disabled + Locked : no + Swide up page ID : disabled + Swide down page ID : disabled + Swide left page ID : disabled + Swide right page ID: disabled + + Events + Preinitialize Event + dim=home.brightness.val + lightsetting.txt="{\"page\": \"light\", \"component\": \"currentpage\", \"value\": \"pagechange\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + vis light_b_press,1 + vis lightslider,1 + vis light_value,1 + vis temp_value_2,1 + // #### OFF Button ##### + vis temp_b_press,0 + vis color_b_pres,0 + // #### OFF Value ##### + vis temp_value,0 + vis light_value_2,0 + // #### OFF Slider ##### + vis tempslider,0 + vis colorwheel,0 + + Touch Press Event + lightsetting.txt="{\"page\": \"light\", \"component\": \"touchevent\", \"value\": \"press\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "touchevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + + Touch Release Event + lightsetting.txt="{\"page\": \"light\", \"component\": \"touchevent\", \"value\": \"release\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "touchevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + +Variable (int32) rgb565 + Attributes + ID : 22 + Scope: local + Value: 0 + +Variable (string) va1 + Attributes + ID : 23 + Scope : local + Text : newtxt + Max. Text Size: 20 + +Variable (string) va2 + Attributes + ID : 24 + Scope : local + Text : newtxt + Max. Text Size: 10 + +Variable (string) va3 + Attributes + ID : 25 + Scope : local + Text : newtxt + Max. Text Size: 10 + +Variable (int32) currenttab + Attributes + ID : 26 + Scope: local + Value: 0 + +Variable (string) lightsetting + Attributes + ID : 32 + Scope : local + Text : + Max. Text Size: 255 + +Variable (string) entity + Attributes + ID : 33 + Scope : global + Text : + Max. Text Size: 100 + +Variable (string) back_page + Attributes + ID : 34 + Scope : local + Text : home + Max. Text Size: 15 + +Number ring + Attributes + ID : 4 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Value : 0 + +Number field + Attributes + ID : 5 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Value : 0 + +Text light_value + Attributes + ID : 1 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text page_label + Attributes + ID : 2 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 25 + +Text temp_value + Attributes + ID : 14 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text light_value_2 + Attributes + ID : 27 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text temp_value_2 + Attributes + ID : 28 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text icon_state + Attributes + ID : 31 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Picture light_button + Attributes + ID : 8 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture color_button + Attributes + ID : 9 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture temp_button + Attributes + ID : 10 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture light_b_press + Attributes + ID : 11 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture temp_b_press + Attributes + ID : 12 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture color_b_pres + Attributes + ID : 13 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture colorwheel + Attributes + ID : 16 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + // Circular Color Picker for Nextion (c) Max Zuidberg 2022 + // This Source Code Form is subject to the terms of the Mozilla Public + // License, v. 2.0. If a copy of the MPL was not distributed with this + // file, You can obtain one at http://mozilla.org/MPL/2.0/. + // + // Put this code in the touch press or release + // event of the pic component with the color wheel. + // Requires the two variables field.val and ring.val + // + // sya0 = x, sya1 = sya1 + // Note the usage of the hidden sya0, sya1 variables + // within event code as local, temporary variable is fine. + sya0=tch0 + sya1=tch1 + // + // Convert absolute coordinates to coordinates relative to + // the color wheel center. + // sys0 = x_center, sys1 = y_center + sys0=colorwheel.w/2 + sys0+=colorwheel.x + sys1=colorwheel.h/2 + sys1+=colorwheel.y + sya0-=sys0 + sya1-=sys1 + // + // Determine ring + ring.val=0 + // sys0 = r^2 = x^2 + y^2 + sys0=sya0*sya0 + sys1=sya1*sya1 + sys0+=sys1 + // repeat for all rings + if(sys0>=156) + { + ring.val++ + } + if(sys0>=625) + { + ring.val++ + } + if(sys0>=1406) + { + ring.val++ + } + if(sys0>=2500) + { + ring.val++ + } + if(sys0>=3906) + { + ring.val++ + } + if(sys0>=5625) + { + ring.val++ + } + if(sys0>=7656) + { + ring.val++ + } + // + // Determine quadrant (0-3). Note: pixel y coords are inverted + // compared to mathematical y coords. But we want math. quadrants. + sya1*=-1 + sys2=0 + if(sya1<0) + { + sys2+=2 + } + sys0=sya0*sya1 + if(sys0<0) + { + sys2+=1 + // In this case we also want to swap x and y otherwise the + // atan(abs(x/y)) (calculated below) gives values running + // "the wrong way" (cw instead of ccw). + sys1=sya1 + sya1=sya0 + sya0=sys1 + } + // + field.val=sys2*6 + // + // x,y sign is not required anymore + if(sya0<0) + { + sya0*=-1 + } + if(sya1<0) + { + sya1*=-1 + } + // + // Determine field in ring quadrant + // Factor 100000 chosen more or less arbitrarily. + // sys0 = 100000 * tan_a = 100000 * y / x + sys0=100000*sya1 + sys0/=sya0 + // repeat for all fields + if(sys0>=26794) + { + field.val++ + } + if(sys0>=57735) + { + field.val++ + } + if(sys0>=99999) + { + field.val++ + } + if(sys0>=173205) + { + field.val++ + } + if(sys0>=373205) + { + field.val++ + } + covx r,va1.txt,0,0 + covx g,va2.txt,0,0 + covx b,va3.txt,0,0 + va1.txt="" + va2.txt="" + va3.txt="" + + Touch Release Event + // Adjust field.val "orientation" and offset to match the h value of the colors in the wheel + h=23-field.val// 0 <= field.val <= 23 + // h is expected to be 0-6*256 (see hsv2rgb) + h*=6*256 + h/=24// Number of fields + // + // s is expected to be 0-256 (see hsv2rgb) + s=ring.val*256 + s/=8// Number of rings + // no "value" selectable; fix it to the maximum (matching the colors in the wheels shown. + v=255 + click hsv2rgb,0 + click rgb888to565,0 + //colPreview.bco=rgb565.val + covx r,va1.txt,0,0 + covx g,va2.txt,0,0 + covx b,va3.txt,0,0 + lightsetting.txt="{\"page\": \"light\", \"component\": \"rgb_color\", \"value\": ["+va1.txt+","+va2.txt+","+va3.txt+"], \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + va1.txt="" + va2.txt="" + va3.txt="" + +Picture light_exit + Attributes + ID : 29 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Slider lightslider + Attributes + ID : 3 + Scope : local + Dragging : 0 + Send Component ID: disabled + Position : 0 + Upper range limit: 100 + Lower range limit: 0 + + Events + Touch Release Event + covx lightslider.val,va1.txt,0,0 + light_value.txt=va1.txt+"%" + light_value_2.txt=va1.txt+"%" + lightsetting.txt="{\"page\": \"light\", \"component\": \"brightness_pct\", \"value\": "+va1.txt+", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + +Slider tempslider + Attributes + ID : 15 + Scope : local + Dragging : 0 + Send Component ID: disabled + Position : 0 + Upper range limit: 500 + Lower range limit: 153 + + Events + Touch Release Event + covx tempslider.val,va1.txt,0,0 + temp_value.txt=va1.txt + temp_value_2.txt=va1.txt + lightsetting.txt="{\"page\": \"light\", \"component\": \"color_temp\", \"value\": "+va1.txt+", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + +Hotspot hsv2rgb + Attributes + ID : 6 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Release Event + // https://de.wikipedia.org/wiki/HSV-Farbraum#Umrechnung_HSV_in_RGB + // The values range from 0..255 instead of 0..1 + // h ranges from 0..(6*256) + if(s>=256) + { + s=255 + }else if(s<0) + { + s=0 + } + if(v>=256) + { + v=255 + }else if(v<0) + { + v=0 + } + f=h&0xff + p=256-s + p*=v + p=p>>8// / 256 + q=s*f// 0-256*256 = 0-65536 + q=65536-q + q*=v + q=q>>16 + t=256-f + t*=s + t=65536-t + t*=v + t=t>>16 + // + f=h>>8 + if(f==1) + { + r=q + g=v + b=p + }else if(f==2) + { + r=p + g=v + b=t + }else if(f==3) + { + r=p + g=q + b=v + }else if(f==4) + { + r=t + g=p + b=v + }else if(f==5) + { + r=v + g=p + b=q + }else + { + r=v + g=t + b=p + } + +Hotspot rgb888to565 + Attributes + ID : 7 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Release Event + r=r&0xff + g=g&0xff + b=b&0xff + sys1=r>>3 + sys2=sys1<<6 + sys1=g>>2 + sys2+=sys1 + sys2=sys2<<5 + sys1=b>>3 + sys2+=sys1 + rgb565.val=sys2 + +Hotspot light_touch + Attributes + ID : 17 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + vis light_b_press,1 + vis lightslider,1 + vis light_value,1 + vis temp_value_2,1 + // #### OFF Button ##### + vis temp_b_press,0 + vis color_b_pres,0 + // #### OFF Value ##### + vis temp_value,0 + vis light_value_2,0 + // #### OFF Slider ##### + vis tempslider,0 + vis colorwheel,0 + +Hotspot temp_touch + Attributes + ID : 18 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + vis temp_b_press,1 + vis tempslider,1 + vis temp_value,1 + vis light_value_2,1 + // #### OFF Button ##### + vis light_b_press,0 + vis color_b_pres,0 + // #### OFF Value ##### + vis light_value,0 + vis temp_value_2,0 + // #### OFF Slider ##### + vis lightslider,0 + vis colorwheel,0 + +Hotspot color_touch + Attributes + ID : 19 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + vis color_b_pres,1 + vis colorwheel,1 + vis light_value_2,1 + // #### OFF Button ##### + vis light_b_press,0 + vis temp_b_press,0 + // #### OFF Value ##### + vis light_value,0 + vis temp_value,0 + vis temp_value_2,0 + // #### OFF Slider ##### + vis lightslider,0 + vis tempslider,0 + // #### OFF Color ##### + +Hotspot light_back + Attributes + ID : 30 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + if(back_page.txt=="buttonpage01") + { + page buttonpage01 + }else if(back_page.txt=="buttonpage02") + { + page buttonpage02 + }else if(back_page.txt=="buttonpage03") + { + page buttonpage03 + }else if(back_page.txt=="buttonpage04") + { + page buttonpage04 + }else + { + page home + } + +Timer swipestore + Attributes + ID : 21 + Scope : local + Period (ms): 50 + Enabled : no + + Events + Timer Event + swipex=tch0 + swipey=tch1 + +TouchCap swipe + Attributes + ID : 20 + Scope: local + Value: 0 + + Events + Touch Press Event + swipestore.en=1 // Start swipestore timer + + Touch Release Event + swipestore.en=0 + // Touch has ended, x + if(tch0==0) + { + swipec=swipex-tch2 + // From Left to Right + if(swipec>swipedx) + { + //page + } + // Right to Left + swipec2=0-swipedx + if(swipec100) + { + //page + } + // Down to Up + swipec2=0-swipedy + if(swipec<-100) + { + //page + } + } + diff --git a/nspanel_us.HMI b/nspanel_us.HMI index c3130c6..81fa5d2 100644 Binary files a/nspanel_us.HMI and b/nspanel_us.HMI differ diff --git a/nspanel_us.tft b/nspanel_us.tft index 46e6995..472819a 100644 Binary files a/nspanel_us.tft and b/nspanel_us.tft differ diff --git a/nspanel_us_code/boot.txt b/nspanel_us_code/boot.txt index 19e879f..a05580a 100644 --- a/nspanel_us_code/boot.txt +++ b/nspanel_us_code/boot.txt @@ -12,6 +12,7 @@ Page boot Events Preinitialize Event + dim=100 printh 92 prints "nspanelevent",0 printh 00 @@ -86,7 +87,7 @@ Text tft_version Dragging : 0 Send Component ID : disabled Associated Keyboard: none - Text : 3.4 + Text : 3.5_dev Max. Text Size : 8 Text esph_version diff --git a/nspanel_us_code/cover.txt b/nspanel_us_code/cover.txt new file mode 100644 index 0000000..b9006e4 --- /dev/null +++ b/nspanel_us_code/cover.txt @@ -0,0 +1,291 @@ +Page cover + Attributes + ID : 0 + Scope : local + Dragging : 0 + Send Component ID : disabled + Locked : no + Swide up page ID : disabled + Swide down page ID : disabled + Swide left page ID : disabled + Swide right page ID: disabled + + Events + Preinitialize Event + dim=home.brightness.val + coversetting.txt="{\"page\": \"cover\", \"component\": \"currentpage\", \"value\": \"pagechange\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + + Touch Press Event + coversetting.txt="{\"page\": \"cover\", \"component\": \"touchevent\", \"value\": \"press\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "touchevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + + Touch Release Event + coversetting.txt="{\"page\": \"cover\", \"component\": \"touchevent\", \"value\": \"release\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "touchevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + +Variable (string) va1 + Attributes + ID : 9 + Scope : local + Text : newtxt + Max. Text Size: 10 + +Variable (string) coversetting + Attributes + ID : 15 + Scope : local + Text : + Max. Text Size: 255 + +Variable (string) entity + Attributes + ID : 16 + Scope : global + Text : + Max. Text Size: 100 + +Variable (string) back_page + Attributes + ID : 17 + Scope : local + Text : home + Max. Text Size: 15 + +Text battery_value + Attributes + ID : 1 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text cover_value + Attributes + ID : 2 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text page_label + Attributes + ID : 3 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 25 + +Text icon_state + Attributes + ID : 13 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text battery_icon + Attributes + ID : 14 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Picture cover_exit + Attributes + ID : 11 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Slider coverslider + Attributes + ID : 6 + Scope : local + Dragging : 0 + Send Component ID: disabled + Position : 0 + Upper range limit: 100 + Lower range limit: 0 + + Events + Touch Release Event + covx coverslider.val,va1.txt,0,0 + cover_value.txt=va1.txt+"%" + coversetting.txt="{\"page\": \"cover\", \"component\": \"cover_position\", \"value\": "+va1.txt+", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + +Button cover_open + Attributes + ID : 4 + Scope : local + Dragging : 0 + Send Component ID: disabled + State : unpressed + Text : + Max. Text Size : 10 + + Events + Touch Press Event + coversetting.txt="{\"page\": \"cover\", \"component\": \"open_cover\", \"value\": \"press\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + +Button cover_close + Attributes + ID : 5 + Scope : local + Dragging : 0 + Send Component ID: disabled + State : unpressed + Text : + Max. Text Size : 10 + + Events + Touch Press Event + coversetting.txt="{\"page\": \"cover\", \"component\": \"close_cover\", \"value\": \"press\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + +Button cover_stop + Attributes + ID : 10 + Scope : local + Dragging : 0 + Send Component ID: disabled + State : unpressed + Text : + Max. Text Size : 10 + + Events + Touch Press Event + coversetting.txt="{\"page\": \"cover\", \"component\": \"stop_cover\", \"value\": \"press\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints coversetting.txt,0 + printh 00 + printh FF FF FF + +Hotspot cover_back + Attributes + ID : 12 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + if(back_page.txt=="buttonpage01") + { + page buttonpage01 + }else if(back_page.txt=="buttonpage02") + { + page buttonpage02 + }else if(back_page.txt=="buttonpage03") + { + page buttonpage03 + }else if(back_page.txt=="buttonpage04") + { + page buttonpage04 + }else + { + page home + } + +Timer swipestore + Attributes + ID : 8 + Scope : local + Period (ms): 50 + Enabled : no + + Events + Timer Event + swipex=tch0 + swipey=tch1 + +TouchCap swipe + Attributes + ID : 7 + Scope: local + Value: 0 + + Events + Touch Press Event + swipestore.en=1 // Start swipestore timer + + Touch Release Event + swipestore.en=0 + // Touch has ended, x + if(tch0==0) + { + swipec=swipex-tch2 + // From Left to Right + if(swipec>swipedx) + { + //page + } + // Right to Left + swipec2=0-swipedx + if(swipec100) + { + //page + } + // Down to Up + swipec2=0-swipedy + if(swipec<-100) + { + //page + } + } + diff --git a/nspanel_us_code/light.txt b/nspanel_us_code/light.txt new file mode 100644 index 0000000..842b2d9 --- /dev/null +++ b/nspanel_us_code/light.txt @@ -0,0 +1,692 @@ +Page light + Attributes + ID : 0 + Scope : local + Dragging : 0 + Send Component ID : disabled + Locked : no + Swide up page ID : disabled + Swide down page ID : disabled + Swide left page ID : disabled + Swide right page ID: disabled + + Events + Preinitialize Event + dim=home.brightness.val + lightsetting.txt="{\"page\": \"light\", \"component\": \"currentpage\", \"value\": \"pagechange\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + vis light_b_press,1 + vis lightslider,1 + vis light_value,1 + vis temp_value_2,1 + // #### OFF Button ##### + vis temp_b_press,0 + vis color_b_pres,0 + // #### OFF Value ##### + vis temp_value,0 + vis light_value_2,0 + // #### OFF Slider ##### + vis tempslider,0 + vis colorwheel,0 + + Touch Press Event + lightsetting.txt="{\"page\": \"light\", \"component\": \"touchevent\", \"value\": \"press\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "touchevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + + Touch Release Event + lightsetting.txt="{\"page\": \"light\", \"component\": \"touchevent\", \"value\": \"release\", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "touchevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + +Variable (int32) rgb565 + Attributes + ID : 22 + Scope: local + Value: 0 + +Variable (string) va1 + Attributes + ID : 23 + Scope : local + Text : newtxt + Max. Text Size: 20 + +Variable (string) va2 + Attributes + ID : 24 + Scope : local + Text : newtxt + Max. Text Size: 10 + +Variable (string) va3 + Attributes + ID : 25 + Scope : local + Text : newtxt + Max. Text Size: 10 + +Variable (int32) currenttab + Attributes + ID : 26 + Scope: local + Value: 0 + +Variable (string) lightsetting + Attributes + ID : 32 + Scope : local + Text : + Max. Text Size: 255 + +Variable (string) entity + Attributes + ID : 33 + Scope : global + Text : + Max. Text Size: 100 + +Variable (string) back_page + Attributes + ID : 34 + Scope : local + Text : home + Max. Text Size: 15 + +Number ring + Attributes + ID : 4 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Value : 0 + +Number field + Attributes + ID : 5 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Value : 0 + +Text light_value + Attributes + ID : 1 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text page_label + Attributes + ID : 2 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 25 + +Text temp_value + Attributes + ID : 14 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text light_value_2 + Attributes + ID : 27 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text temp_value_2 + Attributes + ID : 28 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Text icon_state + Attributes + ID : 31 + Scope : local + Dragging : 0 + Send Component ID : disabled + Associated Keyboard: none + Text : + Max. Text Size : 10 + +Picture light_button + Attributes + ID : 8 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture color_button + Attributes + ID : 9 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture temp_button + Attributes + ID : 10 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture light_b_press + Attributes + ID : 11 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture temp_b_press + Attributes + ID : 12 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture color_b_pres + Attributes + ID : 13 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Picture colorwheel + Attributes + ID : 16 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + // Circular Color Picker for Nextion (c) Max Zuidberg 2022 + // This Source Code Form is subject to the terms of the Mozilla Public + // License, v. 2.0. If a copy of the MPL was not distributed with this + // file, You can obtain one at http://mozilla.org/MPL/2.0/. + // + // Put this code in the touch press or release + // event of the pic component with the color wheel. + // Requires the two variables field.val and ring.val + // + // sya0 = x, sya1 = sya1 + // Note the usage of the hidden sya0, sya1 variables + // within event code as local, temporary variable is fine. + sya0=tch0 + sya1=tch1 + // + // Convert absolute coordinates to coordinates relative to + // the color wheel center. + // sys0 = x_center, sys1 = y_center + sys0=colorwheel.w/2 + sys0+=colorwheel.x + sys1=colorwheel.h/2 + sys1+=colorwheel.y + sya0-=sys0 + sya1-=sys1 + // + // Determine ring + ring.val=0 + // sys0 = r^2 = x^2 + y^2 + sys0=sya0*sya0 + sys1=sya1*sya1 + sys0+=sys1 + // repeat for all rings + if(sys0>=156) + { + ring.val++ + } + if(sys0>=625) + { + ring.val++ + } + if(sys0>=1406) + { + ring.val++ + } + if(sys0>=2500) + { + ring.val++ + } + if(sys0>=3906) + { + ring.val++ + } + if(sys0>=5625) + { + ring.val++ + } + if(sys0>=7656) + { + ring.val++ + } + // + // Determine quadrant (0-3). Note: pixel y coords are inverted + // compared to mathematical y coords. But we want math. quadrants. + sya1*=-1 + sys2=0 + if(sya1<0) + { + sys2+=2 + } + sys0=sya0*sya1 + if(sys0<0) + { + sys2+=1 + // In this case we also want to swap x and y otherwise the + // atan(abs(x/y)) (calculated below) gives values running + // "the wrong way" (cw instead of ccw). + sys1=sya1 + sya1=sya0 + sya0=sys1 + } + // + field.val=sys2*6 + // + // x,y sign is not required anymore + if(sya0<0) + { + sya0*=-1 + } + if(sya1<0) + { + sya1*=-1 + } + // + // Determine field in ring quadrant + // Factor 100000 chosen more or less arbitrarily. + // sys0 = 100000 * tan_a = 100000 * y / x + sys0=100000*sya1 + sys0/=sya0 + // repeat for all fields + if(sys0>=26794) + { + field.val++ + } + if(sys0>=57735) + { + field.val++ + } + if(sys0>=99999) + { + field.val++ + } + if(sys0>=173205) + { + field.val++ + } + if(sys0>=373205) + { + field.val++ + } + covx r,va1.txt,0,0 + covx g,va2.txt,0,0 + covx b,va3.txt,0,0 + va1.txt="" + va2.txt="" + va3.txt="" + + Touch Release Event + // Adjust field.val "orientation" and offset to match the h value of the colors in the wheel + h=23-field.val// 0 <= field.val <= 23 + // h is expected to be 0-6*256 (see hsv2rgb) + h*=6*256 + h/=24// Number of fields + // + // s is expected to be 0-256 (see hsv2rgb) + s=ring.val*256 + s/=8// Number of rings + // no "value" selectable; fix it to the maximum (matching the colors in the wheels shown. + v=255 + click hsv2rgb,0 + click rgb888to565,0 + //colPreview.bco=rgb565.val + covx r,va1.txt,0,0 + covx g,va2.txt,0,0 + covx b,va3.txt,0,0 + lightsetting.txt="{\"page\": \"light\", \"component\": \"rgb_color\", \"value\": ["+va1.txt+","+va2.txt+","+va3.txt+"], \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + va1.txt="" + va2.txt="" + va3.txt="" + +Picture light_exit + Attributes + ID : 29 + Scope : local + Dragging : 0 + Send Component ID: disabled + +Slider lightslider + Attributes + ID : 3 + Scope : local + Dragging : 0 + Send Component ID: disabled + Position : 0 + Upper range limit: 100 + Lower range limit: 0 + + Events + Touch Release Event + covx lightslider.val,va1.txt,0,0 + light_value.txt=va1.txt+"%" + light_value_2.txt=va1.txt+"%" + lightsetting.txt="{\"page\": \"light\", \"component\": \"brightness_pct\", \"value\": "+va1.txt+", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + +Slider tempslider + Attributes + ID : 15 + Scope : local + Dragging : 0 + Send Component ID: disabled + Position : 0 + Upper range limit: 500 + Lower range limit: 153 + + Events + Touch Release Event + covx tempslider.val,va1.txt,0,0 + temp_value.txt=va1.txt + temp_value_2.txt=va1.txt + lightsetting.txt="{\"page\": \"light\", \"component\": \"color_temp\", \"value\": "+va1.txt+", \"entity\": \""+entity.txt+"\"}" + printh 92 + prints "nspanelevent",0 + printh 00 + prints lightsetting.txt,0 + printh 00 + printh FF FF FF + +Hotspot hsv2rgb + Attributes + ID : 6 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Release Event + // https://de.wikipedia.org/wiki/HSV-Farbraum#Umrechnung_HSV_in_RGB + // The values range from 0..255 instead of 0..1 + // h ranges from 0..(6*256) + if(s>=256) + { + s=255 + }else if(s<0) + { + s=0 + } + if(v>=256) + { + v=255 + }else if(v<0) + { + v=0 + } + f=h&0xff + p=256-s + p*=v + p=p>>8// / 256 + q=s*f// 0-256*256 = 0-65536 + q=65536-q + q*=v + q=q>>16 + t=256-f + t*=s + t=65536-t + t*=v + t=t>>16 + // + f=h>>8 + if(f==1) + { + r=q + g=v + b=p + }else if(f==2) + { + r=p + g=v + b=t + }else if(f==3) + { + r=p + g=q + b=v + }else if(f==4) + { + r=t + g=p + b=v + }else if(f==5) + { + r=v + g=p + b=q + }else + { + r=v + g=t + b=p + } + +Hotspot rgb888to565 + Attributes + ID : 7 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Release Event + r=r&0xff + g=g&0xff + b=b&0xff + sys1=r>>3 + sys2=sys1<<6 + sys1=g>>2 + sys2+=sys1 + sys2=sys2<<5 + sys1=b>>3 + sys2+=sys1 + rgb565.val=sys2 + +Hotspot light_touch + Attributes + ID : 17 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + vis light_b_press,1 + vis lightslider,1 + vis light_value,1 + vis temp_value_2,1 + // #### OFF Button ##### + vis temp_b_press,0 + vis color_b_pres,0 + // #### OFF Value ##### + vis temp_value,0 + vis light_value_2,0 + // #### OFF Slider ##### + vis tempslider,0 + vis colorwheel,0 + +Hotspot temp_touch + Attributes + ID : 18 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + vis temp_b_press,1 + vis tempslider,1 + vis temp_value,1 + vis light_value_2,1 + // #### OFF Button ##### + vis light_b_press,0 + vis color_b_pres,0 + // #### OFF Value ##### + vis light_value,0 + vis temp_value_2,0 + // #### OFF Slider ##### + vis lightslider,0 + vis colorwheel,0 + +Hotspot color_touch + Attributes + ID : 19 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + vis color_b_pres,1 + vis colorwheel,1 + vis light_value_2,1 + // #### OFF Button ##### + vis light_b_press,0 + vis temp_b_press,0 + // #### OFF Value ##### + vis light_value,0 + vis temp_value,0 + vis temp_value_2,0 + // #### OFF Slider ##### + vis lightslider,0 + vis tempslider,0 + // #### OFF Color ##### + +Hotspot light_back + Attributes + ID : 30 + Scope : local + Dragging : 0 + Send Component ID: disabled + + Events + Touch Press Event + if(back_page.txt=="buttonpage01") + { + page buttonpage01 + }else if(back_page.txt=="buttonpage02") + { + page buttonpage02 + }else if(back_page.txt=="buttonpage03") + { + page buttonpage03 + }else if(back_page.txt=="buttonpage04") + { + page buttonpage04 + }else + { + page home + } + +Timer swipestore + Attributes + ID : 21 + Scope : local + Period (ms): 50 + Enabled : no + + Events + Timer Event + swipex=tch0 + swipey=tch1 + +TouchCap swipe + Attributes + ID : 20 + Scope: local + Value: 0 + + Events + Touch Press Event + swipestore.en=1 // Start swipestore timer + + Touch Release Event + swipestore.en=0 + // Touch has ended, x + if(tch0==0) + { + swipec=swipex-tch2 + // From Left to Right + if(swipec>swipedx) + { + //page + } + // Right to Left + swipec2=0-swipedx + if(swipec100) + { + //page + } + // Down to Up + swipec2=0-swipedy + if(swipec<-100) + { + //page + } + } + diff --git a/nspanel_us_code/settings.txt b/nspanel_us_code/settings.txt index 7c59276..2816b14 100644 --- a/nspanel_us_code/settings.txt +++ b/nspanel_us_code/settings.txt @@ -12,6 +12,7 @@ Page settings Events Preinitialize Event + dim=home.brightness.val printh 92 prints "nspanelevent",0 printh 00