Update wren-c5-esphome.yaml

This commit is contained in:
Dave Williams | DitroniX | G8PUO
2026-06-22 10:49:04 +01:00
parent b6c87e3f98
commit 64d5e467d5
+267 -57
View File
@@ -1,11 +1,46 @@
# Dave Williams, DitroniX 2019-2026 (ditronix.net)
# WREN | ESP32-C5 Recliner Linear Motor Controller | IoT Home Automation
# Example Code, to demonstrate and test the WREN C5
# Remember!
# - Set the BOARD to Use ESP32C5 Dev Module (or similar).
# - You can also set the BAUD rate up to 921600 to speed up flashing.
# - The SDK does NOT need external power to flash. It will take Power from the USB 5V.
# - The Serial Monitor is configured for BAUD 115200
# The purpose of this test code is to cycle through the various main functions of the board as part of bring up testing.
# This test code is OPEN SOURCE and formatted for easier viewing. Although is is not intended for real world use, it may be freely used, or modified as needed.
# It is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# For board configuration, see:
# * github.com/DitroniX/WREN-Recliner-Linear-Motor-Controller-IoT-Home-Automation/wiki/Arduino-IDE
# * github.com/DitroniX/WREN-Recliner-Linear-Motor-Controller-IoT-Home-Automation/wiki/PlatformIO-ESP32%E2%80%90C5
# * github.com/DitroniX/WREN-Recliner-Linear-Motor-Controller-IoT-Home-Automation/wiki/Home-Assistant-and-ESPHome
# * github.com/DitroniX/Home-Assistant-Dev
# Further information, details and examples can be found on our website or github.com/DitroniX
# * ditronix.net
# * github.com/DitroniX
# * github.com/DitroniX/WREN-Recliner-Linear-Motor-Controller-IoT-Home-Automation
# * github.com/DitroniX/WREN-Recliner-Linear-Motor-Controller-IoT-Home-Automation/wiki
# * github.com/DitroniX/WREN-Recliner-Linear-Motor-Controller-IoT-Home-Automation/wiki/FAQ
# * hackster.io/DitroniX/
# * hackster.io/DitroniX/wren-esp32-c5-recliner-linear-motor-controller-iot-rs485-e2b397
# This YAML code has been created to show the features and functionality of WREN C5.
# This code has expanded to become an all encompassing ESPHome applicaition and is a fully working baseline.
esphome: esphome:
name: wren-c5 name: wren-c5
friendly_name: WREN C5
on_boot: on_boot:
priority: 800 priority: 800
then: then:
- lambda: |- - lambda: |-
uint8_t cfg[2] = {0x03,0x00}; uint8_t cfg[2] = {0x03,0x00};
@@ -22,28 +57,65 @@ esphome:
"TCA6408A initialized" "TCA6408A initialized"
); );
- delay: 500ms - delay: 500ms
- if: - if:
condition: condition:
binary_sensor.is_on: sflag binary_sensor.is_on: sflag
then: then:
- logger.log: - logger.log: "SFLAG ACTIVE AFTER BOOT"
"SFLAG ACTIVE AFTER BOOT" - script.execute: fault_handler
- script.execute:
fault_handler
esp32: esp32:
board: esp32-c5-devkitc-1 board: esp32-c5-devkitc-1
variant: esp32c5 variant: esp32c5
framework: framework:
type: esp-idf type: esp-idf
i2c: ################################## ESPHOME ##################################
# ======================== ESPHome - Enter Below your Key/Pasawords ===========================
api:
encryption:
key: !secret wren_c5__encryption_key
ota:
- platform: esphome
password: !secret wren_c5__ota_password
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: WREN C5 Fallback Hotspot
password: !secret wren_c5__ap_password
captive_portal:
logger:
################################## SUBSTITUTIONS ##################################
substitutions:
# ======================== About ===========================
author: "DitroniX - Dave Williams"
firmware_version: "1.00.02"
release_date: "2026-06-21"
board_name: "WREN C5"
board_mcu: "ESP32-C5"
board_rev: "1.2606.104"
# ======================== Config ===========================
board_location: "Lounge"
voltage_low: 3.00
voltage_high: 48.0
################################## SETUP ##################################
# ========================== GPIO =============================
i2c:
id: bus_a id: bus_a
sda: GPIO2 sda: GPIO2
@@ -52,19 +124,18 @@ i2c:
scan: true scan: true
globals: globals:
- id: fault_active - id: fault_active
type: bool type: bool
restore_value: no restore_value: no
initial_value: 'false' initial_value: "false"
- id: tca_state - id: tca_state
type: uint8_t type: uint8_t
restore_value: no restore_value: no
initial_value: '0' initial_value: "0"
################################## SWITCH ##################################
switch: switch:
- platform: gpio - platform: gpio
id: rs485_enable id: rs485_enable
pin: GPIO23 pin: GPIO23
@@ -75,13 +146,171 @@ output:
pin: GPIO27 pin: GPIO27
id: blue_led id: blue_led
################################## LIGHT ##################################
light: light:
- platform: binary - platform: binary
id: heartbeat id: heartbeat
output: blue_led output: blue_led
binary_sensor: ################################## TEXT SENSOR ##################################
text_sensor:
# =====================================================
# WREN C5 FIRMWARE METADATA
# =====================================================
- platform: template
name: "Author"
entity_category: diagnostic
lambda: |-
return {"${author}"};
- platform: template
name: "Firmware Version"
entity_category: diagnostic
lambda: |-
return {"${firmware_version}"};
- platform: template
name: "Release Date"
entity_category: diagnostic
lambda: |-
return {"${release_date}"};
- platform: template
name: "Board Name"
entity_category: diagnostic
lambda: |-
return {"${board_name}"};
- platform: template
name: "Board MCU"
entity_category: diagnostic
lambda: |-
return {"${board_mcu}"};
- platform: template
name: "Board Build"
entity_category: diagnostic
lambda: |-
return {"${board_rev}"};
- platform: template
name: "Board Location"
entity_category: diagnostic
icon: mdi:information
update_interval: 60s
lambda: |-
return {"${board_location}"};
- platform: template
name: "Product"
icon: mdi:information
entity_category: diagnostic
update_interval: 60s
lambda: |-
return {"Professional Energy Monitor"};
- platform: template
name: "Hardware"
entity_category: diagnostic
icon: mdi:information
update_interval: 60s
lambda: |-
return {"ESP32-C5 Dual ATM90E32"};
- platform: template
name: "WiFi Signal Quality"
id: wifi_signal_quality
entity_category: diagnostic
update_interval: 30s
lambda: |-
if (!id(wifi_signal_db).has_state()) {
return {"No Signal"};
}
int rssi = abs((int)id(wifi_signal_db).state);
if (rssi <= 30) {
return {"Signal Very Strong"};
} else if (rssi <= 50) {
return {"Signal Excellent"};
} else if (rssi <= 60) {
return {"Signal Healthy"};
} else if (rssi <= 70) {
return {"Signal Very Good"};
} else if (rssi <= 80) {
return {"Signal Good"};
} else if (rssi <= 90) {
return {"Signal Poor - Try Moving Position"};
} else if (rssi <= 100) {
return {"Signal Very Low - Move Position"};
} else {
return {"No Signal"};
}
# =====================================================
# VOLTAGE STATUS AND LOG
# =====================================================
- platform: template
name: "Supply Status"
id: supply_status
icon: mdi:power-plug
entity_category: diagnostic
update_interval: 1s
lambda: |-
float v = id(supply_voltage).state;
constexpr float VOLTAGE_LOW = ${voltage_low};
constexpr float VOLTAGE_HIGH = ${voltage_high};
// Developer. Only enable for PCB 1.2606.104 and above, as this value is now taken from +VBUS rather than P24V_DVR
// if (v >= VOLTAGE_LOW && v <= 5.5f) {
// ESP_LOGI(
// "POWER",
// "USB Power Detected - Supply Voltage %.2fV",
// v
// );
// return {"USB Powered"};
// }
if (v >= 5.5f && v <= 10.0f) {
ESP_LOGI(
"POWER",
"Voltage Too Low %.2fV",
v
);
return {"Power Fail"};
}
if (v >= 10.0f && v <= 20.0f) {
return {"Low Voltage"};
}
if (v >= 20.0f && v <= 30.0f) {
return {"Recliner"};
}
if (v >= 30.0f && v <= VOLTAGE_HIGH) {
char buffer[20];
snprintf(buffer, sizeof(buffer), "%.1fV", v);
return {buffer};
}
if (v > 48.0f) {
ESP_LOGI(
"POWER",
"Over Voltage %.2fV",
v
);
return {"Over Voltage"};
}
return {"Unknown"};
############################## BINARY SENSOR ###############################
binary_sensor:
- platform: gpio - platform: gpio
id: in_1a id: in_1a
name: "Motor 1 Extend" name: "Motor 1 Extend"
@@ -130,10 +359,8 @@ binary_sensor:
on_press: on_press:
then: then:
- logger.log: - logger.log: "SFLAG INTERRUPT"
"SFLAG INTERRUPT" - script.execute: fault_handler
- script.execute:
fault_handler
- platform: gpio - platform: gpio
id: en1 id: en1
@@ -151,21 +378,22 @@ binary_sensor:
mode: mode:
input: true input: true
################################## SENSOR ##################################
sensor: sensor:
- platform: adc - platform: adc
id: supply_voltage id: supply_voltage
pin: GPIO4 pin: GPIO4
name: "Supply Voltage" name: "Supply Voltage"
attenuation: auto attenuation: auto
update_interval: 30s update_interval: 30s
entity_category: diagnostic
filters: filters:
- multiply: 44.4444 - multiply: 44.4444
- platform: tmp102 - platform: tmp102
name: "Board Temperature" name: "Board Temperature"
address: 0x4A address: 0x4A
entity_category: diagnostic
update_interval: 30s update_interval: 30s
- platform: wifi_signal - platform: wifi_signal
@@ -175,8 +403,21 @@ sensor:
- platform: uptime - platform: uptime
name: "Uptime" name: "Uptime"
script: # =====================================================
# OTHER SENSORS
# =====================================================
- platform: wifi_signal
name: "WiFi Signal"
id: wifi_signal_db
unit_of_measurement: "dBm"
device_class: signal_strength
state_class: measurement
entity_category: diagnostic
update_interval: 30s
################################## SCRIPT ##################################
script:
- id: fault_handler - id: fault_handler
mode: single mode: single
then: then:
@@ -241,9 +482,8 @@ script:
# ); # );
# esp_restart(); # esp_restart();
################################## INTERVAL ##################################
interval: interval:
# heartbeat # heartbeat
- interval: 1s - interval: 1s
@@ -252,13 +492,11 @@ interval:
- delay: 750ms - delay: 750ms
- light.turn_off: heartbeat - light.turn_off: heartbeat
# motor supervisor # motor supervisor
- interval: 10ms - interval: 10ms
then: then:
- lambda: |- - lambda: |-
// //
@@ -304,18 +542,16 @@ interval:
// VOLTAGE CHECK // VOLTAGE CHECK
// //
constexpr float VOLTAGE_LOW = ${voltage_low};
constexpr float VOLTAGE_HIGH = ${voltage_high};
float v = id(supply_voltage).state; float v = id(supply_voltage).state;
if(v < 10.0f || v > 48.0f) if (v < VOLTAGE_LOW || v > VOLTAGE_HIGH)
{ {
ESP_LOGE( ESP_LOGE("FAULT", "Voltage %.2fV out of range", v);
"FAULT",
"VOLTAGE %.1f",
v
);
id(fault_handler).execute(); id(fault_handler).execute();
return; return;
} }
uint8_t output=0; uint8_t output=0;
@@ -347,7 +583,6 @@ interval:
if(m1b) if(m1b)
output |= (1<<2); output |= (1<<2);
// MOTOR 2 // MOTOR 2
if(m2a) if(m2a)
output |= (1<<4); output |= (1<<4);
@@ -365,33 +600,8 @@ interval:
2 2
); );
// ESP_LOGI( // ESP_LOGI(
// "motor", // "motor",
// "OUT=0x%02X", // "OUT=0x%02X",
// output // output
// ); // );
# #############################
# Enable Home Assistant API
api:
encryption:
key: "xxxx="
ota:
- platform: esphome
password: "xxxx"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Wren-C5-Test Fallback Hotspot"
password: "xxxx"
captive_portal:
logger: