Sending data via LoRa on ESPHome

I have some ESP32 LoRa devices connected to a simple relay and reed sensor. My first question is about sending data over LoRa from ESPHome. As far as I can tell ESPHome doesn’t have any LoRa integrations. I’m assuming then I have to write a custom component and include it in my ESPHome config if I want to use both use ESPHome and send/receive data over LoRa?

My second questions is…can I use LoRa bi-direcitonally? Meaning, can I send a command to my ESP32 over LoRa? I want the device to both send the status of my sensors when they change, and also open/close the relay when I send that command.

I have seen a lot of Arduino code for supporting LoRa but I haven’t been able to find anyone integrating it into ESPHome. I already have a LoRa WAN device that can receive data and publish it to my local MQTT server. Any help or insight appreciated!

No, it doesn’t work over LoRa. LoRa does not have a TCP/IP stack.

Possibly you are best to implement openmqttgateway https://docs.openmqttgateway.com/

Which part doesn’t work over LoRa?

1 Like

Sorry I misunderstood? So you want to essentially make a LoRa to HA gateway?

I still think you would be better to not reinvent the wheel and use OMG.

You can’t use lora to link an ESP with HA through the API as stated by @nickrout as it’s not a network protocol by itself. It’s more a messaging system but you can interface without problem a Lora device with HA if you use either an existing network like TTN or using your own private Lora network with a gw and chirpstack :wink: It can be used in both directions but downlink is very limited on Lora and quite delayed in transmission so you can’t use lora for realtime or nearly, it’s not designed for that !

I have a WisGate Edge Lite 2 and ESP32 with a RFM95W LoRa modem connected to a Relay and 2 Reed sensors. I also am running HomeAssistant.

The WisGate (afaik) acts as the gateway between LoRa devices and my network. I imagine it would just push data it receives to my MQTT Server that I could then read from HomeAssistant.

What I don’t understand is:

  1. How do I program my ESP32 with ESPHome and send sensor data over LoRa?
  2. Can I also send data to my ESP32 over LoRa?

I am not trying to re-invent the wheel, totally open to using OMG. I don’t fully understand how it applies for my use case and need to read up on it. This is my first LoRa project so any handholding/explaining is super appreciated. Thank you a bunch

This part I understand. I have a WisGate Edge Lite 2 which is a gateway that can push LoRa messages to my local MQTT server. I can then read them from HA that way. That part is clear to me. What’s confusing is how do I program my ESP32 to push sensor data over LoRa?

How slow are we talking here? I don’t mind if there is a delay.

As Lora is not yet supported by ESPHome you’ll have to program the ESP using Arduino for example to handle properly the Lora module and that’s it :wink: In all matters you don’t care about ESPHome as you can’t use the ESPHome API in that configuration and communication between HA and your ESP will be done through Lora and your MQTT server :wink: I guess sparkfun supplies some code samples you can start from no ?

Depends of multiple factors in Lora but will go from 1/2 minutes up to few minutes depending of Lora RF load in your area !

Thank you! I live in a rural area and I feel quite confident I am the only person using LoRa in a 15 mile radius :slight_smile: - 30s is an acceptable delay for my use-case.

I feel fine programming the ESP with arduino, I’ll go down that rabbit hole. In terms of configuring my rak-7240 gateway, I’ll have to read up on that. Still a bit unclear how I provision a device that I’m both listening and sending data to.

When you say “depending of Lora RF load in your area !” - Would that still matter even if I was in a LoRa dense area if I’m using my own private gateway?

yep Lora RF spectrum should be quite empty then :+1:

gw is not involved in the process as it’s just forwarding from/to radio messages with Lora server so it does both automatically ! It’s more a question to program it in HA through your MQTT gw to send messages at Lora devices and gw will broadcast message as soon as possible :wink:

own private gw means nothing ! you mean private Lora server ? whatever you are still restricted by RF noise around whatever it’s same Lora network or not :wink:

Ok, this should be pretty quick publishing to MQTT. Thank you for clarifying.

Got it, and thanks for the terminology correction. And yeah I was mostly just trying to suss out if it was an RF noise concern, thanks for answering that!

I think you guys may be confusing LoRa and LoRaWan.

I have no idea what I’m doing honestly, can you expand on what I might be confusing here? I explained the hardware I have above.

If you have any more info to share I would love that. I do not want to use any external/cloud services. I solely want to capture LoRa messages from a LoRa enabled ESP32 I have and publish them to my local MQTT server. I believe I am able to do this with my WisGate Edge/rak-7240. I’m still in the weeds figuring out how to implement it so if I’m misunderstanding something let me know.

1 Like

I think @nickrout pointed out a common misunderstanding between Lora and Lorawan. With the details given, it seems that you are trying to implement a solution leveraging the lorawan protocol on top of Lora.

Let’s differentiate 4 systems into your architecture:

  • the node, you would like to use an esp32
  • the gateway, you have a rak7240
  • the mqtt broker
  • hass

Your rak7240 is a Lora gateway leveraging lorawan protocol.
From this constraint you will need to have an esp32 firmware that supports the lorawan protocol and not only Lora.
As you want to control a device, I suggest to take a look to the different classes of Lorawan devices, A,B or C this will be important for your esp32 node firmware.
You don’t want to rely on a cloud, your gateway would require to have a lorawan server built in, I think it has, but you need to check.
This server would need to be configured to connect to your mqtt broker and forward data both ways.
Finaly you will have to parse the data into Home Assistant.

TTN is proposing good lessons and courses of Lorawan, I encourage you to take those, it will help you in your journey.

As an alternative, for your system you could use an off the shelf lorawan relay/input like the Dragino LT22222, you could earn days of work depending on your existing knowledge.

If you didn’t have the gateway, you could use an esp32 + a lora module as a gateway with or without lorawan.

  • Without Lorawan, OpenMQTTGateway does it.
  • With Lorawan you can find programs already made also, but this would not be a state of the art implementation of Lorawan. Due to the fact that your gateway will have only one channel. And surely less performance compared to the rak7240.

if your gateway can forward the decoded packets from the device to an MQTT broker, this is your simplest route.

Otherwise, to make your life easier, use Chirpstack as the LoRa network core and then you can ship your packets to wherever you want. The beauty of the latest Chirpstack core (v4) is that you can import hundreds of different codecs from TTN…

TTN can be very frustrating and limiting. They have even stricter duty cycles etc…

Personally I connect all my devices (via Chirpstack) and then ingest into HA via MQTT…

2 Likes

Hey,

What gateway are you using with chirpstack? Would like to use a ttgo lora V1.3 as I don’t need more than 1 ch.
Cheers

Dont waste time or money with single channel gateways. Go for something like the Dragino lps8. The Heltec is also a good option.

I run a network with around 20-30 gateways all different types.

With single channel you cannot do ABP as an example… rather get something half decent…

If you really want to try something different, then get a Dragino HP0D, as you can then send traffic to Helium as well as your own private network and therefore recoup some of the gateway cost via HNT… although, token price is pretty low right now…

I don’t want to dirty up a good thread so I’ll keep it simple, is the latency still 30s minimum even if it’s all your own gear and not subject to TTN or other outside factors?

You need to apply the right technology/protocol to your use case requirements. If you want a light to turn on when a lora sensor detects motion, then no, LoRa is not a good fit. But if you want to check when mail has arrived in your mailbox which is at the other end of your garden, a couple hundred meters away, then lora is the right technology

1 Like