UDP server custom component (fake shelly pro em)

I have ceated a UDP server custom component for esphome.

I own a plugin battery that needs a meter to control it’s charge and discharge behaviour. One of the supported meters are a shelly pro EM.
However, I already have an esp (the p1 meter from Marcel Zuidwijk) connected to my P1 port and was looking for ways to use that information.

I found Marstek Venus E with esphome SML Reader as Virtual Shelly 3 Pro EM that already does what I wanted, however the builtin component lacked some features I would like to have and also had an issue with replies coming from the wrong source port (this is a shortcoming of the builtin udp component).

So I set out to create my own custom component:

It features:
:electric_plug: Listen for UDP packets on a configurable port
:incoming_envelope: Receive string data via UDP
:arrows_counterclockwise: Send UDP responses back to the sender
:dart: Trigger ESPHome automations on data reception
:mag: Access sender’s IP address and port in lambda functions
:lock: IP address filtering/whitelist
:mag_right: Text content filtering (contains, starts_with, ends_with, equals)
:zap: Non-blocking continuous operation with loop() monitoring
:performing_arts: Multiple triggers with different filters per UDP port

My personal use example can be found under the examples directory in fake_shelly_em.yaml

2 Likes