ESPHome - configuration JetHub E1-CPU
Processor module configuration JetHub E1-CPU (without motherboard) for 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 platform: ESP32
4 board: nodemcu-32s
5 name_add_mac_suffix: true # This option adds MAC address to the end of the device name
6
7## WARNING: Disable WiFi and captive_portal if Ethernet enabled
8#wifi:
9# ssid: "***"
10# password: "***"
11#
12# # Enable fallback hotspot (captive portal) in case wifi connection fails
13# ap:
14# ssid: "JetHub E1 Fallback Hotspot"
15# password: "***"
16#
17#captive_portal:
18
19# Enable Ethernet
20ethernet:
21 type: LAN8720
22 mdc_pin: GPIO23
23 mdio_pin: GPIO18
24 clk_mode: GPIO17_OUT
25 phy_addr: 1
26
27# Enable logging
28logger:
29
30# Enable Home Assistant API
31api:
32
33# Enable OTA firmware update
34ota:
35
36# Enable I2C bus
37i2c:
38 sda: 5
39 scl: 4
40 frequency: 400kHz
41 scan: true
42 id: i2c1
43
44# Enable UART1, UART2
45uart:
46 - tx_pin: 33
47 rx_pin: 34
48 baud_rate: 115200
49 id: uart_1
50 - tx_pin: 2
51 rx_pin: 39
52 baud_rate: 115200
53 id: uart_2
54
55# Enable SPI bus
56spi:
57 clk_pin: 14
58 mosi_pin: 13
59 miso_pin: 12
60 id: spi1
61
62# Enable CAN bus
63canbus:
64 - platform: esp32_can
65 id: can1
66 tx_pin: 32
67 rx_pin: 15
68 can_id: 1
69 bit_rate: 125KBPS
70
71# Enable I2C GPIO expanders
72pcf8574:
73 - id: cpu_gpio_exp
74 address: 0x20
75 pcf8575: true
76
77# Enable LEDs
78switch:
79 - platform: gpio
80 name: "Red LED"
81 id: red_led
82 pin:
83 pcf8574: cpu_gpio_exp
84 number: 0
85 mode: OUTPUT
86 inverted: true
87 - platform: gpio
88 name: "Green LED"
89 id: green_led
90 pin:
91 pcf8574: cpu_gpio_exp
92 number: 1
93 mode: OUTPUT
94 inverted: true
95
96# Enable button
97binary_sensor:
98 - platform: gpio
99 name: "FN button"
100 pin:
101 number: 0
102 inverted: true
103 - platform: gpio
104 name: "USER button"
105 pin:
106 pcf8574: cpu_gpio_exp
107 number: 2
108 inverted: true
Explanations
Basic Settings
Sets the name of the controller, the type of hardware platform:
esphome:
name: e1-cpu-basic
platform: ESP32
board: nodemcu-32s
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: spi1
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
...