Skip to content

Claw!

Choose a tag to compare

@knoop7 knoop7 released this 29 May 08:20
· 18 commits to main since this release

  ┌────────────┐      ┌────────────┐      ┌────────────┐
  │ HTML Card  │─────▶│  claw API  │─────▶│    Home    │
  │  Content   │      │  Runtime   │      │ Assistant  │
  └────────────┘      └─────┬──────┘      └────────────┘
                            │
        ┌───────────────────┼───────────────────┐
        ▼                   ▼                   ▼
  ┌──────────┐        ┌──────────┐        ┌──────────┐
  │  claw.*  │        │ claw.ws  │        │ claw.api │
  │  state   │        │  send    │        │   get    │
  │  toggle  │        │  call    │        │   post   │
  └──────────┘        └──────────┘        └──────────┘
        │                   │                   │
        └───────────────────┴───────────────────┘
                            │
  ┌─────────────────────────┴─────────────────────────┐
  │              DOMAIN-SPECIFIC APIs                 │
  ├──────────┬──────────┬──────────┬──────────┬───────┤
  │ .config  │ .areas   │ .devices │.entities │.scenes│
  │ .scripts │.automations│.lovelace│ .system │.users │
  └──────────┴──────────┴──────────┴──────────┴───────┘


CORE METHODS

claw.hass() Get hass object
claw.state(entityId) Get entity state object
claw.states(filter?) Get filtered states (string/regex/fn)
claw.callService(domain, svc, data) Call HA service
claw.toggle(entityId) Smart toggle (on↔off)
claw.press(entityId) Smart press (button/scene/script)
claw.navigate(path) Navigate to path
claw.moreInfo(entityId) Open more-info dialog
claw.fire(type, detail) Fire custom event
claw.wait(ms) Promise-based delay

DOM UTILITIES

claw.el(tag, attrs, parent) Create element with attributes
claw.remove(idOrEl) Remove element
claw.inject(css) Inject CSS, returns {remove()}
claw.deepQuery(selector) Query across shadow DOM
claw.deepQueryAll(selector) Query all across shadow DOM

WEBSOCKET API (claw.ws)

claw.ws.send(msg) Send message (no response)
claw.ws.call(msg) Send and await response
claw.ws.subscribe(eventType, cb) Subscribe to event type
claw.ws.subscribeMessage(msg, cb) Subscribe with message filter

HTTP API (claw.api)

claw.api.get(path) GET request with auth
claw.api.post(path, data) POST request with auth
claw.api.put(path, data) PUT request with auth
claw.api.delete(path) DELETE request with auth
claw.api.fetch(path, init) Raw fetch with auth

TYPESCRIPT API (claw.ts) [NEW v3.7]

claw.ts.load() Load TS compiler
claw.ts.transpile(code, options) Transpile to JS
claw.ts.run(code, scope) Run TS with scope
claw.ts.card(code, ctx) Run in card context
claw.ts.module(code, scope) Run as ES module

CONFIG ENTRIES (claw.config)

claw.config.entries(params) Get all config entries
claw.config.entry(entryId) Get single entry
claw.config.update(entryId, params) Update entry
claw.config.delete(entryId) Delete entry
claw.config.reload(entryId) Reload entry
claw.config.disable(entryId) Disable entry
claw.config.enable(entryId) Enable entry
claw.config.subscribe(cb) Subscribe to changes

Config Flow:
claw.config.flow.create(handler) Start config flow
claw.config.flow.get(flowId) Get flow state
claw.config.flow.submit(flowId, d) Submit flow step
claw.config.flow.delete(flowId) Abort flow
claw.config.flow.progress() Get flows in progress
claw.config.flow.subscribe(cb) Subscribe to flow events

Options Flow:
claw.config.options.dialog(entryId) Open options dialog
claw.config.options.read(entryId) Read current options
claw.config.options.update(id, d) Update options

REGISTRIES

Areas:
claw.areas.get() Get all areas
claw.areas.create(name, opts) Create area
claw.areas.update(areaId, opts) Update area
claw.areas.delete(areaId) Delete area

Devices:
claw.devices.get(params) Get devices
claw.devices.update(deviceId, opts) Update device

Entities:
claw.entities.get(params) Get entity registry
claw.entities.getEntry(entityId) Get single entity entry
claw.entities.update(entityId, o) Update entity
claw.entities.remove(entityId) Remove entity

AUTOMATIONS (claw.automations)

claw.automations.get() Get all automations
claw.automations.getById(id) Get single automation
claw.automations.create(config) Create automation
claw.automations.update(id, config) Update automation
claw.automations.delete(id) Delete automation
claw.automations.trigger(entityId) Trigger automation

SCRIPTS (claw.scripts)

claw.scripts.get() Get all scripts
claw.scripts.getById(id) Get single script
claw.scripts.create(config) Create script
claw.scripts.update(id, config) Update script
claw.scripts.delete(id) Delete script
claw.scripts.run(entityId, vars) Run script with variables

SCENES (claw.scenes)

claw.scenes.get() Get all scenes
claw.scenes.create(config) Create scene
claw.scenes.update(id, config) Update scene
claw.scenes.delete(id) Delete scene
claw.scenes.activate(entityId) Activate scene

LOVELACE (claw.lovelace)

claw.lovelace.getConfig() Get dashboard config
claw.lovelace.saveConfig(config) Save dashboard config
claw.lovelace.getDashboards() Get all dashboards
claw.lovelace.createDashboard(o) Create dashboard
claw.lovelace.updateDashboard(id,o) Update dashboard
claw.lovelace.deleteDashboard(id) Delete dashboard
claw.lovelace.getResources() Get resources
claw.lovelace.createResource(opts) Create resource
claw.lovelace.updateResource(id,o) Update resource
claw.lovelace.deleteResource(id) Delete resource

SYSTEM (claw.system)

claw.system.info() Get system info
claw.system.restart() Restart Home Assistant
claw.system.stop() Stop Home Assistant
claw.system.checkConfig() Check configuration
claw.system.reloadCore() Reload core config

USERS (claw.users)

claw.users.list() List all users
claw.users.current() Get current user

UI UTILITIES (claw.ui)

claw.ui.main() Get home-assistant-main
claw.ui.sidebar() Get ha-sidebar
claw.ui.drawer() Get ha-drawer
claw.ui.appLayout() Get ha-app-layout
claw.ui.toolbar() Get app-toolbar
claw.ui.panel() Get current panel

SIDEBAR (claw.sidebar)

claw.sidebar.toggle() Toggle sidebar
claw.sidebar.show() Show sidebar
claw.sidebar.hide() Hide sidebar
claw.sidebar.isNarrow() Check if narrow mode

HOOKS (claw.hook)

claw.hook.hass(callback) Hook hass object changes
claw.hook.element(tagName, cb) Hook custom element registration

// Toggle light with TypeScript
<script type="text/typescript">
  const light = claw.state("light.living_room");
  if (light.state === "on") {
    claw.callService("light", "turn_off", { entity_id: "light.living_room" });
  }
</script>

// Subscribe to state changes
<script>
  claw.hook.hass((hass, oldHass) => {
    const temp = hass.states["sensor.temperature"];
    console.log("Temperature:", temp.state);
  });
</script>

// Create automation via API
<script>
  await claw.automations.create({
    alias: "Morning Lights",
    trigger: [{ platform: "time", at: "07:00:00" }],
    action: [{ service: "light.turn_on", target: { entity_id: "light.bedroom" }}]
  });
</script>

// WebSocket subscription
<script>
  claw.ws.subscribe("state_changed", (event) => {
    console.log("Entity changed:", event.data.entity_id);
  });
</script>

// HTTP API call
<script>
  const info = await claw.api.get("config");
  console.log("HA Version:", info.version);
</script>

Full Changelog: v3.6.2...v3.7