An open API service indexing awesome lists of open source software.

https://github.com/koproductions-code/homeassistant_ws

A dart package for interacting with HomeAssistant using WebSocket.
https://github.com/koproductions-code/homeassistant_ws

Last synced: about 1 year ago
JSON representation

A dart package for interacting with HomeAssistant using WebSocket.

Awesome Lists containing this project

README

          

# homeassistant_ws
This package provides an interface to communicate with HomeAssistant using the websocket protocol. In addition, it provides a way to integrate this interface into flutter applications using [provider](https://pub.dev/packages/provider)

## Features
- Listen for state changes for specific HomeAssistant entities.
- Integrate into flutter widgets using the provider package.

## Getting started

### Dependencies:
```dart
provider: ^6.1.2
```

## Usage

### Usage with Flutter
```dart
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:homeassistant_ws/flutter/homeassistant_ws_flutter.dart'; // <-- If you want to use the flutter functionality, you need to import this subpackage.

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: HomeAssistantBuilder(
host: "homeassistant.koproductions.dev",
port: 443,
entities: ["[Your Entity IDs]"],
child: EntityWidget(
entityId: "[EntityID]",
)));
}
}

class EntityWidget extends StatefulWidget {
final String entityId;

const EntityWidget({super.key, required this.entityId});

@override
EntityWidgetState createState() => EntityWidgetState();
}

class EntityWidgetState extends State {
String state = "unknown";

@override
void didChangeDependencies() {
super.didChangeDependencies();
final provider = Provider.of(context);

provider.socket?.subscribe(widget.entityId, update);
}

void update(HAEntityState data) {
setState(() {
state = data.state;
});
}

@override
Widget build(BuildContext context) {
return Text(state);
}
}

```

## Credits
Thanks to

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.