Skip to content

Home Assistant Integration

Ravi Singh edited this page May 7, 2026 · 1 revision

Home Assistant integration

AmbiSense v6.2.0-alpha.2 and later speak the SmartGhar device protocol — a local-push, mDNS-discovered contract shared across the Techposts IoT product family (AmbiSense, TankSync, future products like RidgeSync). Install one HA custom integration and every Techposts device on your network appears automatically.


⚡ TL;DR

  1. Flash AmbiSense v6.2.0-alpha.2 or later.
  2. Install the SmartGhar HA custom integration via HACS (custom repository, category Integration).
  3. Restart Home Assistant. Your AmbiSense device shows up in Settings → Devices & Services under "Discovered" — click Configure.
  4. Done. No broker, no YAML, no per-device setup.

You'll get this device in HA:

Entity What it shows
binary_sensor.<host>_occupancy on / off — the headline occupancy state. Stationary, target_count, nearest_cm, seconds_since_seen ride as attributes for fancy automations.
sensor.<host>_distance nearest target distance in cm (device class: distance)
sensor.<host>_target_count how many people the radar sees
sensor.<host>_seconds_since_seen vacancy timer (diagnostic)
sensor.<host>_uptime, sensor.<host>_wifi_signal, sensor.<host>_firmware_version hub diagnostics
binary_sensor.<host>_firmware_update_available OTA notification

How it works (under the hood)

Discovery

AmbiSense advertises on _smartghar._tcp.local. zeroconf with TXT records:

hub_id        ambisense_d83bda3506f0   ← unique per device, derived from MAC
product       ambisense
manufacturer  SmartGhar
schema        1.0
path          /api/v1/info

The integration's config_flow listens for that service type, reads hub_id for stable identity across HA restarts, and offers the device as a discovery in your HA inbox.

Real-time data

Once added, the integration:

  • Polls /api/v1/info + /api/v1/devices every 30 seconds for the slow-moving fields (uptime, firmware version, etc.)
  • (Future v6.2.0-alpha.3+) Subscribes to /api/v1/stream WebSocket for ~3 second push snapshots — real-time occupancy without polling lag.
  • Until the WS lands, falls back gracefully to polling — sub-30-second occupancy lag during the alpha window only.

Multiple AmbiSense units

Each device's hub_id is unique per MAC, so you can have as many AmbiSense units as you want on one network — they'll all auto-discover, each becoming its own HA device with its own entity set. No conflicts, no manual configuration.

Same applies if you mix AmbiSense + TankSync: one integration, two product types, distinct devices in HA.


Example automations

Hallway lights follow you (HA-side instead of LED engine)

automation:
  - alias: Hallway lights on when occupied
    trigger:
      - platform: state
        entity_id: binary_sensor.ambisense_06f0_occupancy
        from: 'off'
        to: 'on'
    action:
      - service: light.turn_on
        target:
          entity_id: light.hallway

  - alias: Hallway lights off after vacancy
    trigger:
      - platform: state
        entity_id: binary_sensor.ambisense_06f0_occupancy
        from: 'on'
        to: 'off'
        for: "00:00:30"
    action:
      - service: light.turn_off
        target:
          entity_id: light.hallway

Couch reading mode

automation:
  - alias: Couch occupied + stationary → reading lamp on
    trigger:
      - platform: template
        value_template: >-
          {{ is_state('binary_sensor.livingroom_occupancy', 'on') and
             state_attr('binary_sensor.livingroom_occupancy', 'stationary') }}
        for: "00:01:00"
    action:
      - service: light.turn_on
        target:
          entity_id: light.reading_lamp

(LD2410C-equipped AmbiSense units handle stationary detection more reliably than LD2450 — see Choosing LD2450 vs LD2410C.)

Vacancy alert after long idle

automation:
  - alias: Notify if room has been vacant > 6h during day
    trigger:
      - platform: numeric_state
        entity_id: sensor.ambisense_06f0_seconds_since_seen
        above: 21600
    condition:
      - condition: time
        after: "08:00:00"
        before: "20:00:00"
    action:
      - service: notify.mobile_app
        data:
          message: "Living room hasn't seen anyone in 6+ hours"

Without the SmartGhar integration

Three fallback paths if you can't (or won't) install the custom integration:

1. RESTful sensor (HA core, no custom integration)

# configuration.yaml
binary_sensor:
  - platform: rest
    resource: http://ambisense-XXXX.local/api/presence
    name: AmbiSense Presence
    value_template: "{{ value_json.occupied }}"
    payload_on: "true"
    payload_off: "false"
    scan_interval: 5

sensor:
  - platform: rest
    resource: http://ambisense-XXXX.local/api/presence
    name: AmbiSense Distance
    value_template: "{{ value_json.nearest_cm }}"
    unit_of_measurement: cm
    scan_interval: 5

The Presence tab in the device's web UI auto-fills this YAML with your hostname — open it, copy/paste into configuration.yaml. Polling at 5 s scan_interval; less responsive than the integration's push but works without any installation step.

2. Direct WebSocket from a Node-RED flow

ws://<host>.local/api/live

Pushes 20 Hz live state including occupied, count, stationary, nearest_cm, seconds_since_seen. Drop into a Node-RED websocket in node, parse the JSON, route to whatever automation engine you like. Same data the web UI's Live tab uses.

3. Polling /api/presence from your own script

curl -s http://ambisense-XXXX.local/api/presence

Returns {occupied, target_count, stationary, nearest_cm, vacancy_secs, seconds_since_seen}. Plain HTTP GET; works from anything.


Troubleshooting

My AmbiSense doesn't show up in HA

  1. Confirm the device is on your home Wi-Fi (not still in AP mode). Check the Live tab on the device's web UI — RSSI should show a real value.
  2. Confirm you're on v6.2.0-alpha.2 or later. System tab → About → Version. Older firmware doesn't speak the SmartGhar protocol.
  3. Confirm zeroconf is working on your network. Some routers (especially mesh routers with "device isolation" enabled) block mDNS. Try pinging <host>.local from a machine on the same network — if that fails, mDNS is broken.
  4. In HA: Settings → System → Logs, filter for smartghar. The integration logs every discovery attempt.

The device shows up but no presence entities

You're probably on smartghar-homeassistant < v0.7.0. The PR adding presence support is at https://github.com/Techposts/smartghar-homeassistant/pull/1. Update the integration via HACS.

Multiple devices, only one shows

Each AmbiSense MUST have a unique MAC (they always do — every ESP32 ships with a unique factory MAC). If you've cloned an SDK config that hardcodes a MAC, that's the only way they'd collide. Verify with idf.py -p /dev/cu.usbmodem... monitor — the boot log prints the MAC.

Entities show "Unavailable" intermittently

Most likely Wi-Fi: the AmbiSense dropped briefly. Check sensor.<host>_wifi_signal — if RSSI is below -75 dBm, move closer to your router or add a mesh node. The integration marks entities unavailable if /api/v1/info polling fails twice in a row.


Spec for tinkerers

The full wire contract is documented in docs/SMARTGHAR-PROTOCOL.md on the AmbiSense repo. It's the same spec every Techposts product implements — so if you ever want to write a custom dashboard or talk to AmbiSense from a non-HA system, that's the doc.

Quick reference of the AmbiSense-specific endpoints:

Endpoint Method Purpose
/api/v1/info GET Hub identity + diagnostics
/api/v1/devices GET Sub-device list (one entry, kind: "presence")
/api/v1/devices/0 PUT Config write (vacancy_secs, radar_kind)
/api/v1/hub/identify POST Flash status LED for ~3 s
/api/v1/hub/reboot POST Soft reboot
/api/live WS 20 Hz live state push (web UI uses this)
/api/presence GET One-shot presence snapshot (RESTful sensor friendly)

See also

Clone this wiki locally