https://github.com/wpernath/light-control
Quarkus demo project to control hue lights with several hue bridges
https://github.com/wpernath/light-control
Last synced: about 2 months ago
JSON representation
Quarkus demo project to control hue lights with several hue bridges
- Host: GitHub
- URL: https://github.com/wpernath/light-control
- Owner: wpernath
- Created: 2021-12-25T07:40:58.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-22T19:01:46.000Z (about 3 years ago)
- Last Synced: 2025-01-27T09:26:33.693Z (3 months ago)
- Language: Java
- Size: 592 KB
- Stars: 1
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# light-control
This is a simple Quarkus project which was originally planned and designed as a more advanced demo for the features of Quarkus: REST client, REST easy service, Qute, Panache, OpenShift and Image creation.
## Description
If you have more than one Hue Bridge in your Home Automation, you might now that you need to switch between bridges if you want to turn on/off lights in for example 1st floor and 2nd floor.This project can use several bridges and provides one big database with all rooms and lights in it. If you want to turn on/off a light or a room you don't have to worry about the bridge it belongs to.
light-control also comes with a simple UI
## API
All API calls are relative to `/api/` and are generated by `org.wanja.hue.PublicApiResource.java`## UI
All UI calls are relative to `/ui/` and are generated via Qute by `org.wanja.hue.render.PublicRenderResource.java`.The main qute template is `src/main/resources/templates/index.html`. It includes other content templates based on state (`favorites.html`, `room.html`). It also makes use of `javascript.txt` template.
## Build & Run
### Configure your `src/main/resources/application.properties`
Configure any number of Hue Bridges like:```
hue.bridges[n].name =
hue.bridges[n].base-url=http://192.168.2.126/api/
hue.bridges[n].auth-token=
```where `n` is between `0 and maxint`.
### Build & debug
In order to build this project, you need to have
- Maven
- Java 11
- Docker Desktop```bash
$> mvn clean quarkus:dev
```This builds the project and starts light-control in Quarkus Dev Mode.
### Build Container Image to run it on Kubernetes / OpenShift
This builds and pushes the container image into your registry.```bash
$> mvn package -Dquarkus.container-image.push=true \
-Dquarkus.container-image.image=quay.io//light-control:v1.0.3
```
**NOTE:** You could define any container-image.image here. And any docker-compliant registry. I am using Quay.io here.Quarkus is also generating Kubernetes / OpenShift files, which you can find in `target/kubernetes`. To run this on one of those Container platforms, simply execute the following:
```bash
$> kubectl apply -f target/kubernetes/[openshift|kubernetes].yml
```Please keep in mind that you first need to install a PostgreSQL database instance in the same namespace. Do this on for example OpenShift via:
```bash
$> oc new-app postgresql-persistent \
-p POSTGRESQL_USER= \
-p POSTGRESQL_PASSWORD= \
-p POSTGRESQL_DATABASE=lightsdb \
-p DATABASE_SERVICE_NAME=lightsserver
```But you could also install Crunchy's PostgreSQL Operator and install an instance from them.
And finally, you either need to change `application.properties` again and change the connection settings or you need to specify the following ENV variables to the Kubernetes Deployment:
- `DB_USER`
- `DB_PASSWORD`
- `DB_DATABASE`
- `DB_HOST`### Filling the database
Right now, light-control does not provide an UI interface to scan the database, so you have to do it manually by sending a POST request to `http:///api/bridge/init`. For example via `httpie`:```bash
$> http POST :8080/api/bridge/init
```This will fill the local database when you're running quarkus:dev.
## Running the UI
The UI is available under `http://localhost:8080/ui/index` and should be self explaining, although still a technical preview, as I am by far no front end designer.## Playing with the API
Everything is available via API. Starting URL is `/api`.- GET /api/bridge
- Consumes: application/json
- Produces: application/json
- DELETE /api/bridge/init
- Consumes: application/json
- Produces: application/json
- POST /api/bridge/init
- Consumes: application/json
- Produces: application/json
- GET /api/lights/q
- Consumes: application/json
- Produces: application/json
- PUT /api/lights/q
- Consumes: application/json
- Produces: application/json
- GET /api/lights/toggle
- Consumes: text/plain
- Produces: application/json
- GET /api/rooms
- Consumes: application/json
- Produces: application/json
- GET /api/rooms/q
- Consumes: application/json
- Produces: application/json
- PUT /api/rooms/q
- Consumes: application/json
- Produces: application/json
- GET /api/rooms/toggle
- Consumes: text/plain
- Produces: application/json
- GET /api/sensors
- Consumes: application/json
- Produces: application/json
- GET /api/sensors/{id}
- Consumes: application/json
- Produces: application/json