Skip to content

Commit a7e1c3a

Browse files
committed
Add info for multiplexing to sml.rst
Add info on how multiple meters can be read using a single HardwareSerial UART.
1 parent c4512fb commit a7e1c3a

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

content/components/sml.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,47 @@ sensor:
212212
state_class: measurement
213213
```
214214

215+
## Reading multiple meters
216+
217+
If you are reading data from more meters than your controller has UARTs available (e.g. more than two for an ESP32), you can use multiplexing to switch between reading data from different meters.
218+
219+
In order to do this, after each SML update, the used UART can be set to listen to a different pin.
220+
An example on how to do this is this:
221+
222+
```yaml
223+
uart:
224+
- baud_rate: 9600
225+
data_bits: 8
226+
rx_pin:
227+
number: GPIO17 # Set to the first of the GPIO pins in multiplex_pins
228+
id: uart_multiplex_rx_pin
229+
stop_bits: 1
230+
rx_buffer_size: 512
231+
id: uart_multiplexed
232+
sml:
233+
- id: sml_multiplexed
234+
uart_id: uart_multiplexed
235+
on_data:
236+
- lambda: |-
237+
std::vector<gpio_num_t> multiplex_pins = {::GPIO_NUM_17,::GPIO_NUM_19};
238+
static size_t current_index = 0;
239+
current_index = (current_index + 1) % multiplex_pins.size();
240+
gpio_num_t new_rx_pin = multiplex_pins[current_index];
241+
id(uart_multiplex_rx_pin).set_pin(new_rx_pin);
242+
id(uart_multiplexed).load_settings(true);
243+
sensor:
244+
- platform: sml
245+
name: "Solar Roof"
246+
sml_id: sml_multiplexed
247+
server_id: "12345ab" # IMPORTANT! Set the correct server id
248+
obis_code: "1-0:2.8.0"
249+
- platform: sml
250+
name: "Solar Carport"
251+
sml_id: sml_multiplexed
252+
server_id: "67890cd" # IMPORTANT! Set the correct server id
253+
obis_code: "1-0:2.8.0"
254+
```
255+
215256
## See Also
216257

217258
- {{< apiref "sml/sml.h" "sml/sml.h" >}}

0 commit comments

Comments
 (0)