Journal

Home Assistant Mobile App + Cloudflare Tunnel: Remote Home Control Without Port Forwarding

Home Assistant Mobile App + Cloudflare Tunnel: ควบคุมบ้านจากทุกที่ไม่ต้อง Port Forward

May 12, 2026 · 1 min read
Home Assistant Mobile App + Cloudflare Tunnel: Remote Home Control Without Port Forwarding

Why You Should Not Port Forward Directly

Opening a port forward (e.g., port 8123 directly to Home Assistant) is high risk: it exposes the login page to bot port scanning and brute force attacks. Old Home Assistant CVE vulnerabilities can be exploited this way. Cloudflare Tunnel provides Zero-Trust Network Access (ZTNA) that is far more secure.

Cloudflare Tunnel for Home Assistant

Architecture: Home Assistant runs a Cloudflared Docker container → connects outbound to the Cloudflare network → Cloudflare acts as a reverse proxy, making the instance accessible at a URL such as https://myhome.example.com with no ports opened on the router.

Step-by-step setup: (1) sign up for Cloudflare Free plan and add your domain; (2) install cloudflared on the Home Assistant host (Docker or HA OS add-on); (3) run cloudflared tunnel create myhome-tunnel; (4) configure the tunnel to forward localhost:8123 → myhome.example.com; (5) add a CNAME DNS record in the Cloudflare dashboard; (6) set trusted_proxies in HA configuration.yaml.

Security layer: add a Cloudflare Access policy requiring Google/GitHub OTP login before the Home Assistant URL can be reached — preventing unauthorised access even if the URL is known.

Home Assistant Companion App

Supports iOS (iPhone/iPad) and Android. Key features: full dashboard for controlling every entity; WebSocket real-time updates — device state pushes instantly without polling; smartphone sensors (battery, step count, GPS location, screen state, network type) feed back into HA as sensors for use in automations; Action Shortcuts — iOS home screen widgets that toggle lights or AC with one tap.

Geofencing for Home/Away Automation

The Companion App uses GPS + Wi-Fi SSID detection to define a Home Zone (50–100m radius). On leaving home: turn off all lights, set AC to economy mode, lock doors. On arriving home: turn on the entrance lights, restore AC to comfort mode, notify family members.

Multi-person geofencing: only switch off AC when every family member has left — using a group.family + not_home condition to prevent switching off while someone is still inside.

iOS Critical Alerts for Emergencies

Standard notifications are silenced in Do Not Disturb mode. iOS Critical Alerts are a special permission that plays at full volume even in silent mode. Use them for: gas leak detector (TGS2611), carbon monoxide alarm, elderly fall detection, and flood sensor under the kitchen sink.

Home Assistant notification configuration: set push → sound → critical: 1 and volume: 1.0 in the notify.mobile_app service data.

Actionable Notifications

Send notifications with action buttons that respond directly without opening the app: tap Turn Off Lights → HA turns them off immediately; tap View Camera → opens a camera stream; tap Call Family → initiates a phone call.

WebSocket vs Polling

The HA Companion App uses a long-lived WebSocket connection — state updates in <100ms latency. Compare this to HTTP polling every 30 seconds. The result is a dashboard that shows real-time status as if you were standing in the room.

Questions & answers

How is Cloudflare Tunnel more secure than port forwarding?
Port forwarding opens a router port directly to the internet, exposing it to bot scanning and attacks. Cloudflare Tunnel connects outbound only — no ports are opened on the router. Adding a Cloudflare Access OTP policy further requires authentication before the URL can be reached: true Zero-Trust architecture.
How does iOS Critical Alert differ from a standard notification?
Standard notifications are silenced in Do Not Disturb mode. Critical Alerts require special Apple permission and play at full volume even in silent mode — appropriate for genuine emergencies such as a gas leak or elderly fall detection.
Does geofencing in the HA Companion App use GPS or Wi-Fi?
Both — GPS for outdoor location and Wi-Fi SSID detection when at home (recognising the home network name). This combination is more accurate and uses less battery than GPS alone.
What is an actionable notification in Home Assistant?
A notification that includes action buttons the user can tap directly from the banner without opening the app. For example, HA notifies that the front door is open; tapping the Close Door button sends the command immediately.

Related reading