ESPHome - configuration JetHub E1-CPU
Processor module configuration JetHub E1-CPU (without motherboard) for ESPHome.
Note
The configuration uses ESPHome 2024.6.0 or newer syntax (the ota section with platform: esphome).
Contents
Configuration
- This configuration implements:
Setting up Ethernet with automatic IP address detection.
Integration with Home Assistant.
Setting the LEDs
STAT(red and green).Setting the button
FN.Configuring interfaces: I2C, UART, SPI, CAN.
Note
Once the controller is loaded and the IP address is obtained, the controller will automatically be available on the Home Assistant running on the same network.
Hint
:download:` Download jethub_e1_cpu.yaml <jethub_e1_cpu.yaml>`
1esphome:
2 name: e1-cpu-basic
3 name_add_mac_suffix: true # This option adds MAC address to the end of the device name
4
5esp32:
6 board: nodemcu-32s
7 framework:
8 type: esp-idf
9
10## WARNING: Disable WiFi and captive_portal if Ethernet enabled
11#wifi:
12# ssid: "***"
13# password: "***"
14#
15# # Enable fallback hotspot (captive portal) in case wifi connection fails
16# ap:
17# ssid: "JetHub E1 Fallback Hotspot"
18# password: "***"
19#
20#captive_portal:
21
22# Enable Ethernet
23ethernet:
24 type: LAN8720
25 mdc_pin: GPIO23
26 mdio_pin: GPIO18
27 clk_mode: GPIO17_OUT
28 phy_addr: 1
29
30# Enable logging
31logger:
32
33# Enable Home Assistant API
34api:
35
36# Enable OTA firmware update
37ota:
38 - platform: esphome
39
40# Enable I2C bus
41i2c:
42 sda: 5
43 scl: 4
44 frequency: 400kHz
45 scan: true
46 id: i2c1
47
48# Enable UART1, UART2
49uart:
50 - tx_pin: 33
51 rx_pin: 34
52 baud_rate: 115200
53 id: uart_1
54 - tx_pin: 2
55 rx_pin: 39
56 baud_rate: 115200
57 id: uart_2
58
59# Enable SPI bus
60spi:
61 clk_pin: 14
62 mosi_pin: 13
63 miso_pin: 12
64 id: spi_bus
65
66# Enable CAN bus
67canbus:
68 - platform: esp32_can
69 id: can1
70 tx_pin: 32
71 rx_pin: 15
72 can_id: 1
73 bit_rate: 125KBPS
74
75# Enable I2C GPIO expanders
76pcf8574:
77 - id: cpu_gpio_exp
78 address: 0x20
79 pcf8575: true
80
81# Enable LEDs
82switch:
83 - platform: gpio
84 name: "Red LED"
85 id: red_led
86 pin:
87 pcf8574: cpu_gpio_exp
88 number: 0
89 mode: OUTPUT
90 inverted: true
91 - platform: gpio
92 name: "Green LED"
93 id: green_led
94 pin:
95 pcf8574: cpu_gpio_exp
96 number: 1
97 mode: OUTPUT
98 inverted: true
99
100# Enable button
101binary_sensor:
102 - platform: gpio
103 name: "FN button"
104 pin:
105 number: 0
106 inverted: true
107 - platform: gpio
108 name: "USER button"
109 pin:
110 pcf8574: cpu_gpio_exp
111 number: 2
112 inverted: true
Explanations
Basic Settings
Set the controller name and hardware platform type (the board and framework are moved to a separate esp32 block):
esphome:
name: e1-cpu-basic
esp32:
board: nodemcu-32s
framework:
type: esp-idf
Automatic name suffix
Warning
There should not be two devices with the same name on the same network.
The option adds a suffix based on the MAC address to the device name:
name_add_mac_suffix: true # This option adds MAC address to the end of the device name
Network settings
Warning
Due to ESPHome limitations, Ethernet and Wi-Fi cannot work simultaneously.
Therefore, when using the Ethernet port, it is necessary to disable the sections wifi and captive_portal in the configuration file.
Ethernet
# Enable Ethernet
ethernet:
type: LAN8720
mdc_pin: GPIO23
mdio_pin: GPIO18
clk_mode: GPIO17_OUT
phy_addr: 1
Wi-Fi
Note
ssid and password must be replaced with your own.
wifi:
ssid: "***"
password: "***"
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "JetHub E1 Fallback Hotspot"
password: "***"
Integration with Home Assistant
To integrate the controller into the Home Assistant system it is sufficient to include the section api in the configuration file:
# Enable Home Assistant API
api:
UART ports
Two UART ports, connected to the expansion slot:
# Enable UART1, UART2
uart:
- tx_pin: 33
rx_pin: 34
baud_rate: 115200
id: uart_1
- tx_pin: 2
rx_pin: 39
baud_rate: 115200
id: uart_2
I2C bus
1# Enable I2C bus
2i2c:
3 sda: 5
4 scl: 4
5 frequency: 400kHz
6 scan: true
7 id: i2c1
** Connected to this bus**:
GPIO port expander:
# Enable I2C GPIO expanders pcf8574: - id: cpu_gpio_exp address: 0x20 pcf8575: trueEEPROM:
Todo
Add description
RTC:
Todo
Add description
SPI bus
The SPI bus is connected to the expansion slot:
# Enable SPI bus
spi:
clk_pin: 14
mosi_pin: 13
miso_pin: 12
id: spi_bus
CAN bus
It is possible to output the CAN bus to the expansion connector, it is recommended to use the pins 32 and 15 ESP32 for this purpose:
# Enable CAN bus
canbus:
- platform: esp32_can
id: can1
tx_pin: 32
rx_pin: 15
can_id: 1
bit_rate: 125KBPS
GPIO port expander
Note
Some of the peripherals are connected to the GPIO port expander on the processor board. Therefore, a PCF8575 GPIO expander must be configured in advance (the address on the I2C bus is 0x20).
# Enable I2C GPIO expanders
pcf8574:
- id: cpu_gpio_exp
address: 0x20
pcf8575: true
LEDs
Inverse logic is used to control the LEDs:
# Enable LEDs
switch:
- platform: gpio
name: "Red LED"
id: red_led
pin:
pcf8574: cpu_gpio_exp
number: 0
mode: OUTPUT
inverted: true
- platform: gpio
name: "Green LED"
id: green_led
pin:
pcf8574: cpu_gpio_exp
number: 1
mode: OUTPUT
inverted: true
Note
When you change the state of the outputs, after some time (~40 sec) ESPHome automatically saves their state by default and after reboot restores the state of the outputs to the previously saved.
If this functionality is not needed, you must change this function by setting the output state at startup with the option restore_mode, for example:
switch:
- platform: gpio
...
restore_mode: ALWAYS_OFF
...