"pins": {
"9": "LED_n;1",
"15": "WifiLED_n;0",
"17": "Btn;1",
"24": "BridgeFWD;1",
"26": "BridgeREV;1"
},
I've added them, and my config looks like this (not tested with the relay as the power supply in this unit is broken, which is why I took it out of service and opened it up and finally got round to liberating it).
There may be better ways to tie the LED to the relay state, but there isn't a suitable H-Bridge driver in esphome for relays so manually pulsing for 100ms when the LED goes on/off seemed reasonable enough.
esphome:
name: upk2esphome-bk7231n
on_boot:
- switch.turn_on: relay
bk72xx:
board: generic-bk7231n-qfn32-tuya
packages:
base: !include base.yaml # My wifi and MQTT settings
logger:
level: DEBUG
mqtt:
on_connect:
then:
- light.turn_on: led
on_disconnect:
then:
- light.turn_off: led
text_sensor:
- platform: libretiny
version:
name: LibreTiny Version
light:
- platform: status_led
name: "Status LED"
pin:
number: P15
inverted: true
id: led
restore_mode: ALWAYS_OFF
binary_sensor:
- platform: gpio
name: button
id: button
internal: true
pin:
number: P17
inverted: true
filters:
- delayed_off: 10ms
on_press:
then:
switch.toggle: relay
switch:
- platform: gpio
internal: true
pin: P24
id: relay_on
restore_mode: ALWAYS_OFF
- platform: gpio
internal: true
pin: P26
id: relay_off
restore_mode: ALWAYS_OFF
- platform: gpio
pin:
number: P9
inverted: true
id: relay
name: Relay
restore_mode: ALWAYS_OFF # Will by turned on (with relay) at boot
on_turn_on:
then:
- switch.turn_off: relay_off
- switch.turn_on: relay_on
- delay: 100ms
- switch.turn_off: relay_on
on_turn_off:
then:
- switch.turn_off: relay_on
- switch.turn_on: relay_off
- delay: 100ms
- switch.turn_off: relay_off
uart:
id: uart_bus
tx_pin: TX1
rx_pin: RX1
baud_rate: 4800
stop_bits: 1
sensor:
- platform: bl0942
uart_id: uart_bus
current:
name: BL0942 Current
voltage:
name: BL0942 Voltage
power:
name: BL0942 Power
filters:
multiply: -1
energy:
name: BL0942 Energy
frequency:
name: BL0942 Frequency
accuracy_decimals: 2