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:
Listen for UDP packets on a configurable port
Receive string data via UDP
Send UDP responses back to the sender
Trigger ESPHome automations on data reception
Access sender’s IP address and port in lambda functions
IP address filtering/whitelist
Text content filtering (contains, starts_with, ends_with, equals)
Non-blocking continuous operation with loop() monitoring
Multiple triggers with different filters per UDP port
My personal use example can be found under the examples directory in fake_shelly_em.yaml