Skip to content

Commit 4fd54f2

Browse files
authored
Add info for multiplexing to sml.rst
Add info on how multiple meters can be read using a single HardwareSerial UART.
1 parent 74fc2db commit 4fd54f2

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

components/sml.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,63 @@ These meters can also measure the instantaneous power usage.
224224
device_class: power
225225
state_class: measurement
226226
227+
Reading multiple meters
228+
---------------------------------
229+
If you are reading data from more meters than your controller has UARTs available (e.g. more than 2 for an ESP32), you can use multiplexing to switch between reading data from different meters.
230+
231+
In order to do this, after each SML update, the used UART can be set to listen to a different pin.
232+
An example on how to do this is this:
233+
234+
.. code-block:: yaml
235+
236+
uart:
237+
- baud_rate: 9600
238+
data_bits: 8
239+
rx_pin:
240+
number: 17 # Set to the first of the GPIO pins
241+
id: uart_multiplex_rx_pin
242+
stop_bits: 1
243+
rx_buffer_size: 512
244+
id: uart_multiplexed
245+
246+
sml:
247+
- id: sml_multiplexed
248+
uart_id: uart_multiplexed
249+
on_data:
250+
- lambda: |-
251+
std::vector<gpio_num_t> multiplex_pins = {::GPIO_NUM_17,::GPIO_NUM_19};
252+
static size_t current_index = 0;
253+
current_index = (current_index + 1) % multiplex_pins.size();
254+
gpio_num_t new_rx_pin = multiplex_pins[current_index];
255+
ESP_LOGD("uart_multiplex", "Switching to RX pin: %d (%d)", new_rx_pin, current_index);
256+
id(uart_multiplex_rx_pin).set_pin(new_rx_pin);
257+
id(uart_multiplexed).load_settings(true);
258+
259+
sensor:
260+
- platform: sml
261+
name: "Solar Roof"
262+
sml_id: sml_multiplexed
263+
server_id: "12345ab" # IMPORTANT! Set the correct server id
264+
obis_code: "1-0:2.8.0"
265+
unit_of_measurement: kWh
266+
accuracy_decimals: 2
267+
device_class: energy
268+
state_class: total_increasing
269+
filters:
270+
- multiply: 0.0001
271+
- platform: sml
272+
name: "Solar Carport"
273+
sml_id: sml_multiplexed
274+
server_id: "67890cd" # IMPORTANT! Set the correct server id
275+
obis_code: "1-0:2.8.0"
276+
unit_of_measurement: kWh
277+
accuracy_decimals: 2
278+
device_class: energy
279+
state_class: total_increasing
280+
filters:
281+
- multiply: 0.0001
282+
283+
227284
See Also
228285
--------
229286

0 commit comments

Comments
 (0)