Metadata-Version: 2.4
Name: candyhouse-sesame-cli
Version: 0.1.1
Summary: CLI for CANDY HOUSE Sesame smart locks via the public Web API
Project-URL: Homepage, https://github.com/valda/candyhouse-sesame-cli
Project-URL: Repository, https://github.com/valda/candyhouse-sesame-cli
Project-URL: Issues, https://github.com/valda/candyhouse-sesame-cli/issues
Author-email: YAMAGUCHI Seiji <valda@underscore.jp>
License: MIT License
        
        Copyright (c) 2026 YAMAGUCHI Seiji
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: candyhouse,cli,home-automation,sesame,smart-lock
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: End Users/Desktop
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Home Automation
Requires-Python: >=3.9
Requires-Dist: pycryptodome>=3.19
Description-Content-Type: text/markdown

# candyhouse-sesame-cli

A small CLI + Python library for controlling [CANDY HOUSE Sesame](https://candyhouse.co/) smart locks via the **public Web API** (`app.candyhouse.co/api/sesame2`).

## Scope

Works with any SesameOS2/OS3 smart lock that is reachable from the CANDY HOUSE cloud (i.e. paired with a WiFi Module 2 or a Sesame Hub 3).

- **Tested**: Sesame 4
- **Expected to work** (same API, same command codes, not yet verified): Sesame 3, 5, 5 Pro
- **Out of scope**: Matter-only flows (Sesame 5 Pro + Hub 3 via Matter local control), Sesame Touch / Bot / Bike-specific operations

If you have a Sesame 5 Pro + Hub 3, the Matter path is a better fit than this CLI — it runs locally with lower latency.

## Install

```sh
pipx install candyhouse-sesame-cli
```

Or directly from GitHub:

```sh
pipx install git+https://github.com/valda/candyhouse-sesame-cli.git
```

Requires Python 3.9 or newer. The only runtime dependency is [`pycryptodome`](https://pypi.org/project/pycryptodome/) for AES-CMAC signing.

## Credentials

Obtain the following three values from the [CANDY HOUSE business developer portal](https://biz.candyhouse.co/biz/developer):

- **API key** — per-account, unchanged between devices
- **Device UUID** — per-device (one Sesame = one UUID)
- **Device secret key** — per-device, 32-character hex string (AES-128 key)

Export them to the environment:

```sh
export SESAME_API_KEY="..."
export SESAME_UUID="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
export SESAME_SECRET_KEY="0123456789abcdef0123456789abcdef"
```

## Usage

```sh
$ sesame status
{"isRechargeBattery":0,"batteryPercentage":100,"batteryVoltage":6.116,"position":265,"CHSesame2Status":"locked","timestamp":1776966159,"wm2State":true}

$ sesame lock
{"statusCode":200}

$ sesame unlock
{"statusCode":200}

$ sesame toggle
{"statusCode":200}
```

A `200` response from `lock`/`unlock`/`toggle` only means the command was **accepted by the cloud** — it does not guarantee the physical lock moved. If the WM2 or Hub 3 is offline, the command is silently dropped. Always re-check `sesame status` a few seconds later to confirm.

## Use as a library

```python
from candyhouse_sesame import SesameClient

client = SesameClient(api_key="...", secret_key="...", device_uuid="...")
print(client.status())
client.command("lock")
```

## Integration with Home Assistant

You can wire this CLI into HA via `shell_command` + a template lock. Example `configuration.yaml`:

```yaml
command_line:
  - sensor:
      name: "Sesame Status"
      unique_id: sesame_status
      command: "sesame status"
      scan_interval: 30
      value_template: "{{ value_json.CHSesame2Status }}"
      json_attributes:
        - batteryPercentage
        - batteryVoltage
        - position

shell_command:
  sesame_lock: "sesame lock"
  sesame_unlock: "sesame unlock"

template:
  - lock:
      - name: "Sesame"
        unique_id: sesame_frontdoor
        lock:
          - action: shell_command.sesame_lock
        unlock:
          - action: shell_command.sesame_unlock
        optimistic: true
        state: "{{ is_state('sensor.sesame_status', 'locked') }}"
```

Pass `SESAME_API_KEY`, `SESAME_SECRET_KEY`, and `SESAME_UUID` into the HA container via Docker env.

## Disclaimer

This project uses the CANDY HOUSE public Web API. It is **not** affiliated with or endorsed by CANDY HOUSE, Inc. The API is used at your own risk; response shapes and command codes may change without notice.

## License

MIT. See [LICENSE](LICENSE).
