* Create ReleaseNotes.md (#879) * Create ReleaseNotes.md * sensor display precision * Filter devices to esp32 only (#881) * Filter devices to esp32 only Show only ESP32 devices when selecting the panel * Filtered device list * Sensor display precision (#880) Now the values shown in your panel will follow the [sensor display precision](https://www.home-assistant.io/blog/2023/03/01/release-20233/#sensor-display-precision) provided by Home Assistant. => If you have problems with a value exceeding the available space in your panel, please reduce the number of decimals using Home Assistant [sensor display precision](https://www.home-assistant.io/blog/2023/03/01/release-20233/#sensor-display-precision). * New language selector (#882) * New language selector * Update ReleaseNotes.md * Update ReleaseNotes.md * Remove `settings_entity` (#887) * Remove `settings_entity` - Bump version to 3.5_dev - Removed references to pictures removed from TFT - Removed code related to closing settings pages - Removed trigger `settings_entity` * Removed `set_settings_entity` service - Bump version to 3.5_dev - Removed `set_settings_entity` service - BREAKING CHANGE - Removed `settings_entity` text-sensor - BREAKING CHANGE - Added service `open_entity_settings_page` - BREAKING CHANGE * Removed `settings_entity` - Bump version to 3.5_dev - Removed old climate page (climate_backup) - Removed pics related to old climate page (ids 16-47, 80-83, 95-96 and 125(US only)) - Enforces brightness on any page change (this allows wake-up on settings page with long press on physical buttons) - Pending removing code from Blueprint - Added `entity` variable on pages `climate`, `lightsettings` and `coversettings` - Added `entity` info to `nspanelevent` on pages `climate`, `lightsettings` and `coversettings` - Added `back_page` variable on pages `climate`, `lightsettings` and `coversettings` (default: home) - Moving to TFT close page logic on pages `climate`, `lightsettings` and `coversettings` - Pending changes on Blueprint and ESPHome - Standardized name for `page_label` on pages `climate`, `lightsettings` and `coversettings` - Standardized settings page names: `climate`, `cover` and `light` (Removed `settings` from page name) * Removed `settings_entity` * Removed `settings_entity` * Removed `settings_entity` * Move `entity` variable to home page (#889) * Move `entity` variable to home page This will enable future development of a fallback climate * Move `entity` variable to home page * Move `entity` variable to home page * Move `entity` variable to home page * Move `entity` variable to home page * Use `en` as fallback language (#891) * Use `en` as fallback language Uses English if a non valid language is selected (like when using legacy language selection). * Use `en` as fallback language * Create `nspanel_us_land.tft` (#890) * Create `nspanel_us_land.tft' Add `nspanel_us_land.tft' for US panel on landscape mode, fixing the offset on the touch screen when using `nspanel_eu.tft` into a US panel. Hides the hardware buttons labels, as Nextion cannot support rotated text. * Created `nspanel_us_land.tft` * Created `nspanel_us_land.tft` solves #390 solves #432 solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/299#discussioncomment-4933716 * Created `nspanel_us_land.tft` * Created `nspanel_us_land.tft` * Fix "Button confirmation page not working correctly" Solves #883 * Supports weather forecast with `datetime` not string This adds support to weather integrations where the `datetime` field under `forecast` attribute is provided as a `datetime` type. This was seen on Météo-France, while all other weather integrations tested so far used a `text` field for `datetime`. This solves #893 * Wifi icon to indicate when API offline This changes the behavior of Wifi icon: How it was before: - Wifi icon was visible only when the wifi was connected, nothing was shown when wifi was not connected. How it is now: - Wifi icon will have 3 states: - Wifi & API connected: Gray wifi icon - Wifi disconnected: Red wifi-off icon - Wifi connected, but API disconnected (HA is out?): Red api-off icon * API status indication on the panel * Limit light & cover to supported settings (#896) * Limit light to supported settings When showing light settings, only the supported features will be shown for each light. * Limit light to supported settings * Limit light to supported settings * Limit light to supported settings * Limit light to supported settings * Limit light to supported settings This partially solves #635 * Limits covers to supported settings Only show cover settings when `set_position` is supported. This solves #635 * Limits covers to supported settings * Update instructions.md * Add Fan speed settings page (#897) * Add Fan speed settings page Add an initial fan speed control page for fans supporting speed control. Add speed (%) info in the buttons pages. Solves #404 Solves #791 Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/718#discussioncomment-5786106 * Add Fan speed settings page * Add Fan speed settings page * Add Fan speed settings page * Add Fan speed settings page * Add Fan speed settings page * Fix name on confirmation page Fix the entity name on the confirmation page. The new order is: 1. Name set on the blueprint settings 2. Entity's `friendly_name` attribute 3. Entity's `name` attribute 4. Entity's `entity_id` Solves #501 * Select wake-up page (#898) * Select wake-up page Users will be able to select the wake-up page on the blueprint inputs. This selected page will be shown after a boot (after the boot page) and with a touch in the screen when on screen saver page. After showing this wake-up page, all the previous behavior for closing the page (with a click or after a timeout) will be the same. Solves #576 Solves #612 Solves #801 Probably improves for https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/718#discussioncomment-5715670 * Select wake-up page * Fan update engine Change the fan update engine to follow the same patter as other settings pages. * Update ReleaseNotes.md * Adding vertical bars pics * Panel offline mode (#900) * Panel offline mode Introduces "offline mode" for the panel, which will be used later with a fallback climate. Pages that are depending on the blueprint (buttons pages, entity pages, settings pages, etc) won't be shown when the API is disconnected. * Panel offline mode * Panel offline mode * Panel offline mode * Panel offline mode * "Jump to settings" on tft Moved "Jump to settings page" routine from ESPHome to TFT in order to reduce complexity. * Exclude Nextion2Text Exclude Nextion2Text * Fix validation issue * Time engine on ESPHome * Time engine on ESPHome * Notification page bigger hotspot Added hotspots around the buttons (Accept & Clear) on Notification page to make easier to click on those. Solves #907 * Boot page retry comm The boot page will retry communication with the blueprint once a minute to avoid the situation where that page is shown until the automation is reloaded. * Fix call to screen page Fixes the call to screen page on US panel. Reconciliate the US landscape model from EU model. * Fix fan page `button_on` Fixing rounding on that button. * Fixed Fan page rounding * Prevents boot sequence in other pages * Physical relay local control We are trying to make your panel as autonomous as possible by moving some of the controls from the Blueprint to ESPHome. This will reduce the load in your network and Home Assistant, but also will make a more reliable system capable to do it's core functionality even when the network is unavailable or Home Assistant is restarting. With this version, the following engines have been moved to your panel (local control): - Physical relay control (when hardware left button is connected to relay 1 or right button to relay 2) Solves #910 * Embedded climate (#917) * Performance improvements The main focus here was to reduce the number of calls between Home Assistant and ESPHome, moving logic as much as possible to TFT and ESPHome. - Service calls moved to ESPHome (in preparation for Alarm Control Panel) - Page change informed via event call instead of `nspanel_event` sensor (which still in use by other calls, but might be possible to remove in the future) * Draft embedded climate This adds an initial version of an embedded climate/thermostat (heating only for now) with support for local control even with Wi-Fi out. Solves #646 Solves #263 * Update ReleaseNotes.md * Fix climate slider Fix for climate slider opening in an incorrect position and sending only the integer part of the new target temperature * Moving home page to ESPHome In progress... * Fix translations - Dutch * Embedded chip 3 Home page - Chip 3 will be controlled locally when embedded climate is enable. * Fixed buttons bar Fixed buttons bar managed on ESPHome when embedded climate is visible. * Update ReleaseNotes.md * Services back to the Blueprint Moving service calls back to the blueprint as latest HA requires user's permissions to call HA services from ESPHome. This still have to be used for Alarm calls due to security concerns. * Update ReleaseNotes.md * support to hidden ssid (#908) Supports hidden ssid with the use of substitutions `wifi_hidden: "true"`. This can be breaking change for users with custom/advanced wifi settings. Solves #906 * Update nspanel_esphome.yaml * Removed `restore_state` There is some incomplete work related to alarms on this commit, but the focus here is to fix `restore_state` on ESPHome v2023.7.0. This solves #939 * US model - Fan page - Redistribute icons Redistributed icons on Fan page on US model in order to improve usability. Based on feedback from https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/791#discussioncomment-6338706 * Align `nspanel_us_land` Apply all changes from EU to US_Land * Fix relays chips Fix relay status indication on chips. Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/issues/926#issuecomment-1627660273 * Fix "invalid variable" for "api" Fix error "Nextion invalid variable name" when setting `api`. * Default embedded climate to relay_0 * Fix translations - Italian Based on https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/940#discussioncomment-6511043 * Fix `set_temperature` for climate Solves #957 * Fix `fan.turn_off` call Removed timer call from fan stop button. This solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/791#discussioncomment-6494535 * Call a `fan.turn_off` when percentage is 0% Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/791#discussioncomment-6621756 * Fix call for fan stop button Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/791#discussioncomment-6622377 * Icons on ESPHome Move icons from TFT/HMI to ESPHome to prevent error on Nextion2Text. * Updated translations - Spanish Based on https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/940#discussioncomment-6548961 * Make home page sensor's icons consistent Make icon selection consistent with chips where the entity's icon is used in case a icon is not set in the blueprint settings. Solves #963 * Updated translations - Slovenian Based on: - https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/940#discussioncomment-6665723 - https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/829#discussioncomment-6665751 * dutch (#974) * small ducht translations small ducht translations * Dutch translations --------- Co-authored-by: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> * Add-on support (#977) Moved climate settings to an add-on. Updated documentation. * Fixed link to addon climate docs * Fix change brightness when sleeping Prevents the panel to change screen brightness when sleeping. Solves #975 * Standardize HA service calls * Bump version to `4.0 dev` * Create customization.md This will reduce the need for: - #920 - #662 - #833 * Clean-up for customizations Clean up ESPHome in order to make easier the use of customizations. * Create Alarm page * Add page Alarm * Add Alarm docs Update docs to reflect the current state (new features & changes) * Creating "install.md" and update add-ons instructions * Add Alarm page buttons pics * Add link to Alarm on page Home * Create Alarm page * Alarm button font color * Add `keyb_num` page * Alarm Control Panel with PIN (#982) Implements an Alarm Control Panel page on NSPanel. Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/issues/66 Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/227 Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/issues/672 Partially solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/299#discussioncomment-4874612 Partially solves https://github.com/Blackymas/NSPanel_HA_Blueprint/issues/64#issuecomment-1566204490 Partially solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/718 * Fix alarm without pin not working Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/pull/930#issuecomment-1680981977 * Alarm page UI Fixed close button Disabled buttons are darker * Move Entities button to ESPHome Move logic behind Entities button (Home page) from Blueprint to ESPHome in order to gain performance on creating home page. * Human readable Uptime (#986) * Human readable Uptime * Uptime from Frenck code * Uptime with Frenck code * Updated Human Readable Uptime * Removed trailing spaces * Renamed sensor to "Last started" Sensor renamed Update moved to the boot process Clean-up --------- Co-authored-by: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> Co-authored-by: Edward Firmo <edward@costafirmo.com> * Update alarm icon & color * Revert `fast_connect` back to `false` * Extended chars on buttons pages (#988) Replaces #740 Probably solves #664 Probably solves #738 Probably solves #987 * Removed `fast_connect` * Support to `code_arm_required` Only shows the alarm PIN keyboard if a code is required for arming (or when disarming). * Update alarm icon on home page Refresh icon when alarm state changes. * Fix alarm icon not updating on home page * Home buttons new format - Alarm Modernise the button Alarm flow on page Home to improve performance. * Home buttons new format - Entities Modernise the button "Entities" flow on page Home to improve performance. * Home buttons new format - QRcode Modernise the button "QRcode" flow on page Home to improve performance. * Home buttons new format - Notification Modernise the button "Notification" flow on page Home to improve performance. I haven't moved the code from the Blueprint to ESPHome yet, as I will leave this for when we rebuild the Notification flow in the near future (hopefully), so the performance gains may not be perceived now. Just aligning with other buttons format. * Adding screenshots * Delete ReleaseNotes.md Moved to the release * New entity filter format This new format was released with HA v2023.4 and the old one will be deprecated soon. * Fix Alarm page bypass icon * Bump version to 4.0 * Rename `addon_climate_heat` * Simplify climate substitutions * Add support for `addon_climate_cool` * Removed `${verbose_log}` Use logger level `VERBOSE` instead * Fix script call * Clean up general entities & fallback Store inputs into variables only when needed. Removed fallback mode - Replaced by ESPHome local control when the relay is assigned to the button in the blueprint. * Phase out sensor `nspanel_event` (partially) This sensor is being replaced by event calls. * uptime sensors (#998) * Create ReleaseNotes.md * Fix Climate page when embedded climate And also added a lot of logs which should be removed later as it takes from memory. Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/995#discussioncomment-6835260 * Move brightness control to global var Clean up page Home * Alarm page translations - Finnish https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/940#discussioncomment-6857262 * Exported pics * Clean-up TFT - Removed a bunch of unused pics - Changed page indicator to new format (which will allow future development to hide unused pages) - Standardized close button in most pages * Fixed background pics - Entities pages - Weather pages * Standardize close button * Add "Alarm" section * Support to wake-up page on `wake_up_display` service This changes the behavior of a service introduced by #734. * Optimize `wake_up_display` service * Fix icon font sizes 10 and 64 Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/issues/960#issuecomment-1701903604 And also remove all the unnecessary `wait_until` * Fix Settings page element ids Partially solves https://github.com/Blackymas/NSPanel_HA_Blueprint/issues/960#issuecomment-1702109668 * Add translation keys for `settings` page #1002 * Update settings page when brightness changes on HA Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/issues/960#issuecomment-1702149796 * Clean-up page settings * update docs (#1003) * updated docs * Update ReleaseNotes.md --------- Co-authored-by: Edward Firmo <94725493+edwardtfn@users.noreply.github.com> * Clean-up Cover page I'm preparing this page to have icons changing based on the device_class selected to a cover. * Clean-up boot delay * Enable `current_page` sensor by default Otherwise the system won´t update values unless the page is reloaded. * Use `current_page` in blueprint conditions One more step towards the phase out of `nspanelevent`. * Move `script.refresh_colors` to `service.global_settings` As this is called from a single point, there's no meaning of having a separated script. * Fix climate icon update Partially solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/995#discussioncomment-6891454 * Fix button show on climate page Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/995#discussioncomment-6891335 * Visual improvements on climate page - Add friendly name when embedded - Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/995#discussioncomment-6891465 - Make disable icons a bit darker - Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/995#discussioncomment-6893440 - Add space for page title in EU an US Land versions - Reset page timer when pressing/releasing on the slider - Partially solves #990 * Don't update values when page home is not visible To reduce load on Home Assistant and the network * Cleanup boot sequence Move some functionalities to ESPHome * Display internal sensor value when wifi is out Before it was showing on home page only when API was out. This adds a test for WiFi. * Fix `default_target_temperature` It also updates the page home when thermostat status changes (for the chips). Solves https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/995#discussioncomment-6897727 * Adding ID to components missing it * Renamed `wake_up_display` to `wake_up` * Re-arrange commands list * Add service `set_component_color` Deprecates the following services: - `send_command_font_color` - `send_command_background_color` * Fix button pages not showing * Adjusted time for HW long click * Fixed buttons on settings page * Minor adjustments to page climate And replace font 10 to size 48 (it was 64 since a few days ago). * Updates to breaking changes list * Page settings redesign Clean up the UI of settings page. Prepare for translations. * Enable translations of Settings page * Notification word-wrap For EU and US_LAND only, for now. * Notifications page rebuilt - Notification button processed on ESPHome (as all the info is there) - Added word-wrap for main text - Expanded text size - Handling display mode (used to define the number of chars per line on Notifications) - Versioning handling - As a consequence of the previous item. * Word-wrap buttons pages Taking advantage of the algorithm created for notifications. * Word-wrap for Alarm page * Version mismatch notication * Fix ESPHome not starting with older TFT * Rebuilt home page status bar update * Updated translations - Italian Based on https://github.com/Blackymas/NSPanel_HA_Blueprint/discussions/1002#discussioncomment-6926846 Thanks @MaiPiu * Fix `Nextion reported variable name invalid!` * Fix `Nextion variable invalid` * Handle `embedded_indoor_temperature` Internal temperature display will be handled locally (ESPHome) when no other sensor is selected. * Review temperature correction engine * Fix display climate chip * update `temp_nspanel` when correction changes * Fix `Fan` page not open with long press HW button Solves #1007 * Minor adjustments on settings page * version 4.0 ready for release * Clean-up docs --------- Co-authored-by: bkbartk <bartkock@outlook.com> Co-authored-by: w00zy <WZYProjects+github@gmail.com>
2119 lines
89 KiB
YAML
2119 lines
89 KiB
YAML
#####################################################################################################
|
||
##### NSPANEL ESPHOME created by Blackymas - https://github.com/Blackymas/NSPanel_HA_Blueprint #####
|
||
##### ADVANCED CONFIG + FULL ESPHOME CODE! #####
|
||
##### 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:
|
||
|
||
##### DON'T CHANGE THIS #####
|
||
version: "4.0"
|
||
#############################
|
||
|
||
##### WIFI SETUP #####
|
||
wifi:
|
||
networks:
|
||
- id: wifi_default
|
||
ssid: ${wifi_ssid}
|
||
password: ${wifi_password}
|
||
power_save_mode: none
|
||
ap:
|
||
ssid: "${device_name}"
|
||
password: ${wifi_password}
|
||
|
||
##### ESPHOME CONFIGURATION #####
|
||
esphome:
|
||
name: ${device_name}
|
||
min_version: 2023.5.0
|
||
|
||
##### TYPE OF ESP BOARD #####
|
||
esp32:
|
||
board: esp32dev
|
||
|
||
captive_portal:
|
||
|
||
web_server:
|
||
id: web_server_std
|
||
port: 80
|
||
auth:
|
||
username: admin
|
||
password: ${wifi_password}
|
||
|
||
##### OTA PASSWORD #####
|
||
ota:
|
||
id: ota_std
|
||
password: ${wifi_password}
|
||
safe_mode: true
|
||
reboot_timeout: 3min
|
||
num_attempts: 3
|
||
|
||
##### LOGGER #####
|
||
logger:
|
||
id: logger_std
|
||
|
||
##### ENABLE RINGTONE MUSIC SUPPORT #####
|
||
rtttl:
|
||
id: buzzer
|
||
output: buzzer_out
|
||
|
||
##### CONFIGURE INTERNAL BUZZER #####
|
||
output:
|
||
##### BUZZER FOR PLAYING RINGTONES #####
|
||
- platform: ledc
|
||
id: buzzer_out
|
||
pin:
|
||
number: 21
|
||
|
||
##### UART FOR NEXTION DISPLAY #####
|
||
uart:
|
||
id: tf_uart
|
||
tx_pin: 16
|
||
rx_pin: 17
|
||
baud_rate: 115200
|
||
|
||
##### Keeps time display updated #####
|
||
time:
|
||
- id: time_provider
|
||
platform: homeassistant
|
||
on_time:
|
||
- seconds: 0
|
||
then:
|
||
- script.execute:
|
||
id: refresh_datetime
|
||
on_time_sync:
|
||
then:
|
||
- component.update: api_timestamp
|
||
- component.update: device_timestamp
|
||
- logger.log: "System clock synchronized"
|
||
- script.execute:
|
||
id: refresh_datetime
|
||
|
||
##### START - BUTTON CONFIGURATION #####
|
||
button:
|
||
###### REBOOT BUTTON #####
|
||
- name: ${device_name} Restart
|
||
platform: restart
|
||
id: restart_nspanel
|
||
|
||
##### UPDATE TFT DISPLAY #####
|
||
- name: ${device_name} Update TFT display
|
||
platform: template
|
||
icon: mdi:file-sync
|
||
id: tft_update
|
||
entity_category: config
|
||
on_press:
|
||
- logger.log: "Button pressed: Update TFT display"
|
||
- binary_sensor.template.publish:
|
||
id: nextion_init
|
||
state: false
|
||
- delay: 16ms
|
||
- lambda: id(disp1).upload_tft();
|
||
|
||
##### EXIT REPARSE TFT DISPLAY #####
|
||
- name: ${device_name} Exit reparse
|
||
platform: template
|
||
icon: mdi:file-sync
|
||
id: tft_reparse_off
|
||
entity_category: config
|
||
on_press:
|
||
- logger.log: "Button pressed: Exit reparse"
|
||
- uart.write:
|
||
id: tf_uart
|
||
data: "DRAKJHSUYDGBNCJHGJKSHBDN"
|
||
- uart.write:
|
||
id: tf_uart
|
||
data: [0xFF, 0xFF, 0xFF]
|
||
|
||
##### START - API CONFIGURATION #####
|
||
api:
|
||
id: api_server
|
||
reboot_timeout: 0s
|
||
|
||
services:
|
||
|
||
##### SERVICE TO UPDATE THE HMI FILE ##############
|
||
- service: upload_tft
|
||
then:
|
||
- logger.log: "Service: upload_tft"
|
||
- binary_sensor.template.publish:
|
||
id: nextion_init
|
||
state: false
|
||
- lambda: 'id(disp1)->upload_tft();'
|
||
|
||
##### SERVICE TO UPDATE THE TFT FILE from URL #####
|
||
- service: upload_tft_url
|
||
variables:
|
||
url: string
|
||
then:
|
||
- logger.log: "Service: upload_tft_url"
|
||
- binary_sensor.template.publish:
|
||
id: nextion_init
|
||
state: false
|
||
- lambda: 'id(disp1)->set_tft_url(url.c_str());'
|
||
- lambda: 'id(disp1)->upload_tft();'
|
||
|
||
##### Service to send a command "printf" directly to the display #####
|
||
- service: send_command_printf
|
||
variables:
|
||
cmd: string
|
||
then:
|
||
- lambda: 'id(disp1).send_command_printf("%s", cmd.c_str());'
|
||
|
||
##### Service to send a command "text_printf" directly to the display #####
|
||
- service: send_command_text_printf
|
||
variables:
|
||
component: string
|
||
message: string
|
||
then:
|
||
- lambda: 'id(disp1).set_component_text_printf(component.c_str(), "%s", message.c_str());'
|
||
|
||
##### Service to send a command "component_value (Dualstate Button)" directly to the display #####
|
||
- service: send_command_value
|
||
variables:
|
||
component: string
|
||
message: int
|
||
then:
|
||
- lambda: 'id(disp1).set_component_value(component.c_str(), message);'
|
||
|
||
##### Service to send a command "hide componente" directly to the display #####
|
||
- service: send_command_hide ### unused ###
|
||
variables:
|
||
component: string
|
||
then:
|
||
- lambda: 'id(disp1).hide_component(component.c_str());'
|
||
|
||
##### Service to send a command "show componente" directly to the display #####
|
||
- service: send_command_show ### unused ###
|
||
variables:
|
||
component: string
|
||
then:
|
||
- lambda: 'id(disp1).show_component(component.c_str());'
|
||
|
||
##### Service to send a command "show ALL componente" directly to the display #####
|
||
- service: send_command_show_all ### unused ###
|
||
then:
|
||
- lambda: id(disp1).show_component("255");
|
||
|
||
##### Service to send a command "font color" directly to the display #####
|
||
- service: set_component_color
|
||
variables:
|
||
component: string
|
||
foreground: int[]
|
||
background: int[]
|
||
then:
|
||
- lambda: id(set_component_color).execute(component, foreground, background);
|
||
|
||
##### Service to send a command "font color" directly to the display #####
|
||
#- service: send_command_font_color
|
||
# variables:
|
||
# component: string
|
||
# message: int
|
||
# then:
|
||
# - lambda: 'id(disp1).set_component_font_color(component.c_str(), message);'
|
||
|
||
##### Service to send a command "background color" directly to the display #####
|
||
#- service: send_command_background_color
|
||
# variables:
|
||
# component: string
|
||
# message: int
|
||
# then:
|
||
# - lambda: 'id(disp1).set_component_background_color(component.c_str(), message);'
|
||
|
||
##### Service to show a notification-message on the screen #####
|
||
- service: notification_show
|
||
variables:
|
||
label: string
|
||
text: string
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("service.notification_show", "Starting");
|
||
ESP_LOGV("service.notification_show", "label: %s", label.c_str());
|
||
ESP_LOGV("service.notification_show", "text: %s", text.c_str());
|
||
ESP_LOGV("service.notification_show", "text length: %i", text.length());
|
||
|
||
id(disp1).send_command_printf("is_notification=1");
|
||
id(disp1).send_command_printf("page notification");
|
||
id(disp1).set_component_text_printf("notification.notifi_label", "%s", label.c_str());
|
||
|
||
id(display_wrapped_text).execute("notification.notifi_text01", text.c_str(), id(display_mode) == 2 ? 23 : 32);
|
||
|
||
id(notification_label).publish_state(label.c_str());
|
||
id(notification_text).publish_state(text.c_str());
|
||
- switch.turn_on: notification_unread
|
||
- if:
|
||
condition:
|
||
- switch.is_on: notification_sound
|
||
then:
|
||
- rtttl.play: "two short:d=4,o=5,b=100:16e6,16e6"
|
||
|
||
##### Service to clear the notification #####
|
||
- service: notification_clear
|
||
then:
|
||
- logger.log: "Service: notification_clear"
|
||
- ¬ification_clear
|
||
lambda: |-
|
||
id(disp1).send_command_printf("is_notification=0");
|
||
id(notification_label).publish_state("");
|
||
id(notification_text).publish_state("");
|
||
- switch.turn_off: notification_unread
|
||
|
||
##### 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:
|
||
- lambda: |-
|
||
ESP_LOGV("api.service.open_entity_settings_page", "Starting");
|
||
ESP_LOGV("api.service.open_entity_settings_page", "page: %s", page.c_str());
|
||
ESP_LOGV("api.service.open_entity_settings_page", "page_label: %s", page_label.c_str());
|
||
ESP_LOGV("api.service.open_entity_settings_page", "page_icon: %s", page_icon.c_str());
|
||
ESP_LOGV("api.service.open_entity_settings_page", "page_icon_color: %i, %i, %i", page_icon_color[0], page_icon_color[1], page_icon_color[2] );
|
||
ESP_LOGV("api.service.open_entity_settings_page", "entity: %s", entity.c_str());
|
||
ESP_LOGV("api.service.open_entity_settings_page", "back_page: %s", back_page.c_str());
|
||
id(disp1).set_component_text_printf("home.entity", "%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 != "climate")
|
||
{
|
||
id(set_component_color).execute("icon_state", page_icon_color, {});
|
||
//id(disp1).set_component_font_color("icon_state", page_icon_color);
|
||
}
|
||
if (page == "climate" and entity == "embedded_climate") id(addon_climate_set_climate_friendly_name).execute(page_label.c_str());
|
||
ESP_LOGV("api.service.open_entity_settings_page", "Finished");
|
||
|
||
##### Service to play a rtttl tones #####
|
||
# Example tones : https://codebender.cc/sketch:109888#RTTTL%20Songs.ino
|
||
- service: play_rtttl
|
||
variables:
|
||
song_str: string
|
||
then:
|
||
- rtttl.play:
|
||
rtttl: !lambda 'return song_str;'
|
||
|
||
# Service to show a QR code on the display (ex. for WiFi password)
|
||
- service: qrcode
|
||
variables:
|
||
title: string
|
||
qrcode: string
|
||
show: bool
|
||
then:
|
||
- lambda: |-
|
||
id(disp1).set_component_text_printf("qrcode.qrcode_label", "%s", title.c_str());
|
||
id(disp1).set_component_text_printf("qrcode.qrcode_value", "%s", qrcode.c_str());
|
||
if (show) id(disp1).send_command_printf("page qrcode");
|
||
|
||
#### Service to set climate state ####
|
||
- service: set_climate
|
||
variables:
|
||
current_temp: float
|
||
target_temp: float
|
||
temp_step: int
|
||
total_steps: int
|
||
temp_offset: int
|
||
climate_icon: string
|
||
embedded_climate: bool
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("api.service.set_climate", "climateslider.maxval=%i", total_steps);
|
||
ESP_LOGV("api.service.set_climate", "temp_offset=%f", temp_offset);
|
||
ESP_LOGV("api.service.set_climate", "temp_step=%f", temp_step);
|
||
ESP_LOGV("api.service.set_climate", "current_temp=%f", current_temp);
|
||
ESP_LOGV("api.service.set_climate", "target_temp=%f", target_temp);
|
||
ESP_LOGV("api.service.set_climate", "target_icon=%s", climate_icon.c_str());
|
||
ESP_LOGV("api.service.set_climate", "embedded=%i", (embedded_climate) ? 1 : 0);
|
||
|
||
- script.execute:
|
||
id: set_climate
|
||
current_temp: !lambda "return current_temp;"
|
||
target_temp: !lambda "return target_temp;"
|
||
temp_step: !lambda "return temp_step;"
|
||
total_steps: !lambda "return total_steps;"
|
||
temp_offset: !lambda "return temp_offset;"
|
||
climate_icon: !lambda "return climate_icon;"
|
||
embedded_climate: !lambda "return embedded_climate;"
|
||
|
||
#### Service to set the buttons ####
|
||
- service: set_button
|
||
variables:
|
||
btn_id: string
|
||
btn_pic: int
|
||
btn_bg: int[]
|
||
btn_icon_font: int[]
|
||
btn_txt_font: int[]
|
||
btn_bri_font: int[]
|
||
btn_icon: string
|
||
btn_label: string
|
||
btn_bri_txt: string
|
||
then:
|
||
- lambda: |-
|
||
// ESP_LOGV("nextion", "set button %s", btn_id.c_str());
|
||
std::string btnicon = btn_id.c_str() + std::string("icon");
|
||
std::string btntext = btn_id.c_str() + std::string("text");
|
||
std::string btnbri = btn_id.c_str() + std::string("bri");
|
||
id(disp1).send_command_printf("%spic.pic=%i", btn_id.c_str(), btn_pic);
|
||
id(set_component_color).execute(btnicon.c_str(), btn_icon_font, btn_bg);
|
||
id(set_component_color).execute(btntext.c_str(), btn_txt_font, btn_bg);
|
||
id(set_component_color).execute(btnbri.c_str(), btn_bri_font, btn_bg);
|
||
//id(disp1).set_component_background_color(btnicon.c_str(), btn_bg);
|
||
//id(disp1).set_component_background_color(btntext.c_str(), btn_bg);
|
||
//id(disp1).set_component_background_color(btnbri.c_str(), btn_bg);
|
||
//id(disp1).set_component_font_color(btnicon.c_str(), btn_icon_font);
|
||
//id(disp1).set_component_font_color(btntext.c_str(), btn_txt_font);
|
||
//id(disp1).set_component_font_color(btnbri.c_str(), btn_bri_font);
|
||
id(disp1).set_component_text_printf(btnicon.c_str(), "%s", btn_icon.c_str());
|
||
//id(disp1).set_component_text_printf(btntext.c_str(), "%s", btn_label.c_str());
|
||
id(display_wrapped_text).execute(btntext.c_str(), btn_label.c_str(), 10);
|
||
// id(disp1).set_component_text_printf(btnbri.c_str(), "%s", btn_bri_txt.c_str());
|
||
if (strcmp(btn_bri_txt.c_str(), "0") != 0) {
|
||
id(disp1).set_component_text_printf(btnbri.c_str(), "%s", btn_bri_txt.c_str());
|
||
} else {
|
||
id(disp1).set_component_text_printf(btnbri.c_str(), " ");
|
||
}
|
||
|
||
##### SERVICE TO WAKE UP THE DISPLAY #####
|
||
- service: wake_up
|
||
variables:
|
||
reset_timer: bool
|
||
then:
|
||
- lambda: |-
|
||
if (id(current_page).state == "home")
|
||
{
|
||
id(disp1).send_command_printf("home.dimtimer.en=1");
|
||
id(disp1).send_command_printf("home.sleeptimer.en=1");
|
||
}
|
||
else if (id(current_page).state == "screensaver") id(disp1).send_command_printf("page %i", id(wakeup_page_id));
|
||
id(disp1).send_command_printf("dim=brightness");
|
||
if (reset_timer) id(page_timer)->execute(int(id(page_timeout).state));
|
||
|
||
#### Service to set the entities ####
|
||
- service: set_entity
|
||
variables:
|
||
ent_id: string
|
||
ent_icon: string
|
||
ent_label: string
|
||
ent_value: string
|
||
ent_value_xcen: string
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("service.set_entity", "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");
|
||
std::string entxcen = ent_id.c_str() + std::string(".xcen=") + ent_value_xcen.c_str();
|
||
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());
|
||
if (strcmp(ent_value_xcen.c_str(), "0") != 0) id(disp1).send_command_printf("%s", entxcen.c_str());
|
||
|
||
##### Service for transferring global settings from the blueprint to ESPHome #####
|
||
- service: global_settings
|
||
variables:
|
||
blueprint_version: string
|
||
relay1_local_control: bool
|
||
relay1_icon: string
|
||
relay1_icon_color: int
|
||
relay2_local_control: bool
|
||
relay2_icon: string
|
||
relay2_icon_color: int
|
||
date_color: int
|
||
time_format: string
|
||
time_color: int
|
||
embedded_climate: bool
|
||
embedded_indoor_temperature: bool
|
||
temperature_unit_is_fahrenheit: bool
|
||
wakeup_page: int
|
||
then:
|
||
- lambda: |-
|
||
// Logs - Begin
|
||
ESP_LOGV("service.global_settings", "Starting");
|
||
ESP_LOGD("service.global_settings", "Blueprint version: %s", blueprint_version.c_str());
|
||
ESP_LOGV("service.global_settings", "relay1_local_control: %i", (relay1_local_control) ? 1 : 0);
|
||
ESP_LOGV("service.global_settings", "relay1_icon: %s", relay1_icon.c_str());
|
||
ESP_LOGV("service.global_settings", "relay1_icon_color: %i", relay1_icon_color);
|
||
ESP_LOGV("service.global_settings", "relay2_local_control: %i", (relay2_local_control) ? 1 : 0);
|
||
ESP_LOGV("service.global_settings", "relay2_icon: %s", relay2_icon.c_str());
|
||
ESP_LOGV("service.global_settings", "relay2_icon_color: %i", relay2_icon_color);
|
||
ESP_LOGV("service.global_settings", "date_color: %i", date_color);
|
||
ESP_LOGV("service.global_settings", "time_format: %s", time_format.c_str());
|
||
ESP_LOGV("service.global_settings", "time_color: %i", time_color);
|
||
ESP_LOGV("service.global_settings", "embedded_climate: %i", (embedded_climate) ? 1 : 0);
|
||
ESP_LOGV("service.global_settings", "embedded_indoor_temperature: %i", (embedded_indoor_temperature) ? 1 : 0);
|
||
ESP_LOGV("service.global_settings", "temperature_unit_is_fahrenheit: %i", (temperature_unit_is_fahrenheit) ? 1 : 0);
|
||
ESP_LOGV("service.global_settings", "wakeup_page: %i", wakeup_page);
|
||
|
||
// Blueprint version
|
||
id(version_blueprint) = blueprint_version;
|
||
id(check_versions).execute();
|
||
|
||
// Relays
|
||
id(relay1_local).publish_state(relay1_local_control);
|
||
id(relay2_local).publish_state(relay2_local_control);
|
||
id(home_relay1_icon) = relay1_icon.c_str();
|
||
id(home_relay2_icon) = relay2_icon.c_str();
|
||
id(home_relay1_icon_color) = relay1_icon_color;
|
||
id(home_relay2_icon_color) = relay2_icon_color;
|
||
|
||
// Localization
|
||
id(mui_time_format) = time_format;
|
||
|
||
// Date/Time colors
|
||
id(home_date_color) = date_color;
|
||
id(home_time_color) = time_color;
|
||
|
||
// Embedded thermostat
|
||
id(addon_climate_global_settings)->execute(embedded_climate);
|
||
|
||
// Indoor temperature
|
||
id(embedded_indoor_temp) = embedded_indoor_temperature;
|
||
id(temp_unit_fahrenheit) = temperature_unit_is_fahrenheit;
|
||
id(display_embedded_temp)->execute();
|
||
|
||
// Wakeup page
|
||
ESP_LOGV("service.global_settings", "Wakeup page - Start");
|
||
id(wakeup_page_id) = wakeup_page;
|
||
|
||
// Refresh colors of global components
|
||
ESP_LOGV("service.global_settings", "Refresh colors of global components");
|
||
id(disp1).set_component_font_color("home.date", id(home_date_color));
|
||
id(disp1).set_component_font_color("home.time", id(home_time_color));
|
||
id(disp1).set_component_font_color("home.icon_top_01", id(home_relay1_icon_color));
|
||
id(disp1).set_component_font_color("home.icon_top_02", id(home_relay2_icon_color));
|
||
|
||
// Update home page
|
||
ESP_LOGV("service.global_settings", "Update home page");
|
||
id(update_page_home).execute();
|
||
|
||
- if:
|
||
condition:
|
||
- text_sensor.state: # Is boot page visible?
|
||
id: current_page
|
||
state: 'boot'
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("service.global_settings", "Boot page is visible");
|
||
id(disp1).set_component_text_printf("boot.bluep_version", "%s", blueprint_version.c_str());
|
||
ESP_LOGV("service.global_settings", "Wait a bit");
|
||
- wait_until:
|
||
condition:
|
||
- not:
|
||
- text_sensor.state: # Is boot page visible?
|
||
id: current_page
|
||
state: 'boot'
|
||
timeout: 2s
|
||
- if:
|
||
condition:
|
||
- text_sensor.state: # Avoid this being called twice by multiple boot triggers
|
||
id: current_page
|
||
state: 'boot'
|
||
then:
|
||
- if:
|
||
condition:
|
||
switch.is_on: notification_sound
|
||
then:
|
||
- lambda: ESP_LOGV("service.global_settings", "Play boot sound");
|
||
- rtttl.play:
|
||
rtttl: 'two short:d=4,o=5,b=100:16e6,16e6'
|
||
- lambda: id(disp1).send_command_printf("page %i", id(wakeup_page_id));
|
||
|
||
- lambda: ESP_LOGV("service.global_settings", "Finished");
|
||
|
||
#### Service to populate the page Home #####
|
||
- service: page_home
|
||
variables:
|
||
notification_icon: string
|
||
notification_icon_color_normal: int[]
|
||
notification_icon_color_unread: int[]
|
||
qrcode: bool
|
||
qrcode_icon: string
|
||
qrcode_icon_color: int[]
|
||
entities_pages: bool
|
||
entities_pages_icon: string
|
||
entities_pages_icon_color: int[]
|
||
alarm_state: string
|
||
then:
|
||
- lambda: |-
|
||
// Logs - Begin
|
||
ESP_LOGV("service.page_home_settings", "Starting");
|
||
ESP_LOGV("service.page_home_settings", "notification_icon: %s", notification_icon.c_str());
|
||
ESP_LOGV("service.page_home_settings", "qrcode: %i", (qrcode) ? 1 : 0);
|
||
ESP_LOGV("service.page_home_settings", "qrcode_icon: %s", qrcode_icon.c_str());
|
||
ESP_LOGV("service.page_home_settings", "entities_pages: %i", (entities_pages) ? 1 : 0);
|
||
ESP_LOGV("service.page_home_settings", "entities_pages_icon: %s", entities_pages_icon.c_str());
|
||
ESP_LOGV("service.page_home_settings", "alarm_state: %s", alarm_state.c_str());
|
||
|
||
// Notification button
|
||
ESP_LOGV("service.page_home_settings", "Notification button - Start");
|
||
id(disp1).send_command_printf("is_notification=%i", (id(notification_text).state.empty() and id(notification_label).state.empty()) ? 0 : 1);
|
||
id(disp1).set_component_text_printf("home.bt_notific", "%s", notification_icon.c_str());
|
||
id(set_component_color).execute("home.bt_notific", id(notification_unread).state ? notification_icon_color_unread : notification_icon_color_normal, {});
|
||
id(home_notify_icon_color_normal) = notification_icon_color_normal;
|
||
id(home_notify_icon_color_unread) = notification_icon_color_unread;
|
||
|
||
// QRCode button
|
||
ESP_LOGV("service.page_home_settings", "QRcode button - Start");
|
||
id(disp1).send_command_printf("is_qrcode=%i", (qrcode) ? 1 : 0);
|
||
id(disp1).set_component_text_printf("home.bt_qrcode", "%s", qrcode_icon.c_str());
|
||
id(set_component_color).execute("home.bt_qrcode", qrcode_icon_color, {});
|
||
|
||
// Entities pages button
|
||
ESP_LOGV("service.page_home_settings", "Entities pages button - Start");
|
||
id(disp1).send_command_printf("is_entities=%i", (entities_pages) ? 1 : 0);
|
||
id(disp1).set_component_text_printf("home.bt_entities", "%s", entities_pages_icon.c_str());
|
||
id(set_component_color).execute("home.bt_entities", entities_pages_icon_color, {});
|
||
|
||
// Alarm button
|
||
ESP_LOGV("service.page_home_settings", "Alarm button - Start");
|
||
id(disp1).send_command_printf("is_alarm=%i", (alarm_state=="" or alarm_state.empty()) ? 0 : 1);
|
||
id(update_alarm_icon)->execute("home.bt_alarm", alarm_state.c_str());
|
||
|
||
// Logs - End
|
||
ESP_LOGV("service.page_home_settings", "Finished");
|
||
|
||
#### Service to populate the page Settings #####
|
||
- service: page_settings
|
||
variables:
|
||
reboot: string
|
||
sleep_mode: string
|
||
brightness: string
|
||
dimming: string
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("service.page_settings", "Starting");
|
||
ESP_LOGV("service.page_settings", "reboot: %s", reboot.c_str());
|
||
ESP_LOGV("service.page_settings", "sleep_mode: %s", sleep_mode.c_str());
|
||
ESP_LOGV("service.page_settings", "brightness: %s", brightness.c_str());
|
||
ESP_LOGV("service.page_settings", "dimming: %s", dimming.c_str());
|
||
if (not reboot.empty()) id(disp1).set_component_text_printf("settings.lbl_reboot", " %s", reboot.c_str());
|
||
if (not sleep_mode.empty()) id(disp1).set_component_text_printf("settings.lbl_sleep", " %s", sleep_mode.c_str());
|
||
if (not brightness.empty()) id(disp1).set_component_text_printf("settings.lbl_brightness", "%s", brightness.c_str());
|
||
if (not dimming.empty()) id(disp1).set_component_text_printf("settings.lbl_dimming", "%s", dimming.c_str());
|
||
|
||
#### Service to populate the alarm settings page #####
|
||
- service: alarm_settings
|
||
variables:
|
||
page_title: string
|
||
state: string
|
||
supported_features: int
|
||
code_format: string
|
||
code_arm_required: bool
|
||
entity: string
|
||
mui_alarm: string[] #std::vector<std::string> #std::map
|
||
then:
|
||
- lambda: |-
|
||
// Logs - Begin
|
||
ESP_LOGV("service.alarm_settings", "Starting");
|
||
ESP_LOGV("service.alarm_settings", "page_title: %s", page_title.c_str());
|
||
ESP_LOGV("service.alarm_settings", "state: %s", state.c_str());
|
||
ESP_LOGV("service.alarm_settings", "supported_features: %i", supported_features);
|
||
ESP_LOGV("service.alarm_settings", "code_format: %s", code_format.c_str());
|
||
ESP_LOGV("service.alarm_settings", "code_arm_required: %i", (code_arm_required) ? 1 : 0);
|
||
ESP_LOGV("service.alarm_settings", "entity: %s", entity.c_str());
|
||
|
||
// set alarm icon on home page
|
||
ESP_LOGV("service.alarm_settings", "Updating home page icon");
|
||
id(disp1).send_command_printf("is_alarm=%i", (state=="" or state.empty()) ? 0 : 1);
|
||
id(update_alarm_icon)->execute("home.bt_alarm", state.c_str());
|
||
|
||
// Is page Alarm visible?
|
||
if (id(current_page).state=="alarm")
|
||
{ // Update alarm page
|
||
ESP_LOGV("service.alarm_settings", "Updating alarm page");
|
||
// Alarm page - Header
|
||
id(update_alarm_icon)->execute("icon_state", state.c_str());
|
||
id(disp1).set_component_text_printf("page_label", "%s", page_title.c_str());
|
||
id(disp1).set_component_text_printf("code_format", "%s", code_format.c_str());
|
||
if (code_arm_required) id(disp1).set_component_text_printf("code_arm_req", "1"); else id(disp1).set_component_text_printf("code_arm_req", "0");
|
||
id(disp1).set_component_text_printf("entity", "%s", entity.c_str());
|
||
|
||
// Alarm page - Button's icons
|
||
id(disp1).set_component_text_printf("bt_home_icon", "\uE689"); //mdi:shield-home
|
||
id(disp1).set_component_text_printf("bt_away_icon", "\uE99C"); //mdi:shield-lock
|
||
id(disp1).set_component_text_printf("bt_night_icon", "\uF827"); //mdi:shield-moon
|
||
id(disp1).set_component_text_printf("bt_vacat_icon", "\uE6BA"); //mdi:shield-airplane
|
||
id(disp1).set_component_text_printf("bt_bypass_icon", "\uE77F"); //mdi:shield-half-full
|
||
id(disp1).set_component_text_printf("bt_disarm_icon", "\uE99D"); //mdi:shield-off
|
||
|
||
// Alarm page - Button's text
|
||
id(display_wrapped_text).execute("bt_home_text", mui_alarm[0].c_str(), 10);
|
||
id(display_wrapped_text).execute("bt_away_text", mui_alarm[1].c_str(), 10);
|
||
id(display_wrapped_text).execute("bt_night_text", mui_alarm[2].c_str(), 10);
|
||
id(display_wrapped_text).execute("bt_vacat_text", mui_alarm[3].c_str(), 10);
|
||
id(display_wrapped_text).execute("bt_bypass_text", mui_alarm[4].c_str(), 10);
|
||
id(display_wrapped_text).execute("bt_disarm_text", mui_alarm[5].c_str(), 10);
|
||
|
||
// Alarm page - Buttons
|
||
if (supported_features & 1) // Alarm - Button - Home
|
||
{
|
||
id(disp1).send_command_printf("bt_home_pic.pic=%i", (state=="armed_home") ? 43 : 42);
|
||
id(disp1).set_component_background_color("bt_home_text", (state=="armed_home") ? 19818 : 52857);
|
||
id(disp1).set_component_background_color("bt_home_icon", (state=="armed_home") ? 19818 : 52857);
|
||
id(disp1).set_component_font_color("bt_home_text", (state=="armed_home") ? 65535 : 0);
|
||
id(disp1).set_component_font_color("bt_home_icon", (state=="armed_home") ? 65535 : 0);
|
||
if (state=="armed_home") id(disp1).hide_component("bt_home"); else id(disp1).show_component("bt_home");
|
||
}
|
||
if (supported_features & 2) // Alarm - Button - Away
|
||
{
|
||
id(disp1).send_command_printf("bt_away_pic.pic=%i", (state=="armed_away") ? 43 : 42);
|
||
id(disp1).set_component_background_color("bt_away_text", (state=="armed_away") ? 19818 : 52857);
|
||
id(disp1).set_component_background_color("bt_away_icon", (state=="armed_away") ? 19818 : 52857);
|
||
id(disp1).set_component_font_color("bt_away_text", (state=="armed_away") ? 65535 : 0);
|
||
id(disp1).set_component_font_color("bt_away_icon", (state=="armed_away") ? 65535 : 0);
|
||
if (state=="armed_away") id(disp1).hide_component("bt_away"); else id(disp1).show_component("bt_away");
|
||
}
|
||
if (supported_features & 4) // Alarm - Button - Night
|
||
{
|
||
id(disp1).send_command_printf("bt_night_pic.pic=%i", (state=="armed_night") ? 43 : 42);
|
||
id(disp1).set_component_background_color("bt_night_text", (state=="armed_night") ? 19818 : 52857);
|
||
id(disp1).set_component_background_color("bt_night_icon", (state=="armed_night") ? 19818 : 52857);
|
||
id(disp1).set_component_font_color("bt_night_text", (state=="armed_night") ? 65535 : 0);
|
||
id(disp1).set_component_font_color("bt_night_icon", (state=="armed_night") ? 65535 : 0);
|
||
if (state=="armed_night") id(disp1).hide_component("bt_night"); else id(disp1).show_component("bt_night");
|
||
}
|
||
if (supported_features & 32) // Alarm - Button - Vacation
|
||
{
|
||
id(disp1).send_command_printf("bt_vacat_pic.pic=%i", (state=="armed_vacation") ? 43 : 42);
|
||
id(disp1).set_component_background_color("bt_vacat_text", (state=="armed_vacation") ? 19818 : 52857);
|
||
id(disp1).set_component_background_color("bt_vacat_icon", (state=="armed_vacation") ? 19818 : 52857);
|
||
id(disp1).set_component_font_color("bt_vacat_text", (state=="armed_vacation") ? 65535 : 0);
|
||
id(disp1).set_component_font_color("bt_vacat_icon", (state=="armed_vacation") ? 65535 : 0);
|
||
if (state=="armed_vacation") id(disp1).hide_component("bt_vacat"); else id(disp1).show_component("bt_vacat");
|
||
}
|
||
if (supported_features & 16) // Alarm - Button - Custom bypass
|
||
{
|
||
id(disp1).send_command_printf("bt_bypass_pic.pic=%i", (state=="armed_bypass") ? 43 : 42);
|
||
id(disp1).set_component_background_color("bt_bypass_text", (state=="armed_bypass") ? 19818 : 52857);
|
||
id(disp1).set_component_background_color("bt_bypass_icon", (state=="armed_bypass") ? 19818 : 52857);
|
||
id(disp1).set_component_font_color("bt_bypass_text", (state=="armed_bypass") ? 65535 : 0);
|
||
id(disp1).set_component_font_color("bt_bypass_icon", (state=="armed_bypass") ? 65535 : 0);
|
||
if (state=="armed_bypass") id(disp1).hide_component("bt_bypass"); else id(disp1).show_component("bt_bypass");
|
||
}
|
||
if ( true ) // Alarm - Button - Disarm
|
||
{
|
||
id(disp1).send_command_printf("bt_disarm_pic.pic=%i", (state=="disarmed") ? 43 : 42);
|
||
id(disp1).set_component_background_color("bt_disarm_text", (state=="disarmed") ? 19818 : 52857);
|
||
id(disp1).set_component_background_color("bt_disarm_icon", (state=="disarmed") ? 19818 : 52857);
|
||
id(disp1).set_component_font_color("bt_disarm_text", (state=="disarmed") ? 65535 : 0);
|
||
id(disp1).set_component_font_color("bt_disarm_icon", (state=="disarmed") ? 65535 : 0);
|
||
if (state=="disarmed") id(disp1).hide_component("bt_disarm"); else id(disp1).show_component("bt_disarm");
|
||
}
|
||
}
|
||
|
||
// Logs - End
|
||
ESP_LOGV("service.alarm_settings", "Finished");
|
||
|
||
##### START - GLOBALS CONFIGURATION #####
|
||
globals:
|
||
|
||
##### Display mode (1 = EU, 2 = US, 3 = US Landscape)
|
||
- id: display_mode
|
||
type: int
|
||
restore_value: true
|
||
initial_value: '0'
|
||
|
||
##### Save Display Brightness for NSPanel reboot #####
|
||
- id: display_brightness_global
|
||
type: int
|
||
restore_value: true
|
||
initial_value: '100'
|
||
|
||
##### Save Display DIM Brightness for NSPanel reboot
|
||
- id: display_dim_brightness_global
|
||
type: int
|
||
restore_value: true
|
||
initial_value: '10'
|
||
|
||
##### Temperature unit #####
|
||
##### Is embedded sensor used for indoor temperature? #####
|
||
- id: embedded_indoor_temp
|
||
type: bool
|
||
restore_value: true
|
||
initial_value: 'true'
|
||
- id: temp_unit_fahrenheit
|
||
type: bool
|
||
restore_value: true
|
||
initial_value: 'false'
|
||
|
||
##### Date/time formats #####
|
||
#- id: mui_date_format
|
||
# type: std::string
|
||
# restore_value: no
|
||
# initial_value: '"%A, %d.%m"'
|
||
- id: home_date_color
|
||
type: int
|
||
restore_value: true
|
||
initial_value: '65535'
|
||
|
||
- id: mui_time_format
|
||
type: std::string
|
||
restore_value: no
|
||
initial_value: '"%H:%M"'
|
||
|
||
- id: home_time_color
|
||
type: int
|
||
restore_value: true
|
||
initial_value: '65535'
|
||
|
||
##### Relay icons #####
|
||
- id: home_relay1_icon
|
||
type: std::string
|
||
restore_value: false
|
||
initial_value: ''
|
||
|
||
- id: home_relay1_icon_color
|
||
type: int
|
||
restore_value: true
|
||
initial_value: '65535'
|
||
|
||
- id: home_relay2_icon
|
||
type: std::string
|
||
restore_value: false
|
||
initial_value: ''
|
||
|
||
- id: home_relay2_icon_color
|
||
type: int
|
||
restore_value: true
|
||
initial_value: '65535'
|
||
|
||
- id: home_notify_icon_color_normal
|
||
type: std::vector<int>
|
||
restore_value: false
|
||
#initial_value: '52857'
|
||
|
||
- id: home_notify_icon_color_unread
|
||
type: std::vector<int>
|
||
restore_value: false
|
||
#initial_value: '63488'
|
||
|
||
##### Wakeup page ID #####
|
||
- id: wakeup_page_id
|
||
type: int
|
||
restore_value: true
|
||
initial_value: '0'
|
||
|
||
##### Versions #####
|
||
- id: version_blueprint
|
||
type: std::string
|
||
restore_value: false
|
||
initial_value: ''
|
||
- id: version_tft
|
||
type: std::string
|
||
restore_value: false
|
||
initial_value: ''
|
||
|
||
##### START - BINARY SENSOR CONFIGURATION #####
|
||
binary_sensor:
|
||
|
||
###### LEFT BUTTON BELOW DISPLAY TO TOGGLE RELAY#####
|
||
- name: ${device_name} Left Button
|
||
platform: gpio
|
||
id: left_button
|
||
pin:
|
||
number: 14
|
||
inverted: true
|
||
on_multi_click:
|
||
- timing: &long_click-timing
|
||
- ON for at least 0.8s
|
||
then:
|
||
- logger.log: "Left button - Long click"
|
||
- script.execute:
|
||
id: ha_button
|
||
page: !lambda return id(current_page).state;
|
||
component: "hw_bt_left"
|
||
command: "long_click"
|
||
- timing: &short_click-timing
|
||
- ON for at most 0.8s
|
||
then:
|
||
- logger.log: "Left button - Short click"
|
||
- if:
|
||
condition:
|
||
- switch.is_on: relay1_local
|
||
then:
|
||
- switch.toggle: relay_1
|
||
- script.execute: refresh_relays
|
||
- script.execute:
|
||
id: ha_button
|
||
page: !lambda return id(current_page).state;
|
||
component: "hw_bt_left"
|
||
command: "short_click"
|
||
|
||
##### RIGHT BUTTON BELOW DISPLAY TO TOGGLE RELAY #####
|
||
- name: ${device_name} Right Button
|
||
platform: gpio
|
||
id: right_button
|
||
pin:
|
||
number: 27
|
||
inverted: true
|
||
on_multi_click:
|
||
- timing: *long_click-timing
|
||
then:
|
||
- logger.log: "Right button - Long click"
|
||
- script.execute:
|
||
id: ha_button
|
||
page: !lambda return id(current_page).state;
|
||
component: "hw_bt_right"
|
||
command: "long_click"
|
||
- timing: *short_click-timing
|
||
then:
|
||
- logger.log: "Right button - Short click"
|
||
- if:
|
||
condition:
|
||
- switch.is_on: relay2_local
|
||
then:
|
||
- switch.toggle: relay_2
|
||
- script.execute: refresh_relays
|
||
- script.execute:
|
||
id: ha_button
|
||
page: !lambda return id(current_page).state;
|
||
component: "hw_bt_right"
|
||
command: "short_click"
|
||
|
||
##### Restart NSPanel Button - Setting Page #####
|
||
- name: ${device_name} Restart
|
||
platform: nextion
|
||
page_id: 7
|
||
component_id: 9
|
||
internal: true
|
||
on_click:
|
||
- button.press: restart_nspanel
|
||
|
||
##### Restart NSPanel Button - Boot Page #####
|
||
- name: ${device_name} Restart
|
||
platform: nextion
|
||
page_id: 8
|
||
component_id: 4
|
||
internal: true
|
||
on_click:
|
||
- button.press: restart_nspanel
|
||
|
||
##### Sleep mode NSPanel Button #####
|
||
- name: ${device_name} Sleep mode
|
||
platform: nextion
|
||
page_id: 7
|
||
component_id: 10
|
||
internal: true
|
||
on_click:
|
||
- logger.log: "Sleep mode - Nextion toggle"
|
||
- switch.toggle: sleep_mode
|
||
|
||
##### global variable to keep track on whether the Nextion display is ready or not.
|
||
## Delays initial info from HA to the display #####
|
||
- name: ${device_name} Nextion display
|
||
id: nextion_init
|
||
platform: template
|
||
device_class: connectivity
|
||
publish_initial_state: true
|
||
entity_category: diagnostic
|
||
icon: mdi:tablet-dashboard
|
||
|
||
##### API connection status
|
||
- name: ${device_name} Status
|
||
platform: status
|
||
id: api_status
|
||
on_state:
|
||
then:
|
||
- script.execute:
|
||
id: refresh_wifi_icon
|
||
|
||
##### START - SENSOR CONFIGURATION #####
|
||
sensor:
|
||
|
||
##### Uptime Sensors #####
|
||
- name: ${device_name} Uptime seconds
|
||
id: uptime_sec
|
||
platform: uptime
|
||
internal: true
|
||
|
||
- name: ${device_name} API uptime
|
||
id: api_timestamp
|
||
platform: template
|
||
lambda: 'return id(time_provider).now().timestamp;'
|
||
internal: false
|
||
device_class: timestamp
|
||
entity_category: diagnostic
|
||
accuracy_decimals: 0
|
||
update_interval: never
|
||
|
||
- name: ${device_name} Device uptime
|
||
id: device_timestamp
|
||
platform: template
|
||
lambda: 'return (id(time_provider).now().timestamp - id(uptime_sec).state);'
|
||
internal: false
|
||
device_class: timestamp
|
||
entity_category: diagnostic
|
||
accuracy_decimals: 0
|
||
update_interval: never
|
||
|
||
##### WIFI Signal stregth
|
||
- name: ${device_name} RSSI
|
||
platform: wifi_signal
|
||
update_interval: 60s
|
||
on_value:
|
||
- script.execute:
|
||
id: refresh_wifi_icon
|
||
|
||
##### INTERNAL TEMPERATURE SENSOR, ADC VALUE #####
|
||
- id: ntc_source
|
||
platform: adc
|
||
pin: 38
|
||
update_interval: 60s
|
||
attenuation: 11db
|
||
|
||
##### INTERNAL TEMPERATURE SENSOR, adc reading converted to resistance (calculation)#####
|
||
- id: resistance_sensor
|
||
platform: resistance
|
||
sensor: ntc_source
|
||
configuration: DOWNSTREAM
|
||
resistor: 11.2kOhm
|
||
|
||
##### INTERNAL TEMPERATURE SENSOR, resistance to temperature (calculation) #####
|
||
- name: ${device_name} Temperature
|
||
platform: ntc
|
||
id: temp_nspanel
|
||
sensor: resistance_sensor
|
||
calibration:
|
||
b_constant: 3950
|
||
reference_temperature: 25°C
|
||
reference_resistance: 10kOhm
|
||
filters:
|
||
- lambda: return x + id(temperature_correction).state;
|
||
on_value:
|
||
then:
|
||
# Show panel's temperature if API or Wi-Fi are out
|
||
- lambda: id(display_embedded_temp)->execute();
|
||
|
||
###### Display Brightness GET VALUE FROM NSPanel SLIDER #####
|
||
- name: ${device_name} brightness Slider
|
||
platform: nextion
|
||
id: brightslider
|
||
variable_name: brightslider
|
||
internal: true
|
||
on_value:
|
||
then:
|
||
- number.set:
|
||
id: display_brightness
|
||
value: !lambda 'return int(x);'
|
||
|
||
###### Display DIM Brightness GET VALUE FROM NSPanel SLIDER #####
|
||
- name: ${device_name} dim brightness slider
|
||
platform: nextion
|
||
id: dimslider
|
||
variable_name: dimslider
|
||
internal: true
|
||
on_value:
|
||
then:
|
||
- number.set:
|
||
id: display_dim_brightness
|
||
value: !lambda 'return int(x);'
|
||
|
||
##### START - TEXT SENSOR CONFIGURATION #####
|
||
text_sensor:
|
||
|
||
##### Current page name #####
|
||
- name: ${device_name} current page
|
||
platform: template
|
||
id: current_page
|
||
internal: false
|
||
disabled_by_default: false
|
||
|
||
##### ESPhome version used to compile the app #####
|
||
- name: ${device_name} ESPhome Version
|
||
platform: version
|
||
disabled_by_default: true
|
||
|
||
- platform: wifi_info
|
||
ip_address:
|
||
name: ${device_name} IP
|
||
disabled_by_default: true
|
||
id: ip_address
|
||
ssid:
|
||
name: ${device_name} SSID
|
||
disabled_by_default: true
|
||
bssid:
|
||
name: ${device_name} BSSID
|
||
disabled_by_default: true
|
||
|
||
- name: ${device_name} Notification Label
|
||
platform: template
|
||
id: notification_label
|
||
|
||
- name: ${device_name} Notification Text
|
||
platform: template
|
||
id: notification_text
|
||
|
||
##### NSPanel event sensor, the main action sensor - push to HA #####
|
||
- name: ${device_name} NSPanel event
|
||
platform: nextion
|
||
nextion_id: disp1
|
||
id: disp1_nspanel_event
|
||
component_name: nspanelevent
|
||
internal: false
|
||
filters:
|
||
- lambda: |-
|
||
x = x.c_str();
|
||
x.shrink_to_fit();
|
||
return x;
|
||
on_value:
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("text_sensor.nspanelevent", "Starting");
|
||
id(page_timer)->execute(int(id(page_timeout).state));
|
||
DynamicJsonDocument doc(1024);
|
||
deserializeJson(doc, x);
|
||
std::string page = doc["page"];
|
||
std::string component = doc["component"];
|
||
std::string value = doc["value"];
|
||
std::string entity = doc["entity"];
|
||
ESP_LOGV("text_sensor.nspanelevent", "page: %s", page.c_str());
|
||
ESP_LOGV("text_sensor.nspanelevent", "component: %s", component.c_str());
|
||
ESP_LOGV("text_sensor.nspanelevent", "value: %s", value.c_str());
|
||
ESP_LOGV("text_sensor.nspanelevent", "entity: %s", entity.c_str());
|
||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||
{
|
||
{"type", "generic"},
|
||
{"page", page},
|
||
{"component", component},
|
||
{"value", value},
|
||
{"entity", entity}
|
||
});
|
||
if (component=="currentpage")
|
||
{
|
||
ESP_LOGD("text_sensor.nspanelevent", "New page: %s", page.c_str());
|
||
ESP_LOGV("text_sensor.nspanelevent", "Trigger HA event");
|
||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||
{
|
||
{"type", "page_changed"},
|
||
{"page", page},
|
||
{"entity", entity}
|
||
});
|
||
ESP_LOGV("text_sensor.nspanelevent", "Call add-ons scripts for new page");
|
||
id(addon_climate_set_climate).execute(page=="climate" and entity=="embedded_climate");
|
||
ESP_LOGV("text_sensor.nspanelevent", "Publish current_page sensor");
|
||
id(current_page).publish_state(page);
|
||
ESP_LOGV("text_sensor.nspanelevent", "Construct new page");
|
||
if (page=="home")
|
||
{
|
||
ESP_LOGV("text_sensor.nspanelevent", "Construct home page");
|
||
id(update_page_home).execute();
|
||
}
|
||
else if (page=="screensaver")
|
||
{
|
||
ESP_LOGV("text_sensor.nspanelevent", "Construct screensaver page");
|
||
id(disp1).set_component_value("orign", id(wakeup_page_id));
|
||
}
|
||
else if (page=="climate")
|
||
{
|
||
ESP_LOGV("text_sensor.nspanelevent", "Construct climate page");
|
||
id(disp1).set_component_text_printf("climate.button01_icon", "%s", "\uEE8D"); //mdi:calendar-sync
|
||
id(disp1).set_component_text_printf("climate.button02_icon", "%s", "\uE069"); //mdi:autorenew
|
||
id(disp1).set_component_text_printf("climate.button03_icon", "%s", "\uE237"); //mdi:fire
|
||
id(disp1).set_component_text_printf("climate.button04_icon", "%s", "\uE716"); //mdi:snowflake
|
||
id(disp1).set_component_text_printf("climate.button05_icon", "%s", "\uE58D"); //mdi:water-percent
|
||
id(disp1).set_component_text_printf("climate.button06_icon", "%s", "\uE20F"); //mdi:fan
|
||
id(disp1).set_component_text_printf("climate.button07_icon", "%s", "\uE424"); //mdi:power
|
||
id(addon_climate_update_page_climate)->execute();
|
||
}
|
||
else if (page=="cover")
|
||
{
|
||
ESP_LOGV("text_sensor.nspanelevent", "Construct cover page");
|
||
id(disp1).set_component_text_printf("cover.cover_stop", "%s", "\uE666"); //mdi:stop-circle-outline
|
||
// In the future this will be dynamically contructed based on the device_class
|
||
id(disp1).set_component_text_printf("cover.cover_open", "%s", "\uF11D"); //mdi:window-shutter-open
|
||
id(disp1).set_component_text_printf("cover.cover_close", "%s", "\uF11B"); //mdi:window-shutter
|
||
}
|
||
else if (page=="fan")
|
||
{
|
||
ESP_LOGV("text_sensor.nspanelevent", "Construct fan page");
|
||
id(disp1).set_component_text_printf("fan.button_on", "%s", "\uE20F"); //mdi:fan
|
||
id(disp1).set_component_text_printf("fan.button_off", "%s", "\uE81C"); //mdi:fan-off
|
||
id(disp1).set_component_text_printf("fan.button_up", "%s", "\uF46D"); //mdi:fan-chevron-up
|
||
id(disp1).set_component_text_printf("fan.button_down", "%s", "\uF46C"); //mdi:fan-chevron-down
|
||
}
|
||
else if (page=="keyb_num")
|
||
{
|
||
ESP_LOGV("text_sensor.nspanelevent", "Construct keyb_num page");
|
||
id(disp1).set_component_text_printf("keyb_num.bview", "%s", "\uE207"); //mdi:eye
|
||
id(disp1).set_component_text_printf("keyb_num.bclose", "%s", "\uE158"); //mdi:close-circle
|
||
id(disp1).set_component_text_printf("keyb_num.bclear", "%s", "\uE641"); //mdi:eraser-variant
|
||
id(disp1).set_component_text_printf("keyb_num.benter", "%s", "\uE12B"); //mdi:check
|
||
}
|
||
else if (page=="weather01") id(disp1).set_component_text_printf("page_index", "%s", "\uE764\uE765\uE765\uE765\uE765"); // 1/5
|
||
else if (page=="weather02") id(disp1).set_component_text_printf("page_index", "%s", "\uE765\uE764\uE765\uE765\uE765"); // 2/5
|
||
else if (page=="weather03") id(disp1).set_component_text_printf("page_index", "%s", "\uE765\uE765\uE764\uE765\uE765"); // 3/5
|
||
else if (page=="weather04") id(disp1).set_component_text_printf("page_index", "%s", "\uE765\uE765\uE765\uE764\uE765"); // 4/5
|
||
else if (page=="weather05") id(disp1).set_component_text_printf("page_index", "%s", "\uE765\uE765\uE765\uE765\uE764"); // 5/5
|
||
else if (page=="buttonpage01" or page=="entitypage01") id(disp1).set_component_text_printf("page_index", "%s", "\uE764\uE765\uE765\uE765"); // 1/4
|
||
else if (page=="buttonpage02" or page=="entitypage02") id(disp1).set_component_text_printf("page_index", "%s", "\uE765\uE764\uE765\uE765"); // 2/4
|
||
else if (page=="buttonpage03" or page=="entitypage03") id(disp1).set_component_text_printf("page_index", "%s", "\uE765\uE765\uE764\uE765"); // 3/4
|
||
else if (page=="buttonpage04" or page=="entitypage04") id(disp1).set_component_text_printf("page_index", "%s", "\uE765\uE765\uE765\uE764"); // 4/4
|
||
else if (page=="settings")
|
||
{
|
||
ESP_LOGV("text_sensor.nspanelevent", "Construct settings page");
|
||
//id(disp1).set_component_text_printf("bt_reboot", "%s", "\uE708"); //mdi:restart
|
||
id(disp1).set_component_text_printf("bt_sleep", "%s", (id(sleep_mode).state) ? "\uEA19" : "\uEA18"); //mdi:toggle-switch-outline or mdi:toggle-switch-off-outline
|
||
id(disp1).set_component_text_printf("icon_bright", "%s", "\uE0DD"); //mdi:brightness-5
|
||
id(disp1).set_component_text_printf("icon_dim", "%s", "\uE0DE"); //mdi:brightness-5
|
||
}
|
||
else if (page=="notification")
|
||
{
|
||
if (not id(confirmation_message).state)
|
||
{
|
||
id(disp1).set_component_text_printf("notification.notifi_label", "%s", id(notification_label).state.c_str());
|
||
id(display_wrapped_text).execute("notification.notifi_text01", id(notification_text).state.c_str(), id(display_mode) == 2 ? 23 : 32);
|
||
}
|
||
}
|
||
}
|
||
if (page=="boot")
|
||
{
|
||
// Detect display mode - Need review
|
||
if (doc.containsKey("display_mode"))
|
||
{
|
||
std::string display_mode_str = doc["display_mode"];
|
||
ESP_LOGV("text_sensor.nspanelevent", "display_mode: %s", display_mode_str.c_str());
|
||
float display_mode_float = stof(display_mode_str);
|
||
if (display_mode_float > 0) id(display_mode) = int(display_mode_float);
|
||
}
|
||
|
||
// Detect TFT version
|
||
if (doc.containsKey("version"))
|
||
{
|
||
std::string version_tmp = doc["version"];
|
||
id(version_tft) = version_tmp;
|
||
}
|
||
id(check_versions).execute();
|
||
|
||
// Detect timeout
|
||
if (component=="timeout")
|
||
{
|
||
ESP_LOGV("text_sensor.nspanelevent", "Trigger boot timeout event");
|
||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||
{
|
||
{"type", "boot"},
|
||
{"step", "timeout"},
|
||
{"value", value}
|
||
});
|
||
if (stof(value) >= 5)
|
||
{
|
||
ESP_LOGV("text_sensor.nspanelevent", "Jump to wakeup page: %i", id(wakeup_page_id));
|
||
id(disp1).send_command_printf("page %i", id(wakeup_page_id));
|
||
}
|
||
}
|
||
}
|
||
|
||
##### NSPanel event - Execute actions from ESPHome - NO push to HA #####
|
||
- name: ${device_name} NSPanel local event
|
||
platform: nextion
|
||
nextion_id: disp1
|
||
id: disp1_local_event
|
||
component_name: localevent
|
||
internal: True
|
||
filters:
|
||
- lambda: |-
|
||
x = x.c_str();
|
||
x.shrink_to_fit();
|
||
return x;
|
||
on_value:
|
||
then:
|
||
- lambda: |-
|
||
id(page_timer)->execute(int(id(page_timeout).state));
|
||
DynamicJsonDocument doc(1024);
|
||
deserializeJson(doc, x);
|
||
std::string domain = doc["domain"];
|
||
std::string key = doc["key"];
|
||
std::string value = doc["value"];
|
||
std::string entity = doc["entity"];
|
||
int embedded = doc["embedded"];
|
||
std::string service = "";
|
||
ESP_LOGV("text_sensor.localevent", "domain=%s", domain.c_str());
|
||
ESP_LOGV("text_sensor.localevent", "key=%s", key.c_str());
|
||
ESP_LOGV("text_sensor.localevent", "value=%s", value.c_str());
|
||
ESP_LOGV("text_sensor.localevent", "entity=%s", entity.c_str());
|
||
ESP_LOGV("text_sensor.localevent", "embedded=%i", embedded);
|
||
if (domain == "climate") id(service_call_climate)->execute(entity.c_str(), key.c_str(), value.c_str(), (embedded==1));
|
||
else if (domain == "alarm")
|
||
{
|
||
std::string code_format = doc["code_format"];
|
||
std::string code_arm_req = doc["code_arm_req"];
|
||
std::string title = doc["mui"];
|
||
if (code_format=="number" and (key=="disarm" or code_arm_req=="1"))
|
||
{
|
||
id(disp1).send_command_printf("page keyb_num");
|
||
id(disp1).set_component_value("keyb_num.page_id", 23); //Calling from Alarm page
|
||
id(disp1).set_component_text_printf("keyb_num.domain", "%s", domain.c_str());
|
||
id(disp1).set_component_text_printf("keyb_num.key", "%s", key.c_str());
|
||
id(disp1).set_component_text_printf("keyb_num.value", "%s", value.c_str());
|
||
id(disp1).set_component_text_printf("keyb_num.entity", "%s", entity.c_str());
|
||
id(disp1).set_component_text_printf("keyb_num.title", "%s", title.c_str());
|
||
}
|
||
else id(service_call_alarm_control_panel)->execute(entity.c_str(), key.c_str(), code_format.c_str(), "");
|
||
}
|
||
else if (domain == "keyb_num")
|
||
{
|
||
std::string base_domain = doc["base_domain"];
|
||
if (base_domain == "alarm")
|
||
{
|
||
std::string code_format = doc["code_format"];
|
||
std::string pin = doc["pin"];
|
||
id(service_call_alarm_control_panel)->execute(entity.c_str(), key.c_str(), code_format.c_str(), pin.c_str());
|
||
}
|
||
else if (base_domain == "" or base_domain.empty()) base_domain = "home";
|
||
id(disp1).send_command_printf("page %s", base_domain.c_str());
|
||
}
|
||
else if (domain == "light") id(ha_call_service)->execute("light.turn_on", key.c_str(), value.c_str(), entity.c_str());
|
||
else if (domain == "cover")
|
||
{
|
||
if (key == "position") id(ha_call_service)->execute("cover.set_cover_position", key.c_str(), value.c_str(), entity.c_str());
|
||
else id(ha_call_service)->execute((std::string("cover.") + key.c_str()), "", "", entity.c_str());
|
||
}
|
||
else if (domain == "fan")
|
||
{
|
||
if (key == "stop" or value == "0") id(ha_call_service)->execute("fan.turn_off", "", "", entity.c_str());
|
||
else id(ha_call_service)->execute("fan.turn_on", key.c_str(), value.c_str(), entity.c_str());
|
||
}
|
||
|
||
##### touchevent sensor, Reset the page timeout #####
|
||
- id: disp1_touchevent
|
||
platform: nextion
|
||
nextion_id: disp1
|
||
#name: ${device_name} touchevent
|
||
component_name: touchevent
|
||
internal: true
|
||
filters:
|
||
- lambda: |-
|
||
x = x.c_str();
|
||
x.shrink_to_fit();
|
||
return x;
|
||
on_value:
|
||
then:
|
||
- lambda: |-
|
||
id(page_timer)->execute(int(id(page_timeout).state));
|
||
|
||
##### START - SWITCH CONFIGURATION #####
|
||
switch:
|
||
|
||
##### Notification unread #####
|
||
- name: ${device_name} Notification unread
|
||
platform: template
|
||
id: notification_unread
|
||
entity_category: config
|
||
optimistic: true
|
||
restore_mode: ALWAYS_OFF
|
||
on_turn_on:
|
||
- lambda: id(set_component_color).execute("home.bt_notific", id(home_notify_icon_color_unread), {});
|
||
on_turn_off:
|
||
- lambda: id(set_component_color).execute("home.bt_notific", id(home_notify_icon_color_normal), {});
|
||
|
||
##### Notification sound #####
|
||
- name: ${device_name} Notification sound
|
||
platform: template
|
||
id: notification_sound
|
||
entity_category: config
|
||
optimistic: true
|
||
restore_mode: RESTORE_DEFAULT_OFF
|
||
|
||
##### Confirmation Message #####
|
||
- name: ${device_name} Confirmation Message
|
||
platform: template
|
||
id: confirmation_message
|
||
entity_category: config
|
||
restore_mode: RESTORE_DEFAULT_OFF
|
||
optimistic: true
|
||
|
||
##### PHYSICAL SWITCH 1 #####
|
||
- name: ${device_name} Relay 1
|
||
platform: gpio
|
||
id: relay_1
|
||
pin:
|
||
number: 22
|
||
restore_mode: RESTORE_DEFAULT_OFF
|
||
on_turn_on:
|
||
then:
|
||
- script.execute:
|
||
id: refresh_relays
|
||
on_turn_off:
|
||
then:
|
||
- script.execute:
|
||
id: refresh_relays
|
||
##### PHYSICAL SWITCH 2 ######
|
||
- name: ${device_name} Relay 2
|
||
platform: gpio
|
||
id: relay_2
|
||
pin:
|
||
number: 19
|
||
restore_mode: RESTORE_DEFAULT_OFF
|
||
on_turn_on:
|
||
then:
|
||
- script.execute:
|
||
id: refresh_relays
|
||
on_turn_off:
|
||
then:
|
||
- script.execute:
|
||
id: refresh_relays
|
||
|
||
##### DISPLAY ALWAYS ON #####
|
||
- name: ${device_name} Screen Power
|
||
platform: gpio
|
||
id: screen_power
|
||
entity_category: config
|
||
pin:
|
||
number: 4
|
||
inverted: true
|
||
restore_mode: ALWAYS_ON
|
||
internal: true
|
||
|
||
##### Switch Display Sleep mode #####
|
||
- name: ${device_name} Sleep mode
|
||
platform: template
|
||
device_class: switch
|
||
id: sleep_mode
|
||
entity_category: config
|
||
restore_mode: RESTORE_DEFAULT_OFF
|
||
optimistic: false
|
||
turn_on_action: &sleep_mode-turn_on
|
||
- lambda: |-
|
||
ESP_LOGV("switch.sleep_mode", "Turn on");
|
||
id(disp1).send_command_printf("sleep_mode=1");
|
||
id(disp1).set_component_value("settings.bt_sleep",1);
|
||
id(disp1).set_component_text_printf("settings.bt_sleep", "%s", "\uEA19");
|
||
id(sleep_mode).publish_state(true);
|
||
turn_off_action: &sleep_mode-turn_off
|
||
- lambda: |-
|
||
ESP_LOGV("switch.sleep_mode", "Turn off");
|
||
id(disp1).send_command_printf("sleep_mode=0");
|
||
id(disp1).set_component_value("settings.bt_sleep",0);
|
||
id(disp1).set_component_text_printf("settings.bt_sleep", "%s", "\uEA18");
|
||
id(sleep_mode).publish_state(false);
|
||
|
||
##### Relay Local control #####
|
||
- name: ${device_name} Relay 1 Local
|
||
platform: template
|
||
id: relay1_local
|
||
entity_category: config
|
||
optimistic: true
|
||
restore_mode: RESTORE_DEFAULT_OFF
|
||
internal: true
|
||
on_turn_on:
|
||
- logger.log: "Relay 1 Local turned On!"
|
||
on_turn_off:
|
||
- logger.log: "Relay 1 Local turned Off!"
|
||
- name: ${device_name} Relay 2 Local
|
||
platform: template
|
||
id: relay2_local
|
||
entity_category: config
|
||
optimistic: true
|
||
restore_mode: RESTORE_DEFAULT_OFF
|
||
internal: true
|
||
on_turn_on:
|
||
- logger.log: "Relay 2 Local turned On!"
|
||
on_turn_off:
|
||
- logger.log: "Relay 2 Local turned Off!"
|
||
|
||
##### START - NUMBER CONFIGURATION #####
|
||
number:
|
||
|
||
##### SCREEN BRIGHTNESS #####
|
||
- platform: template
|
||
name: ${device_name} Display Brightness
|
||
id: display_brightness
|
||
entity_category: config
|
||
unit_of_measurement: '%'
|
||
min_value: 1
|
||
max_value: 100
|
||
step: 1
|
||
restore_value: true
|
||
optimistic: true
|
||
set_action:
|
||
then:
|
||
- lambda: |-
|
||
id(display_brightness_global) = int(x);
|
||
id(disp1).send_command_printf("brightness=%i", int(x));
|
||
id(disp1).send_command_printf("settings.brightslider.val=%i", int(x));
|
||
if (id(current_page).state != "screensaver")
|
||
{
|
||
id(disp1).set_backlight_brightness(x/100);
|
||
id(disp1).send_command_printf("home.dimtimer.en=1");
|
||
}
|
||
if (id(current_page).state == "settings")
|
||
{
|
||
id(disp1).set_component_text_printf("bright_text", "%i%%", int(x));
|
||
}
|
||
|
||
##### SCREEN BRIGHTNESS DIMMED DOWN #####
|
||
- platform: template
|
||
name: ${device_name} Display Brightness Dimdown
|
||
id: display_dim_brightness
|
||
entity_category: config
|
||
unit_of_measurement: '%'
|
||
min_value: 1
|
||
max_value: 100
|
||
step: 1
|
||
restore_value: true
|
||
optimistic: true
|
||
set_action:
|
||
then:
|
||
- lambda: |-
|
||
id(display_dim_brightness_global) = int(x);
|
||
id(disp1).send_command_printf("brightness_dim=%i", int(x));
|
||
id(disp1).send_command_printf("settings.dimslider.val=%i", int(x));
|
||
if (id(current_page).state == "settings") id(disp1).set_component_text_printf("dim_text", "%i%%", int(x));
|
||
|
||
##### Temperature Correction #####
|
||
- name: ${device_name} Temperature Correction
|
||
platform: template
|
||
id: temperature_correction
|
||
entity_category: config
|
||
unit_of_measurement: '°C'
|
||
initial_value: 0
|
||
min_value: -10
|
||
max_value: 10
|
||
step: 0.1
|
||
restore_value: true
|
||
internal: false
|
||
optimistic: true
|
||
set_action:
|
||
- logger.log: Temperature correction changed.
|
||
- delay: 1s
|
||
- lambda: id(temp_nspanel).publish_state(id(temp_nspanel).raw_state);
|
||
|
||
##### page-timeout #####
|
||
- platform: template
|
||
name: ${device_name} Page Timeout
|
||
id: page_timeout
|
||
entity_category: config
|
||
min_value: 0
|
||
max_value: 60
|
||
initial_value: 10
|
||
step: 1
|
||
restore_value: true
|
||
optimistic: true
|
||
|
||
##### START - DISPLAY START CONFIGURATION #####
|
||
display:
|
||
- id: disp1
|
||
platform: nextion
|
||
uart_id: tf_uart
|
||
tft_url: ${nextion_update_url}
|
||
on_page: # I couldn't make this trigger to work, so used text_sensor nspanelevent and localevent instead
|
||
- lambda: ESP_LOGW("display.disp1", "NEXTION PAGE CHANGED");
|
||
on_setup:
|
||
then:
|
||
- lambda: |-
|
||
id(disp1).send_command_printf("page 8");
|
||
id(disp1).set_component_text_printf("boot.esph_version", "%s", "${version}"); // ### esphome-version ###
|
||
id(disp1).show_component("bt_reboot");
|
||
- wait_until:
|
||
api.connected
|
||
- lambda: |-
|
||
id(disp1).set_component_text_printf("boot.ip_addr", "%s", id(ip_address).state.c_str());
|
||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||
{
|
||
{"type", "boot"},
|
||
{"step", "start"}
|
||
});
|
||
- delay: 1s
|
||
- if:
|
||
condition:
|
||
switch.is_off: sleep_mode
|
||
then: *sleep_mode-turn_off
|
||
else: *sleep_mode-turn_on
|
||
- lambda: |-
|
||
id(display_brightness).publish_state(id(display_brightness_global));
|
||
id(display_dim_brightness).publish_state(id(display_dim_brightness_global));
|
||
id(disp1).send_command_printf("settings.brightslider.val=%i", id(display_brightness_global));
|
||
id(disp1).send_command_printf("settings.dimslider.val=%i", id(display_dim_brightness_global));
|
||
id(nextion_init).publish_state(true);
|
||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||
{
|
||
{"type", "boot"},
|
||
{"step", "nextion_init"}
|
||
});
|
||
id(home_relay1_icon) = "\uE3A5";
|
||
id(home_relay1_icon) = "\uE3A8";
|
||
- *notification_clear
|
||
- switch.turn_off: notification_unread
|
||
- logger.log: "Nextion start - Done!"
|
||
|
||
### Script for page_timer
|
||
script:
|
||
- id: page_timer
|
||
mode: restart
|
||
parameters:
|
||
delay: int
|
||
then:
|
||
- lambda: ESP_LOGV("script.page_timer", "start page-timer delay %i", int(id(page_timeout).state));
|
||
- delay: !lambda return delay *1000;
|
||
- lambda: |-
|
||
if (id(current_page).state == "home" or id(current_page).state == "screensaver" or id(current_page).state == "boot" or int(id(page_timeout).state) == 0)
|
||
ESP_LOGD("script.page_timer", "no page-jump");
|
||
else
|
||
{
|
||
ESP_LOGD("script.page_timer", "timer->home");
|
||
id(disp1).send_command_printf("page 0");
|
||
}
|
||
|
||
- id: set_climate
|
||
mode: restart
|
||
parameters:
|
||
current_temp: float
|
||
target_temp: float
|
||
temp_step: int
|
||
total_steps: int
|
||
temp_offset: int
|
||
climate_icon: string
|
||
embedded_climate: bool
|
||
then:
|
||
- lambda: ESP_LOGV("script.set_climate", "Starting");
|
||
- if:
|
||
condition:
|
||
- text_sensor.state: # Is climate page visible?
|
||
id: current_page
|
||
state: 'climate'
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("script.set_climate", "climateslider.maxval=%i", total_steps);
|
||
ESP_LOGV("script.set_climate", "temp_offset=%i", temp_offset);
|
||
ESP_LOGV("script.set_climate", "temp_step=%i", temp_step);
|
||
ESP_LOGV("script.set_climate", "current_temp=%f", current_temp);
|
||
ESP_LOGV("script.set_climate", "target_temp=%f", target_temp);
|
||
ESP_LOGV("script.set_climate", "target_icon=%s", climate_icon.c_str());
|
||
ESP_LOGV("script.set_climate", "embedded=%i", (embedded_climate) ? 1 : 0);
|
||
id(addon_climate_set_climate).execute(embedded_climate);
|
||
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)
|
||
{
|
||
float slider_val = round(((10*target_temp) - temp_offset) / temp_step);
|
||
ESP_LOGV("script.set_climate", "climateslider=%f", slider_val);
|
||
id(disp1).set_component_value("climateslider", slider_val);
|
||
id(disp1).set_component_text_printf("target_temp", "%.1f°", target_temp);
|
||
id(disp1).set_component_text_printf("target_icon", "%s", climate_icon.c_str());
|
||
id(disp1).show_component("target_icon");
|
||
id(disp1).show_component("target_temp");
|
||
id(disp1).show_component("climateslider");
|
||
id(disp1).show_component("decrease_temp");
|
||
id(disp1).show_component("increase_temp");
|
||
}
|
||
else
|
||
{
|
||
id(disp1).hide_component("target_icon");
|
||
id(disp1).hide_component("target_temp");
|
||
id(disp1).hide_component("climateslider");
|
||
id(disp1).hide_component("decrease_temp");
|
||
id(disp1).hide_component("increase_temp");
|
||
}
|
||
id(disp1).set_component_value("embedded", (embedded_climate) ? 1 : 0);
|
||
- lambda: ESP_LOGV("script.set_climate", "Finished");
|
||
|
||
- id: refresh_datetime
|
||
mode: restart
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("script.refresh_datetime", "Starting");
|
||
std::string time_format_str = id(mui_time_format);
|
||
if (time_format_str.find("%p") != std::string::npos)
|
||
{
|
||
std::string meridiem_text = id(time_provider).now().strftime("%p");
|
||
id(disp1).set_component_text_printf("home.meridiem", "%s", meridiem_text.c_str());
|
||
}
|
||
else { id(disp1).set_component_text_printf("home.meridiem", " "); }
|
||
if (time_format_str.find("%-H") != std::string::npos) { time_format_str = time_format_str.replace(time_format_str.find("%-H"), sizeof("%-H")-1, to_string((int)(id(time_provider).now().hour))); }
|
||
if (time_format_str.find("%-I") != std::string::npos)
|
||
{
|
||
if (id(time_provider).now().hour>12)
|
||
{
|
||
time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, to_string((int)(id(time_provider).now().hour-12)));
|
||
}
|
||
else if (id(time_provider).now().hour==0)
|
||
{
|
||
time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, "12");
|
||
}
|
||
else
|
||
{
|
||
time_format_str = time_format_str.replace(time_format_str.find("%-I"), sizeof("%-I")-1, to_string((int)(id(time_provider).now().hour)));
|
||
}
|
||
}
|
||
std::string time_text = id(time_provider).now().strftime(time_format_str);
|
||
id(disp1).set_component_text_printf("home.time", "%s", time_text.c_str());
|
||
ESP_LOGV("script.refresh_datetime", "Finished");
|
||
|
||
- id: refresh_relays
|
||
mode: restart
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("script.refresh_relays", "Starting");
|
||
// Chips - Relays
|
||
if (id(relay_1).state) id(disp1).set_component_text_printf("home.icon_top_01", "%s", id(home_relay1_icon).c_str());
|
||
else id(disp1).set_component_text_printf("icon_top_01", "\uFFFF");
|
||
if (id(relay_2).state) id(disp1).set_component_text_printf("home.icon_top_02", "%s", id(home_relay2_icon).c_str());
|
||
else id(disp1).set_component_text_printf("home.icon_top_02", "\uFFFF");
|
||
// Hardware buttons - Fallback mode
|
||
if (id(relay_1).state and id(relay1_local).state) id(disp1).send_command_printf("home.left_bt_pic.val=%i", (id(relay_1).state) ? 1 : 0);
|
||
if (id(relay_2).state and id(relay2_local).state) id(disp1).send_command_printf("home.right_bt_pic.val=%i", (id(relay_2).state) ? 1 : 0);
|
||
ESP_LOGV("script.refresh_relays", "Finished");
|
||
|
||
- id: refresh_wifi_icon
|
||
mode: restart
|
||
then:
|
||
- lambda: ESP_LOGV("script.refresh_wifi_icon", "Starting");
|
||
- if:
|
||
condition:
|
||
- binary_sensor.is_on: nextion_init
|
||
then:
|
||
# Update Wi-Fi icon
|
||
- if:
|
||
condition:
|
||
wifi.connected:
|
||
then:
|
||
- if:
|
||
condition:
|
||
api.connected:
|
||
then:
|
||
- lambda: id(disp1).send_command_printf("api=1");
|
||
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\uE5A8");
|
||
- lambda: id(disp1).set_component_font_color("home.wifi_icon", 33808);
|
||
else:
|
||
- lambda: id(disp1).send_command_printf("api=0");
|
||
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\uF256");
|
||
- lambda: id(disp1).set_component_font_color("home.wifi_icon", 63488);
|
||
else:
|
||
- lambda: id(disp1).send_command_printf("api=0");
|
||
- lambda: id(disp1).set_component_text_printf("home.wifi_icon", "%s", "\uE5A9");
|
||
- lambda: id(disp1).set_component_font_color("home.wifi_icon", 63488);
|
||
- lambda: ESP_LOGV("script.refresh_wifi_icon", "Finished");
|
||
|
||
- id: update_page_home
|
||
mode: restart
|
||
then:
|
||
- lambda: ESP_LOGV("script.update_page_home", "Starting");
|
||
- if:
|
||
condition:
|
||
- text_sensor.state: # Is home page visible?
|
||
id: current_page
|
||
state: 'home'
|
||
then:
|
||
- script.execute: refresh_relays
|
||
- script.execute: refresh_wifi_icon
|
||
- lambda: |-
|
||
ESP_LOGV("script.update_page_home", "is_notification=%i", (id(notification_text).state.empty() and id(notification_label).state.empty()) ? 0 : 1);
|
||
id(disp1).send_command_printf("is_notification=%i", (id(notification_text).state.empty() and id(notification_label).state.empty()) ? 0 : 1);
|
||
id(set_component_color).execute("home.bt_notific", id(notification_unread).state ? id(home_notify_icon_color_unread) : id(home_notify_icon_color_normal), {});
|
||
- script.execute: refresh_datetime
|
||
- script.execute: addon_climate_update_page_home
|
||
|
||
- lambda: ESP_LOGV("script.update_page_home", "Finished");
|
||
|
||
- id: service_call_alarm_control_panel
|
||
mode: restart
|
||
parameters:
|
||
entity: string
|
||
key: string
|
||
code_format: string
|
||
pin: string
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("service_call_alarm_control_panel", "ESPHome remote service call");
|
||
ESP_LOGV("service_call_alarm_control_panel", "entity=%s", entity.c_str());
|
||
ESP_LOGV("service_call_alarm_control_panel", "key=%s", key.c_str());
|
||
ESP_LOGV("service_call_alarm_control_panel", "code_format=%s", code_format.c_str());
|
||
ESP_LOGV("service_call_alarm_control_panel", "pin=%s", entity.c_str());
|
||
std::string service = "";
|
||
if (key=="home") service = "alarm_control_panel.alarm_arm_home";
|
||
else if (key=="away") service = "alarm_control_panel.alarm_arm_away";
|
||
else if (key=="night") service = "alarm_control_panel.alarm_arm_night";
|
||
else if (key=="vacation") service = "alarm_control_panel.alarm_arm_vacation";
|
||
else if (key=="bypass") service = "alarm_control_panel.alarm_arm_custom_bypass";
|
||
else if (key=="disarm") service = "alarm_control_panel.alarm_disarm";
|
||
ESP_LOGV("service_call_alarm_control_panel", "service=%s", service.c_str());
|
||
if (service != "" and not service.empty())
|
||
{
|
||
ESP_LOGV("service_call_alarm_control_panel", "ESPHome remote service call");
|
||
HomeassistantServiceResponse resp;
|
||
HomeassistantServiceMap resp_kv;
|
||
resp.service = service.c_str();
|
||
resp_kv.key = "entity_id";
|
||
resp_kv.value = entity.c_str();
|
||
resp.data.push_back(resp_kv);
|
||
if (pin != "" and not pin.empty())
|
||
{
|
||
resp_kv.key = "code";
|
||
resp_kv.value = pin.c_str();
|
||
resp.data.push_back(resp_kv);
|
||
}
|
||
id(api_server).send_homeassistant_service_call(resp);
|
||
}
|
||
|
||
- id: service_call_climate
|
||
mode: restart
|
||
parameters:
|
||
entity: string
|
||
key: string
|
||
value: string
|
||
embedded: bool
|
||
then:
|
||
- lambda: |-
|
||
if (embedded)
|
||
id(addon_climate_service_call)->execute(key.c_str(), value.c_str());
|
||
else if (key == "set_temperature")
|
||
id(ha_call_service)->execute("climate.set_temperature", "temperature", to_string(stof(value) / 10), entity.c_str());
|
||
else if (key == "hvac_mode")
|
||
id(ha_call_service)->execute("climate.set_hvac_mode", key.c_str(), value.c_str(), entity.c_str());
|
||
|
||
- id: ha_call_service
|
||
mode: restart
|
||
parameters:
|
||
service: string
|
||
key: string
|
||
value: string
|
||
entity: string
|
||
then:
|
||
- lambda: |-
|
||
if (service != "" and not service.empty())
|
||
{
|
||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||
{
|
||
{"type", "service_call"},
|
||
{"service", service},
|
||
{"entity", entity},
|
||
{"key", key},
|
||
{"value", value}
|
||
});
|
||
}
|
||
|
||
- id: ha_button
|
||
mode: parallel
|
||
parameters:
|
||
page: string
|
||
component: string
|
||
command: string
|
||
then:
|
||
- lambda: |-
|
||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||
{
|
||
{"type", "button_click"},
|
||
{"page", page},
|
||
{"component", component},
|
||
{"command", command}
|
||
});
|
||
|
||
- id: update_alarm_icon
|
||
mode: restart
|
||
parameters:
|
||
component: string
|
||
state: string
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("script.update_alarm_icon", "Starting");
|
||
std::string alarm_icon = "\uEECC"; //mdi:shield-alert-outline
|
||
int alarm_color = 65535;
|
||
// Standard colors:
|
||
// blue: '1055' # rgb(0, 128, 248)
|
||
// grey_dark: '10597' # rgb(40, 44, 40)
|
||
// grey_light: '33808' # rgb(128, 128, 128)
|
||
// grey_super_light: '52857' # rgb(200, 204, 200)
|
||
// grey_white: '59164' # rgb(225, 225, 225)
|
||
// red: '63488' # rgb(248, 0, 0)
|
||
// white: '65535' # rgb(255, 255, 255)
|
||
// yellow: '65472' # rgb(248, 248, 0)
|
||
// #### Colors from HA Style:
|
||
// green: '19818' # rgb(76, 175, 80)
|
||
// orange: '64704' # rgb(255, 152, 0)
|
||
// cyan: '1530' # rgb(0, 188, 212)
|
||
// deep-orange: '64164' # rgb(255, 87, 34)
|
||
// amber: '65024' # rgb(255, 193, 7)
|
||
// "off": '35921' #8a8a8a
|
||
// disabled: '48631' # rgb(189, 189, 189)
|
||
if (state == "disarmed")
|
||
{
|
||
alarm_icon = "\uE99B"; //mdi:shield-off-outline
|
||
alarm_color = 65535;
|
||
}
|
||
else if (state == "armed_home")
|
||
{
|
||
alarm_icon = "\uECCA"; //mdi:shield-home-outline
|
||
alarm_color = 19818;
|
||
}
|
||
else if (state == "armed_away")
|
||
{
|
||
alarm_icon = "\uECCB"; //mdi:shield-lock-outline
|
||
alarm_color = 19818;
|
||
}
|
||
else if (state == "armed_night")
|
||
{
|
||
alarm_icon = "\uF828"; //mdi:shield-moon-outline
|
||
alarm_color = 19818;
|
||
}
|
||
else if (state == "armed_vacation")
|
||
{
|
||
alarm_icon = "\uECC6"; //mdi:shield-airplane-outline
|
||
alarm_color = 19818;
|
||
}
|
||
else if (state == "armed_custom_bypass")
|
||
{
|
||
alarm_icon = "\uE77F"; //mdi:shield-half-full
|
||
alarm_color = 19818;
|
||
}
|
||
else if (state == "pending" or state == "arming")
|
||
{
|
||
alarm_icon = "\uE498"; //mdi:shield-outline
|
||
alarm_color = 65024;
|
||
}
|
||
else if (state == "disarming")
|
||
{
|
||
alarm_icon = "\uE99B"; //mdi:shield-off-outline
|
||
alarm_color = 65024;
|
||
}
|
||
else if (state == "triggered")
|
||
{
|
||
alarm_icon = "\uEECC"; //mdi:shield-alert-outline
|
||
alarm_color = 63488;
|
||
}
|
||
id(disp1).set_component_text_printf(component.c_str(), alarm_icon.c_str());
|
||
id(disp1).set_component_font_color(component.c_str(), alarm_color);
|
||
ESP_LOGV("script.update_alarm_icon", "Finished");
|
||
|
||
- id: update_climate_icon
|
||
mode: restart
|
||
parameters:
|
||
component: string
|
||
action: int
|
||
mode: int
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("script.update_climate_icon", "Starting");
|
||
ESP_LOGV("script.update_climate_icon", "component: %s", component.c_str());
|
||
ESP_LOGV("script.update_climate_icon", "action: %i", action);
|
||
ESP_LOGV("script.update_climate_icon", "mode: %i", mode);
|
||
switch (action) // CLIMATE_ACTION_OFF = 0, CLIMATE_ACTION_COOLING = 2, CLIMATE_ACTION_HEATING = 3, CLIMATE_ACTION_IDLE = 4, CLIMATE_ACTION_DRYING = 5, CLIMATE_ACTION_FAN = 6
|
||
{
|
||
case 0: //CLIMATE_ACTION_OFF
|
||
ESP_LOGV("script.update_climate_icon", "Climate 'action' is off. Using 'mode' instead");
|
||
switch (mode) // CLIMATE_MODE_OFF = 0, CLIMATE_MODE_HEAT_COOL = 1, CLIMATE_MODE_COOL = 2, CLIMATE_MODE_HEAT = 3, CLIMATE_MODE_FAN_ONLY = 4, CLIMATE_MODE_DRY = 5, CLIMATE_MODE_AUTO = 6
|
||
{
|
||
case 0: //CLIMATE_MODE_OFF
|
||
ESP_LOGV("script.update_climate_icon", "Icon: none");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uFFFF"); // (E424) Don't show icon when off
|
||
id(disp1).set_component_font_color(component.c_str(), 35921); // grey (off)
|
||
break;
|
||
case 1: //CLIMATE_MODE_HEAT_COOL
|
||
ESP_LOGV("script.update_climate_icon", "Icon: autorenew");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uE069"); // mdi:autorenew
|
||
id(disp1).set_component_font_color(component.c_str(), 35921); // grey (off)
|
||
break;
|
||
case 2: //CLIMATE_MODE_COOL
|
||
ESP_LOGV("script.update_climate_icon", "Icon: snowflake");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uE716"); // mdi:snowflake
|
||
id(disp1).set_component_font_color(component.c_str(), 35921); // grey (off)
|
||
break;
|
||
case 3: //CLIMATE_MODE_HEAT
|
||
ESP_LOGV("script.update_climate_icon", "Icon: fire");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uE237"); // mdi:fire
|
||
id(disp1).set_component_font_color(component.c_str(), 35921); // grey (off)
|
||
break;
|
||
case 4: //CLIMATE_MODE_FAN_ONLY
|
||
ESP_LOGV("script.update_climate_icon", "Icon: fan");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uE20F"); // mdi:fan
|
||
id(disp1).set_component_font_color(component.c_str(), 35921); // grey (off)
|
||
break;
|
||
case 5: //CLIMATE_MODE_DRY
|
||
ESP_LOGV("script.update_climate_icon", "Icon: water-percent");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uE58D"); // mdi:water-percent
|
||
id(disp1).set_component_font_color(component.c_str(), 35921); // grey (off)
|
||
break;
|
||
case 6: //CLIMATE_MODE_AUTO
|
||
ESP_LOGV("script.update_climate_icon", "Icon: calendar-sync");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uEE8D"); // mdi:calendar-sync
|
||
id(disp1).set_component_font_color(component.c_str(), 35921); // grey (off)
|
||
break;
|
||
}
|
||
break;
|
||
case 2: //CLIMATE_ACTION_COOLING
|
||
ESP_LOGV("script.update_climate_icon", "Icon: snowflake");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uE716"); // mdi:snowflake
|
||
id(disp1).set_component_font_color(component.c_str(), 1055); // blue
|
||
break;
|
||
case 3: //CLIMATE_ACTION_HEATING
|
||
ESP_LOGV("script.update_climate_icon", "Icon: fire");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uE237"); // mdi:fire
|
||
id(disp1).set_component_font_color(component.c_str(), 64164); // deep-orange
|
||
break;
|
||
case 4: //CLIMATE_ACTION_IDLE
|
||
ESP_LOGV("script.update_climate_icon", "Icon: thermometer");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uE50E"); // mdi:thermometer
|
||
id(disp1).set_component_font_color(component.c_str(), 35921); // grey (off)
|
||
break;
|
||
case 5: //CLIMATE_ACTION_DRYING
|
||
ESP_LOGV("script.update_climate_icon", "Icon: water-percent");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uE58D"); // mdi:water-percent
|
||
id(disp1).set_component_font_color(component.c_str(), 64704); // orange
|
||
break;
|
||
case 6: //CLIMATE_ACTION_FAN
|
||
ESP_LOGV("script.update_climate_icon", "Icon: fan");
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", "\uE20F"); // mdi:fan
|
||
id(disp1).set_component_font_color(component.c_str(), 1530); // cyan
|
||
break;
|
||
}
|
||
ESP_LOGV("script.update_climate_icon", "Finished");
|
||
|
||
- id: set_component_color
|
||
mode: queued
|
||
parameters:
|
||
component: string
|
||
foreground: int[]
|
||
background: int[]
|
||
then:
|
||
- lambda: |-
|
||
ESP_LOGV("script.set_component_color", "Starting");
|
||
ESP_LOGV("script.set_component_color", "Component: %s", component.c_str());
|
||
int fg565 = -1;
|
||
int bg565 = -1;
|
||
|
||
// Foreground
|
||
if (foreground.size() == 3) fg565 = ((foreground[0] & 0b11111000) << 8) | ((foreground[1] & 0b11111100) << 3) | (foreground[2] >> 3);
|
||
else if (foreground.size() == 1) fg565 = foreground[0];
|
||
if (fg565 >= 0) id(disp1).set_component_font_color(component.c_str(), fg565);
|
||
|
||
// Background
|
||
if (background.size() == 3) bg565 = ((background[0] & 0b11111000) << 8) | ((background[1] & 0b11111100) << 3) | (background[2] >> 3);
|
||
else if (background.size() == 1) bg565 = background[0];
|
||
if (bg565 >= 0) id(disp1).set_component_background_color(component.c_str(), bg565);
|
||
|
||
ESP_LOGV("script.set_component_color", "Finished");
|
||
|
||
- id: display_wrapped_text
|
||
mode: queued
|
||
parameters:
|
||
component: string
|
||
text: string
|
||
line_length_limit: int
|
||
then:
|
||
- lambda: |-
|
||
int startPos = 0;
|
||
int endPos = 0;
|
||
std::string wrappedText = "";
|
||
while (startPos < text.length()) {
|
||
while (text[startPos] == ' ' and startPos < text.length()) { startPos++; }
|
||
int endPos = startPos + line_length_limit;
|
||
if (endPos >= text.length()) endPos = text.length();
|
||
else
|
||
{
|
||
while (endPos > startPos && text[endPos] != ' ') { endPos--; }
|
||
if (endPos == startPos) endPos = startPos + line_length_limit; // Handle case of long word
|
||
}
|
||
wrappedText += text.substr(startPos, endPos-startPos);
|
||
if (endPos < text.length())
|
||
{
|
||
while (text[endPos] == ' ') { endPos--; }
|
||
if (endPos >= startPos) wrappedText += "\\r";
|
||
}
|
||
startPos = endPos + 1; // Skip the space
|
||
while (text[startPos] == ' ' and startPos < text.length()) { startPos++; }
|
||
}
|
||
ESP_LOGV("script.display_wrapped_text", "text (new): %s", wrappedText.c_str());
|
||
id(disp1).set_component_text_printf(component.c_str(), "%s", wrappedText.c_str());
|
||
|
||
- id: display_embedded_temp
|
||
mode: restart
|
||
then:
|
||
- if:
|
||
condition:
|
||
- or:
|
||
- lambda: return id(embedded_indoor_temp);
|
||
- not:
|
||
- api.connected:
|
||
- not:
|
||
- wifi.connected:
|
||
then:
|
||
- lambda: |-
|
||
if (id(temp_unit_fahrenheit)) id(disp1).set_component_text_printf("home.current_temp", "%.0f°F", ((id(temp_nspanel).state * 9.0 / 5.0) + 32.0)); // °F = (°C × 9/5) + 32
|
||
else id(disp1).set_component_text_printf("home.current_temp", "%.1f°C", id(temp_nspanel).state);
|
||
|
||
- id: check_versions
|
||
mode: restart
|
||
then:
|
||
- delay: 30s
|
||
- lambda: |-
|
||
ESP_LOGD("script.check_versions", "ESPHome version: ${version}");
|
||
ESP_LOGD("script.check_versions", "TFT version: %s", id(version_tft).c_str());
|
||
if (id(version_tft) != "${version}") ESP_LOGE("script.check_versions", "TFT version mismatch!");
|
||
ESP_LOGD("script.check_versions", "Blueprint version: %s", id(version_blueprint).c_str());
|
||
if (id(version_blueprint) != "${version}") ESP_LOGE("script.check_versions", "Blueprint version mismatch!");
|
||
auto ha_event = new esphome::api::CustomAPIDevice();
|
||
ha_event->fire_homeassistant_event("esphome.nspanel_ha_blueprint",
|
||
{
|
||
{"type", "version"},
|
||
{"tft", id(version_tft).c_str()},
|
||
{"esphome", "${version}"},
|
||
{"blueprint", id(version_blueprint).c_str()}
|
||
});
|
||
|
||
##### ADD-ONS ############################################################
|
||
##### Add-on - Climate #####
|
||
- id: addon_climate_service_call
|
||
mode: restart
|
||
parameters:
|
||
key: string
|
||
value: string
|
||
then:
|
||
# Reserved for Add-on Climate
|
||
- lambda: |-
|
||
ESP_LOGV("script.addon_climate_service_call", "Check for addon_climate");
|
||
- id: addon_climate_update_page_home
|
||
mode: restart
|
||
then:
|
||
# Reserved for Add-on Climate
|
||
- lambda: |-
|
||
ESP_LOGV("script.addon_climate_update_page_home", "Check for addon_climate");
|
||
- id: addon_climate_set_climate
|
||
mode: restart
|
||
parameters:
|
||
embedded_climate: bool
|
||
then:
|
||
# Reserved for Add-on Climate
|
||
- lambda: |-
|
||
ESP_LOGV("script.addon_climate_set_climate", "Check for addon_climate");
|
||
ESP_LOGV("script.addon_climate_set_climate", "embedded_climate: %i", (embedded_climate) ? 1 : 0);
|
||
- id: addon_climate_global_settings
|
||
mode: restart
|
||
parameters:
|
||
embedded_climate: bool
|
||
then:
|
||
# Reserved for Add-on Climate
|
||
- lambda: |-
|
||
ESP_LOGV("script.addon_climate_global_settings", "Check for addon_climate");
|
||
ESP_LOGV("script.addon_climate_global_settings", "embedded_climate: %i", (embedded_climate) ? 1 : 0);
|
||
- id: addon_climate_update_page_climate
|
||
mode: restart
|
||
then:
|
||
# Reserved for Add-on Climate
|
||
- lambda: |-
|
||
ESP_LOGV("script.addon_climate_update_page_climate", "Check for addon_climate");
|
||
- id: addon_climate_set_climate_friendly_name
|
||
mode: restart
|
||
parameters:
|
||
friendly_name: string
|
||
then:
|
||
# Reserved for Add-on Climate
|
||
- lambda: |-
|
||
ESP_LOGV("script.addon_climate_set_climate_friendly_name", "Check for addon_climate");
|
||
ESP_LOGV("script.addon_climate_set_climate_friendly_name", "friendly_name: %s", friendly_name.c_str());
|