home_assistant 2.0.0 copy "home_assistant: ^2.0.0" to clipboard
home_assistant: ^2.0.0 copied to clipboard

A Dart library for interacting with Home Assistant APIs.

example/home_assistant_example.dart

import 'package:home_assistant/home_assistant.dart';

void main() {
  // Initialize Home Assistant
  final HomeAssistant homeAssistant = HomeAssistant(
    baseUrl: 'http://example.com',
    bearerToken: 'your_token',
  );
  fetchData(homeAssistant);
}

fetchData(HomeAssistant homeAssistant) async {
  print("The API is working: ${await homeAssistant.verifyApiIsWorking()}");

  final Configuration config = await homeAssistant.fetchConfig();
  print(config.toJson());

  final List<Entity> entities = await homeAssistant.fetchStates();
  print(entities.first.entityId);

  final Entity entity = await homeAssistant.fetchState(entities.first.entityId);
  print(entity.entityId);

  final List<Service> services = await homeAssistant.fetchServices();
  print(services.first.domain);

  homeAssistant.executeService(
    "switch.ceiling_lights_socket_1",
    "turn_on",
    additionalActions: {},
  );
  homeAssistant.executeService(
    "light.bedside_lamp_mercury",
    "turn_on",
    additionalActions: {
      "brightness": 255,
      "color_temp": 400,
    },
  );

  await Future.delayed(const Duration(seconds: 1));

  homeAssistant.executeService(
    "switch.ceiling_lights_socket_1",
    "turn_off",
    additionalActions: {},
  );
  homeAssistant.executeService(
    "light.bedside_lamp_mercury",
    "turn_off",
    additionalActions: {},
  );

  await Future.delayed(const Duration(seconds: 1));
}
14
likes
150
points
62
downloads

Publisher

verified publisherpraharshbhatt.com

Weekly Downloads

A Dart library for interacting with Home Assistant APIs.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

http, json_annotation

More

Packages that depend on home_assistant