changes to esphome devices and packages to start removing node red dependencies
This commit is contained in:
@@ -55,6 +55,8 @@ substitutions:
|
||||
api_key: !secret esp-api_key
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-officelights_ip
|
||||
mqtt_command_main_topic: !secret mqtt_command_main_topic
|
||||
mqtt_status_main_topic: !secret mqtt_status_main_topic
|
||||
|
||||
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
|
||||
# Don't forget to switch it back when changed.
|
||||
@@ -64,6 +66,16 @@ substitutions:
|
||||
log_level: "INFO"
|
||||
update_interval: "60s"
|
||||
|
||||
# MQTT LOCAL Controls
|
||||
# Topic that remote things will use to command this locally without HA
|
||||
mqtt_local_device1_name: "office-main-lights-left"
|
||||
mqtt_local_command1_topic: "${mqtt_command_main_topic}/${mqtt_local_device1_name}"
|
||||
mqtt_local_status1_topic: "${mqtt_status_main_topic}/${mqtt_local_device1_name}"
|
||||
|
||||
mqtt_local_device2_name: "office-main-lights-right"
|
||||
mqtt_local_command2_topic: "${mqtt_command_main_topic}/${mqtt_local_device2_name}"
|
||||
mqtt_local_status2_topic: "${mqtt_status_main_topic}/${mqtt_local_device2_name}"
|
||||
|
||||
# Switch Naming
|
||||
switch_1_name: "Nighttime Lights" # Only one light (Bunker Light) actually connected to this relay
|
||||
switch_2_name: "Daytime Lights" # Virtual only, no power connected to 2nd relay
|
||||
@@ -99,7 +111,7 @@ packages:
|
||||
#### DIAGNOSTICS Sensors ####
|
||||
diag_basic: !include common/include_basic_diag_sensors.yaml
|
||||
diag_more: !include common/include_more_diag_sensors.yaml
|
||||
diag_debug: !include common/include_debug_diag_sensors.yaml
|
||||
#diag_debug: !include common/include_debug_diag_sensors.yaml
|
||||
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
|
||||
|
||||
#:########################################################################################:#
|
||||
@@ -160,7 +172,7 @@ binary_sensor:
|
||||
use_interrupt: false
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
on_press:
|
||||
- switch.toggle: relay_1
|
||||
- switch.toggle: Relay_1
|
||||
|
||||
# Button 2 (GPIO05)
|
||||
- platform: gpio
|
||||
@@ -170,7 +182,7 @@ binary_sensor:
|
||||
inverted: true
|
||||
name: "Button 2: ${switch_2_name}"
|
||||
on_press:
|
||||
- switch.toggle: relay_2
|
||||
- switch.toggle: Relay_2
|
||||
|
||||
# Button 3 (GPIO4)
|
||||
- platform: gpio
|
||||
@@ -180,7 +192,115 @@ binary_sensor:
|
||||
inverted: true
|
||||
name: "Button 3: ${switch_3_name}"
|
||||
on_press:
|
||||
- switch.toggle: relay_3
|
||||
- switch.toggle: Relay_3
|
||||
|
||||
#:########################################################################################:#
|
||||
# MQTT COMPONENT:
|
||||
# Device-specific MQTT command triggers
|
||||
# https://esphome.io/components/mqtt.html
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_message:
|
||||
- topic: "${mqtt_local_command1_topic}"
|
||||
payload: "On"
|
||||
then:
|
||||
- script.stop: relay_1_timer_script
|
||||
- switch.turn_on: Relay_1
|
||||
|
||||
- topic: "${mqtt_local_command1_topic}"
|
||||
payload: "Off"
|
||||
then:
|
||||
- script.stop: relay_1_timer_script
|
||||
- switch.turn_off: Relay_1
|
||||
|
||||
- topic: "${mqtt_local_command1_topic}"
|
||||
then:
|
||||
- lambda: |-
|
||||
if (x.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool numeric_payload = true;
|
||||
for (char c : x) {
|
||||
if (c < '0' || c > '9') {
|
||||
numeric_payload = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!numeric_payload) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int timer_seconds = atoi(x.c_str());
|
||||
if (timer_seconds < 1 || timer_seconds > 3600) {
|
||||
return;
|
||||
}
|
||||
|
||||
id(relay_1_timer_script)->execute(timer_seconds * 1000);
|
||||
|
||||
- topic: "${mqtt_local_command2_topic}"
|
||||
payload: "On"
|
||||
then:
|
||||
- script.stop: relay_2_timer_script
|
||||
- switch.turn_on: Relay_2
|
||||
|
||||
- topic: "${mqtt_local_command2_topic}"
|
||||
payload: "Off"
|
||||
then:
|
||||
- script.stop: relay_2_timer_script
|
||||
- switch.turn_off: Relay_2
|
||||
|
||||
- topic: "${mqtt_local_command2_topic}"
|
||||
then:
|
||||
- lambda: |-
|
||||
if (x.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool numeric_payload = true;
|
||||
for (char c : x) {
|
||||
if (c < '0' || c > '9') {
|
||||
numeric_payload = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!numeric_payload) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int timer_seconds = atoi(x.c_str());
|
||||
if (timer_seconds < 1 || timer_seconds > 3600) {
|
||||
return;
|
||||
}
|
||||
|
||||
id(relay_2_timer_script)->execute(timer_seconds * 1000);
|
||||
|
||||
#:########################################################################################:#
|
||||
# SCRIPT COMPONENT:
|
||||
# Relay 1 timer script
|
||||
# mode: restart means a new valid timer value restarts the timer from zero
|
||||
# https://esphome.io/components/script.html
|
||||
#:########################################################################################:#
|
||||
script:
|
||||
- id: relay_1_timer_script
|
||||
mode: restart
|
||||
parameters:
|
||||
timer_duration_ms: int
|
||||
then:
|
||||
- switch.turn_on: Relay_1
|
||||
- delay: !lambda "return timer_duration_ms;"
|
||||
- switch.turn_off: Relay_1
|
||||
|
||||
- id: relay_2_timer_script
|
||||
mode: restart
|
||||
parameters:
|
||||
timer_duration_ms: int
|
||||
then:
|
||||
- switch.turn_on: Relay_2
|
||||
- delay: !lambda "return timer_duration_ms;"
|
||||
- switch.turn_off: Relay_2
|
||||
|
||||
#:########################################################################################:#
|
||||
# SWITCH
|
||||
@@ -191,16 +311,16 @@ switch:
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
pin: GPIO13
|
||||
id: relay_1
|
||||
id: Relay_1
|
||||
|
||||
# Relay 2 (GPIO12)
|
||||
- platform: gpio
|
||||
name: "Relay 2: ${switch_2_name}"
|
||||
pin: GPIO12
|
||||
id: relay_2
|
||||
id: Relay_2
|
||||
|
||||
# Relay 3 (GPIO14)
|
||||
- platform: gpio
|
||||
name: "Relay 3: ${switch_3_name}"
|
||||
pin: GPIO14
|
||||
id: relay_3
|
||||
id: Relay_3
|
||||
Reference in New Issue
Block a user