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.
- Host: GitHub
- URL: https://github.com/koproductions-code/homeassistant_ws
- Owner: koproductions-code
- Created: 2024-07-23T18:01:05.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2025-01-11T21:57:59.000Z (over 1 year ago)
- Last Synced: 2025-06-08T15:48:12.840Z (about 1 year ago)
- Language: Dart
- Size: 23.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
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.