esphome / feature-requests

ESPHome Feature Request Tracker
https://esphome.io/
411 stars 26 forks source link

[Feature Request] for Cloudflared tunnel support #2223

Open deanfourie1 opened 1 year ago

deanfourie1 commented 1 year ago

Would love to see integration for the ESPhome project and ESP32 to support the possiblity to connect to a cloudflared tunnel. Not sure how possible this is to achieve, but I have a use case scenario where I want to use a ESP32 to connect and send MQTT over WAN on a different network / 4G, but cannot open port due to CGNat.

Allowing ESPhome to connect the ESP to a cloudflared tunnel would be pretty awesome!

deanfourie1 commented 1 year ago

bump

PablexXXXX commented 1 year ago

This would be amazing. Imagine if you could have an URL entry in your YAML pointing to your external home assistance instance. PLEASE DO THIS.

PablexXXXX commented 1 year ago

ESPHome Cloudflare tunnel.

Ralphy140 commented 1 year ago

As described in a similar request this the challenge is that the ESPHome device is the server not the HA so the ESPHome device would need to setup the tunnel not the other way around. to be able to expose the ESPHome device you would need it to run the cloudflared tunnel code on the ESP and then create a new DNS endpoint. You would then need to point your home assistant server at the new end point.1) I am not sure that the ESP32 is powerfull enough to run that code and 2) A solution for remote and encrypted communication already exists, if you want to do remote ESP home devices it would be best to use encrypted/authenticated MQTT that is pointed at a public MQTT broker then connect your HA instance to liten to that MQTT server, this still solve the "anywhere" challenge of deploying an ESPHome device with components that are already in place.

deanfourie1 commented 1 year ago

Yes but in order to setup remote MQTT you will need to have MQTT port open server side.

This is not possible for those behind CGNat.

The idea of the esp32 creating the tunnel is seemless,

It executes the connection and creates the tunnel,

The the cloudflare routing handles the rest, routing between other tunnels etc to reach the HA instance.

This is what would make this integration so awesome.

Ralphy140 commented 1 year ago

In this architecture you would use a public MQTT broker like hivemq, You would connect both the endpoint of the ESP and the HA server to it. Then it will do MQTT message exchange without ether device being public. I am not proposing that you make your HA server public

nagyrobi commented 1 year ago

Cloudflared is "public" too... They do see inside your tunnels...

dougiteixeira commented 1 year ago

I manage to expose my MQTT broker through the cloudflared tunnel, but only MQTT over WebSocket, which is not possible to use with ESPHome… so implementing MQTT over WebSocket in ESPHome could be a palliative to be able to use remote ESPHome devices even being in a CGNAT network (where it is not possible to expose ports) and not needing to depend on public brokers.

Marckkill commented 9 months ago

This would be amazing.

VishveshC commented 3 months ago

Dead thread; but did this ever come to life? Anyone find a way?

deanfourie1 commented 3 months ago

Nah, sad :(

grest commented 2 months ago

I manage to expose my MQTT broker through the cloudflared tunnel, but only MQTT over WebSocket, which is not possible to use with ESPHome… so implementing MQTT over WebSocket in ESPHome could be a palliative to be able to use remote ESPHome devices even being in a CGNAT network (where it is not possible to expose ports) and not needing to depend on public brokers.

Yes, I did the same. Support of WebSocket transport is the missing component and would be the excellent solution.

deanfourie1 commented 2 months ago

But seriously, how hard could it be? I don't see it requiring a lot of resources on the esp to make this feature possible.

Cloudflare have all docs available for API. Just need some smart cookie to make it happen ;)