Receiving UDP traffic

I have a device that is spitting out UDP messages, I would like to pull these into hassio and create a sensor from the data. Is this easy and where should I start?

1 Like

I am having the same problem, though no solution yet.

I think node-red can receive udp packets and react. I’m starting using it for some automation instead of yaml and it seems very promising.

1 Like

Spot on! I now have my lightwaverf trv displaying on home assistant :slight_smile:

Hi there,
I had the same issue with a device regularly reporting via UDP, and exploiting the existing TCP sensor I have created the following UDP sensor:

Maybe useful for your case? I’m considering to do a PR and contribute it back, even though there’s quite some duplication with the TCP sensor and it could be merged with it.

1 Like

How do I use your UDP sensor? Can you give a short explanation please?
I’m trying to get data from my pellet burner and it uses an UDP protocol.

Cheers!

Hi,

The configuration is very similar to the TCP sensor. The only required parameter is the UDP port to which to listen, e.g.:

sensor:
  - platform: udp
    port: your_port
    timeout: 30
    name: your_favourite_name

Note that your HA must be able to bind and listen to that port. If you run it in a docker container, you have to either use the --net=host option when creating the container or explicitly bridge the port with -p.

Hope this helps,
Cheers,
Giuseppe

Does it matter if it’s Hass.io or not? I’m running Hass.io on a RPi…

Is it in a container? If so, the note above applies, otherwise I think it does not matter…

1 Like

Ok. Thank you for the clarification and work! :+1:

No problem! Feel free to post whether it works for you on Hass.io…

Hi

how do you use the script ?
I get a “Unable to find component sensor.udp” when starting Home assistant on RPI

Can you make a short guide on how to load the script to make the UDP sensor work :slight_smile:

Thx

Did you copy the script to <your_hass_config>/custom_components/sensor/udp.py ? That’s where Home Assistant looks for any custom component, nothing specific to this one :wink:

Hi
Thx for the reply.
i now got the config of the UDP sensor working, but its not showing any data received.
Just getting these warnings in the log
image

Ok, that may be due to your device’s refresh interval: for example in my case I know I get an update every 60 seconds, so this is the timeout I set.

As for the warnings, this is due to the sensor being synchronous (like the TCP one) and for now I don’t have a solution.

Hope this helps

I don´t quite understand where I have to use the “–net=host” or “-p” options, since in the log I get a " Unable to bind on port"
Thanks for the component!

Which command line do you use to run your homeassistant container? --net=host or -p host_port:container_port are possible options to be given to docker.

I run HA in a RPi, from the image of Hass.io that I’ve downloaded of the official site…don´t even know if I´m answering what you asked, but I don´t exactly know how Hass.io works inside, sorry

Well, neither do I - I run HA directly from its container and I control the way it is started, I guess Hass.io is also container-based, and if this is the case it is definitely possible to change the way it is executed. Perhaps you could ask around for more details. Sorry for not being more helpful.

Thanks anyway!

1 Like