Created
November 8, 2022 07:21
-
-
Save ccorderor/bfb77629dd57cc92ba373fa2a929605d to your computer and use it in GitHub Desktop.
Un Loco y su Tecnologia
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
esphome: | |
name: nspanel-1 | |
comment: nspanel-1 | |
esp32: | |
board: esp32dev | |
wifi: | |
ssid: !secret wifi_ap | |
password: !secret wifi_password | |
logger: | |
ota: | |
mqtt: | |
broker: 192.168.1.15 | |
discovery: false | |
on_json_message: | |
topic: alarmo/event | |
then: | |
- if: | |
condition: | |
- lambda: return x["event"] == "INVALID_CODE_PROVIDED"; | |
then: | |
- rtttl.play: "twobits:d=4,o=5,b=300:11e6" | |
# Note: this may not be needed if the pull request has been merged. | |
# Check https://github.com/esphome/esphome/pull/2956 for current status. | |
external_components: | |
- source: github://pr#2956 | |
components: [nextion] | |
refresh: 1h | |
# Home Assistant API | |
api: | |
services: | |
# Musica en el buzzer | |
- service: play_rtttl | |
variables: | |
song_str: string | |
then: | |
- rtttl.play: | |
rtttl: !lambda 'return song_str;' | |
- service: upload_tft | |
then: | |
- lambda: 'id(disp1)->upload_tft();' | |
# Service to show a notification on the screen for 15 s. Tap or wait to close | |
- service: notification | |
variables: | |
header: string | |
message: string | |
then: | |
- lambda: |- | |
id(disp1).set_component_text_printf("Notifications.head", "%s", header.c_str()); | |
id(disp1).set_component_text_printf("Notifications.body", "%s", message.c_str()); | |
id(disp1).send_command_printf("page Notifications"); | |
- rtttl.play: "twobits:d=4,o=5,b=220:c6,8g,8g,a,g,p,b,c6" | |
- delay: 15s | |
- lambda: |- | |
id(disp1).send_command_printf("page Home"); | |
id(disp1).set_component_text_printf("Notifications.head", " "); | |
id(disp1).set_component_text_printf("Notifications.body", " "); | |
id(disp1).send_command_printf("page Home"); | |
button: | |
- platform: restart | |
name: Restart Ns Panel | |
# Time component that fetches time from Home Assistant and updates the display once a minute and when the display is ready at bootup (and time is available). | |
time: | |
- platform: homeassistant | |
id: homeassistant_time | |
on_time: | |
- seconds: 0 | |
minutes: /1 | |
then: | |
- lambda: id(disp1).set_component_text_printf("Home.time", "%02i:%02i", id(homeassistant_time).now().hour, id(homeassistant_time).now().minute); | |
- lambda: id(disp1).set_component_text_printf("Home.date", "%i-%02i-%02i", id(homeassistant_time).now().year, id(homeassistant_time).now().month, id(homeassistant_time).now().day_of_month); | |
on_time_sync: | |
then: | |
- wait_until: | |
switch.is_on: nextion_init | |
- lambda: id(disp1).set_component_text_printf("Home.time", "%02i:%02i", id(homeassistant_time).now().hour, id(homeassistant_time).now().minute); | |
- lambda: id(disp1).set_component_text_printf("Home.date", "%i-%02i-%02i", id(homeassistant_time).now().year, id(homeassistant_time).now().month, id(homeassistant_time).now().day_of_month); | |
sensor: | |
- platform: wifi_signal | |
name: NSPanel WiFi Signal | |
update_interval: 60s | |
- platform: ntc | |
id: temperature | |
sensor: resistance_sensor | |
calibration: | |
b_constant: 3950 | |
reference_temperature: 25°C | |
reference_resistance: 10kOhm | |
name: NSPanel Temperature | |
- platform: resistance | |
id: resistance_sensor | |
sensor: ntc_source | |
configuration: DOWNSTREAM | |
resistor: 11.2kOhm | |
- platform: adc | |
id: ntc_source | |
pin: 38 | |
update_interval: 10s | |
attenuation: 11db | |
# Temperature outside, fetched from HA | |
- platform: homeassistant | |
id: current_temperature | |
entity_id: sensor.netatmo_casa_estacion_meteorologica_exterior_temperature | |
on_value: | |
then: | |
- wait_until: | |
switch.is_on: nextion_init | |
- lambda: id(disp1).set_component_text_printf("Home.temp", "%.1f", id(current_temperature).state); | |
# Temperature outside feels like, fetched from HA | |
- platform: homeassistant | |
id: temp_feelslike | |
entity_id: sensor.netatmo_casa_estacion_meteorologica_exterior_humidity | |
on_value: | |
then: | |
- wait_until: | |
switch.is_on: nextion_init | |
- lambda: id(disp1).set_component_text_printf("Home.tempfl", "%.0f", id(temp_feelslike).state); | |
switch: | |
# Relés internos del dispositivo | |
- platform: gpio | |
name: NSPanel Relay 1 | |
id: relay_1 | |
pin: | |
number: 22 | |
- platform: gpio | |
name: NSPanel Relay 2 | |
id: relay_2 | |
pin: | |
number: 19 | |
# Fin Relés internos del dispositivo | |
# Pin 4 always needs to be on to power up the display | |
- platform: gpio | |
id: screen_power | |
entity_category: config | |
pin: | |
number: 4 | |
inverted: true | |
restore_mode: ALWAYS_ON | |
# Basically a global variable to keep track on whether the Nextion display is ready or not. Delays initial info from HA to the display. | |
- platform: template | |
name: NSPanel Nextion inited | |
id: nextion_init | |
entity_category: config | |
restore_state: false | |
assumed_state: off | |
optimistic: true | |
number: | |
platform: template | |
name: NSPanel Brightness | |
id: brightness | |
entity_category: config | |
unit_of_measurement: '%' | |
min_value: 0 | |
max_value: 100 | |
step: 1 | |
initial_value: 30 | |
set_action: | |
then: | |
- lambda: 'id(disp1).set_backlight_brightness(x/100);' | |
text_sensor: | |
- platform: homeassistant | |
name: "alarm_panel" | |
id: "alarm_panel" | |
entity_id: alarm_control_panel.stargate | |
on_value: | |
- if: | |
condition: | |
- lambda: return id(alarm_panel).state == "arming"; | |
- switch.is_on: nextion_init | |
then: | |
- lambda: id(disp1).set_component_text("Home.t1", "ARMANDO"); | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6,16e6" | |
- if: | |
condition: | |
- lambda: return id(alarm_panel).state == "disarmed"; | |
- switch.is_on: nextion_init | |
then: | |
- lambda: id(disp1).set_component_text("Home.t1", ""); | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6,16e6,16e6" | |
- if: | |
condition: | |
- lambda: return id(alarm_panel).state == "armed_away"; | |
- switch.is_on: nextion_init | |
then: | |
- lambda: id(disp1).set_component_text("Home.t1", "TOTAL"); | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6,16e6,16e6" | |
- if: | |
condition: | |
- lambda: return id(alarm_panel).state == "armed_night"; | |
- switch.is_on: nextion_init | |
then: | |
- lambda: id(disp1).set_component_text("Home.t1", "NOCHE"); | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6,16e6,16e6" | |
- if: | |
condition: | |
- lambda: return id(alarm_panel).state == "armed_house"; | |
- switch.is_on: nextion_init | |
then: | |
- lambda: id(disp1).set_component_text("Home.t1", "HOUSE"); | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6,16e6,16e6" | |
- if: | |
condition: | |
- lambda: return id(alarm_panel).state == "pending"; | |
- switch.is_on: nextion_init | |
then: | |
- lambda: id(disp1).set_component_text("Home.t1", "DESARME"); | |
- number.set: | |
id: brightness | |
value: 60 | |
- lambda: id(disp1).send_command_printf("page Home"); | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6,16e6,16e6,16e6,16e6,16e6,16e6,16e6" | |
- if: | |
condition: | |
- lambda: return id(alarm_panel).state == "triggered"; | |
- switch.is_on: nextion_init | |
then: | |
- lambda: id(disp1).set_component_text("Home.t1", "ALARMA"); | |
- number.set: | |
id: brightness | |
value: 60 | |
- lambda: id(disp1).send_command_printf("page Home"); | |
- rtttl.play: "twobits:d=4,o=5,b=300:11e6,11e6,11e6,16e6,16e6,16e6,16e6,11e6,11e6,11e6,11e6,11e6" | |
- platform: homeassistant | |
id: secto | |
entity_id: light.buhardilla_flexoizquierda | |
on_value: | |
then: | |
- wait_until: | |
switch.is_on: nextion_init | |
- lambda: |- | |
int symbol = 23; | |
if (id(secto).state == "off") { | |
symbol=22; | |
} | |
id(disp1).send_command_printf("Lights.light0.pic=%i", symbol); | |
# Light setup, first light's name | |
- platform: homeassistant | |
id: secto_name | |
entity_id: light.buhardilla_flexoizquierda | |
attribute: friendly_name | |
on_value: | |
then: | |
- wait_until: | |
switch.is_on: nextion_init | |
- lambda: id(disp1).set_component_text_printf("Lights.light0t", "%s", id(secto_name).state.c_str()); | |
- platform: homeassistant | |
id: luz2 | |
entity_id: light.buhardilla_flexoderecha | |
on_value: | |
then: | |
- wait_until: | |
switch.is_on: nextion_init | |
- lambda: |- | |
int symbol = 27; | |
if (id(luz2).state == "off") { | |
symbol=26; | |
} | |
id(disp1).send_command_printf("Lights.light1.pic=%i", symbol); | |
# Light setup, first light's name | |
- platform: homeassistant | |
id: luz2_name | |
entity_id: light.buhardilla_flexoderecha | |
attribute: friendly_name | |
on_value: | |
then: | |
- wait_until: | |
switch.is_on: nextion_init | |
- lambda: id(disp1).set_component_text_printf("Lights.light1t", "%s", id(luz2_name).state.c_str()); | |
- platform: nextion | |
nextion_id: disp1 | |
name: va0 | |
id: va0 | |
update_interval: 1s | |
component_name: va0 | |
on_value: | |
then: | |
- if: | |
condition: | |
- lambda: return id(va0).state.length() == 4; | |
then: | |
- homeassistant.service: | |
service: alarm_control_panel.alarm_disarm | |
data: | |
entity_id: alarm_control_panel.stargate | |
code: !lambda 'return id(va0).state;' | |
- lambda: id(disp1).send_command_printf("page Home"); | |
# Configure the internal bleeper | |
output: | |
- platform: ledc | |
id: buzzer_out | |
pin: | |
number: 21 | |
# Enable ringtone music support | |
rtttl: | |
id: buzzer | |
output: buzzer_out | |
binary_sensor: | |
- platform: homeassistant | |
name: "Recordatorio Salida" | |
id: "recordatorio_salida" | |
entity_id: input_boolean.recordatorio_salida | |
on_press: | |
- lambda: id(disp1).set_component_text("Home.text1", "NO SALIR"); | |
on_release: | |
- lambda: id(disp1).set_component_text("Home.text1", ""); | |
# Botones físicos del dispositivo | |
- platform: gpio | |
name: NSPanel Left Button | |
pin: | |
number: 14 | |
inverted: true | |
on_click: | |
- switch.toggle: relay_1 | |
- platform: gpio | |
name: NSPanel Right Button | |
pin: | |
number: 27 | |
inverted: true | |
# on_click: | |
# - switch.toggle: relay_2 | |
# Fin Botones físicos del dispositivo | |
# Botones alarma Home | |
- platform: nextion | |
name: NSPanel arm away button | |
page_id: 0 | |
component_id: 17 | |
on_click: | |
- homeassistant.service: | |
service: alarm_control_panel.alarm_arm_away | |
data: | |
entity_id: alarm_control_panel.stargate | |
# Fin Botones alarma Home | |
# Buttons on the Lights page | |
- platform: nextion | |
name: NSPanel Light 0 button | |
page_id: 2 | |
component_id: 17 | |
on_click: | |
- homeassistant.service: | |
service: light.toggle | |
data: | |
entity_id: light.buhardilla_flexoizquierda | |
- platform: nextion | |
name: number_1 | |
page_id: 9 | |
component_id: 4 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
- platform: nextion | |
name: number_2 | |
page_id: 9 | |
component_id: 5 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
- platform: nextion | |
name: number_3 | |
page_id: 9 | |
component_id: 6 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
- platform: nextion | |
name: number_4 | |
page_id: 9 | |
component_id: 7 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
- platform: nextion | |
name: number_5 | |
page_id: 9 | |
component_id: 8 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
- platform: nextion | |
name: number_6 | |
page_id: 9 | |
component_id: 9 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
- platform: nextion | |
name: number_7 | |
page_id: 9 | |
component_id: 10 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
- platform: nextion | |
name: number_8 | |
page_id: 9 | |
component_id: 11 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
- platform: nextion | |
name: number_9 | |
page_id: 9 | |
component_id: 12 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
- platform: nextion | |
name: number_borrar | |
page_id: 9 | |
component_id: 13 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
- platform: nextion | |
name: number_0 | |
page_id: 9 | |
component_id: 14 | |
internal: true | |
on_click: | |
- rtttl.play: "twobits:d=4,o=5,b=100:16e6" | |
# Configure UART for communicating with the screen | |
uart: | |
id: tf_uart | |
tx_pin: 16 | |
rx_pin: 17 | |
baud_rate: 115200 | |
# Configure the screen itself | |
display: | |
- platform: nextion | |
id: disp1 | |
uart_id: tf_uart | |
tft_url: http://192.168.1.181:8123/local/carlos.tft | |
# A little fun... | |
on_setup: | |
then: | |
- number.set: | |
id: brightness | |
value: 60 | |
# Enable 1 light page (up to 4 available) | |
- lambda: id(disp1).send_command_printf("Lights.pages.val=1"); | |
- number.set: | |
id: brightness | |
value: 30 | |
- lambda: id(disp1).send_command_printf("page Connecting"); | |
- wait_until: | |
api.connected | |
- switch.template.publish: | |
id: nextion_init | |
state: on | |
- delay: 5s | |
- lambda: id(disp1).send_command_printf("page Home"); | |
- lambda: | | |
if(id(recordatorio_salida).state) { | |
id(disp1).set_component_text("Home.text1", "NO SALIR"); | |
} | |
else { | |
id(disp1).set_component_text("Home.text1", ""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment