Building automations in Typescript with @digital-alchemy

New feature as part of April updates

The hass library has gained the ability to directly work with:

  • zones
  • floors
  • areas
  • labels

You can create, update, apply, remove, etc these across your system. There are also new quick querying APIs for quickly calling services using these groups. Optionally filtering by domain with.

export function Example({ hass }: TServiceParams) {
  const exampleSensor = hass.entity.byId("binary_sensor.example");
  exampleSensor.onUpdate(async () => {
    if (exampleSensor.state === "off") {
      await hass.call.switch.turn_off({
        entity_id: hass.entity.byArea("living_room", "switch"),
      });
      await hass.call.homeassistant.turn_off({
        entity_id: hass.entity.byFloor("downstairs")
      });
    } else {
      await hass.call.light.turn_on({
        entity_id: hass.entity.byLabel("my_special_label", "light"),
      });
    }
  });
}

Just like with entities, all your labels / areas / etc will have typescript suggestions & validations right in the editor.

1 Like