From e96336dbc474723197e4ec6bc32753ed84424a57 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 5 Aug 2025 00:21:37 +1200 Subject: [PATCH] esphome pmb 6 button switch update --- esphome/esp-6buttontest-pmb.yaml | 104 ++++++++++++++++++++++++++----- 1 file changed, 88 insertions(+), 16 deletions(-) diff --git a/esphome/esp-6buttontest-pmb.yaml b/esphome/esp-6buttontest-pmb.yaml index 1fb697d..0e7f045 100644 --- a/esphome/esp-6buttontest-pmb.yaml +++ b/esphome/esp-6buttontest-pmb.yaml @@ -9,7 +9,9 @@ # process then hold down the I00 button. I think GPIO12 is preventing the flash process # 2. OTA flash to an Existing Tasmota device is likely a bit hard with and ESP32 as they # expect a signed Tasmota binary... and partition layout needs to be fixed anyway -# +# 3. EspHome warns on compiling: "legacy adc driver is deprecated, please migrate to use +# esp_adc/adc_oneshot.h and esp_adc/adc_continuous.h for oneshot mode and continuous mode +# drivers respectively" [-Wcpp]"" # ########################################################################################## ########################################################################################## @@ -104,6 +106,40 @@ esp32: preferences: flash_write_interval: 5min # not too important but anything written for reboot mem will wear the flash + +########################################################################################## +# GLOBALS - State storage for vrelays +########################################################################################## +globals: + - id: vrelay_1_state + type: bool + restore_value: yes + initial_value: 'false' + - id: vrelay_2_state + type: bool + restore_value: yes + initial_value: 'false' + - id: vrelay_3_state + type: bool + restore_value: yes + initial_value: 'false' + - id: vrelay_4_state + type: bool + restore_value: yes + initial_value: 'false' + - id: vrelay_5_state + type: bool + restore_value: yes + initial_value: 'false' + - id: vrelay_5b_state + type: bool + restore_value: yes + initial_value: 'false' + - id: vrelay_5c_state + type: bool + restore_value: yes + initial_value: 'false' + ############################################# # ESPHome Logging Enable # https://esphome.io/components/logger.html @@ -187,9 +223,8 @@ binary_sensor: mode: INPUT inverted: true name: "Button 5: ${switch_5_name}" - # No delayed_on/off here to allow accurate multi-click timing on_multi_click: - # Double click first + # Double click - timing: - ON for 50ms to 500ms - OFF for 50ms to 500ms @@ -304,67 +339,104 @@ switch: - platform: template name: "Output 1: ${switch_1_name}" id: vrelay_1 - restore_mode: RESTORE_DEFAULT_OFF + lambda: |- + return id(vrelay_1_state); turn_on_action: - light.turn_on: led1 + - lambda: |- + id(vrelay_1_state) = true; turn_off_action: - light.turn_off: led1 + - lambda: |- + id(vrelay_1_state) = false; - platform: template name: "Output 2: ${switch_2_name}" id: vrelay_2 - restore_mode: RESTORE_DEFAULT_OFF + lambda: |- + return id(vrelay_2_state); turn_on_action: - light.turn_on: led2 + - lambda: |- + id(vrelay_2_state) = true; turn_off_action: - light.turn_off: led2 + - lambda: |- + id(vrelay_2_state) = false; - platform: template name: "Output 3: ${switch_3_name}" id: vrelay_3 - restore_mode: RESTORE_DEFAULT_OFF + lambda: |- + return id(vrelay_3_state); turn_on_action: - light.turn_on: led3 + - lambda: |- + id(vrelay_3_state) = true; turn_off_action: - light.turn_off: led3 + - lambda: |- + id(vrelay_3_state) = false; - platform: template name: "Output 4: ${switch_4_name}" id: vrelay_4 - restore_mode: RESTORE_DEFAULT_OFF + lambda: |- + return id(vrelay_4_state); turn_on_action: - light.turn_on: led4 + - lambda: |- + id(vrelay_4_state) = true; turn_off_action: - light.turn_off: led4 + - lambda: |- + id(vrelay_4_state) = false; - platform: template name: "Output 5: ${switch_5_name}" id: vrelay_5 - restore_mode: RESTORE_DEFAULT_OFF + lambda: |- + return id(vrelay_5_state); turn_on_action: - light.turn_on: led5 + - lambda: |- + id(vrelay_5_state) = true; turn_off_action: - light.turn_off: led5 + - lambda: |- + id(vrelay_5_state) = false; + #- switch.turn_off: vrelay_5c - platform: template name: "Output 5B: ${switch_5b_name}" id: vrelay_5b - restore_mode: RESTORE_DEFAULT_OFF + lambda: |- + return id(vrelay_5b_state); turn_on_action: - logger.log: "vrelay_5b ON" + - lambda: |- + id(vrelay_5b_state) = true; turn_off_action: - logger.log: "vrelay_5b OFF" + - lambda: |- + id(vrelay_5b_state) = false; - platform: template name: "Output 5C: ${switch_5c_name}" id: vrelay_5c - restore_mode: RESTORE_DEFAULT_OFF + lambda: |- + return id(vrelay_5c_state); turn_on_action: - light.turn_on: - id: led1 + id: led5 effect: "Pulse 0.5s" + - lambda: |- + id(vrelay_5c_state) = true; turn_off_action: - - light.turn_off: led1 + - light.turn_off: led5 + - lambda: |- + id(vrelay_5c_state) = false; + #- switch.turn_off: vrelay_5 #- platform: template # name: "Output 6: ${switch_6_name}" @@ -423,8 +495,8 @@ sensor: filters: - calibrate_linear: # Format: raw_value -> real_voltage_at_pin - - 0.80 -> 3.20 # Example: ADC reads 0.80 when pin is actually 3.20V - - 0.90 -> 3.60 # Example: ADC reads 0.90 when pin is actually 3.60V - - 1.00 -> 4.00 # Example: ADC reads 1.00 when pin is actually 4.00V - - multiply: 4.00 # Voltage divider ratio + - 00.66 -> 10.00 # Example: ADC reads 0.80 when pin is actually 3.20V + - 00.99 -> 15.00 # Example: ADC reads 1.00 when pin is actually 4.00V + - 01.30 -> 20.00 # Example: ADC reads 0.90 when pin is actually 3.60V + #- multiply: 4.00 # Voltage divider ratio unit_of_measurement: "V" \ No newline at end of file