diff --git a/README.md b/README.md index 2e4c486..1ece0e6 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Please read volume persistent requirements: - **Do not run docker/docker-compose as root, app will exit!!** **As docker best practice, add your user to docker group instead with `usermod -a -G docker `** -- **Make sure default userid(1000) is a system valid id with read/write permission on persistent volumes, if not change `USER_UID` env var on docker-compose.yml** +- **Make sure default userid(1000) is a system valid id with read/write permission on persistent volumes, if not change `USER_UID` env var on docker-compose.yml** **On linux run command `id` to get your user id**
Before you can start using this tool you might want to test locally with [docker-compose](https://docs.docker.com/compose/install/). @@ -216,10 +216,10 @@ You can decide how many events logs you want to keep with *MAX_LOG_EVENTS* var, Why? Just because it's cool :-) I use home assistant for a lot of stuff so I wanted to have unicloud as entities on HA. I didn't have time so far to create a real integration, maybe I will consider it for the future if useful. -As for now client/server/shares infos are published at a custom interval (HOME_ASSITANT_PUSH_INTERVAL). +As for now client/server/shares infos are published at a custom interval (HOME_ASSITANT_PUSH_INTERVAL). +Clients have also binary_sensors for replica sync status (InSync/OutOfSync). Configuration is simple, make sure you have a token and fillup all 4 HOME_ASSISTANT_* ENV VARS. - This is the result on home assistant.
diff --git a/app/scheduler_tasks.py b/app/scheduler_tasks.py index 62a03a3..64d30c6 100644 --- a/app/scheduler_tasks.py +++ b/app/scheduler_tasks.py @@ -24,8 +24,8 @@ def scheduler_tasks_update_sync_status(app): c_status.update_sync_status(sync_status) -def scheduler_tasks_home_assistant_post(sensor_name, data): - url = f"{home_assistant_url}/api/states/sensor.unicloud_{sensor_name}" +def scheduler_tasks_home_assistant_post(sensor_name, data, domain="sensor"): + url = f"{home_assistant_url}/api/states/{domain}.unicloud_{sensor_name}" headers = { 'Authorization': f'Bearer {home_assistant_token}', 'content-type': 'application/json', @@ -67,6 +67,12 @@ def scheduler_tasks_update_home_assistant_clients(app): "Sync_Ok": client_info['ok'], "Sync_Ko": client_info['ko'], "Sync_Threshold": client_info['threshold'], "Sync_Total": client_info['total']}} scheduler_tasks_home_assistant_post(sensor_name, data) + if sync_status == "In Sync": + binary_status = "off" + else: + binary_status = "on" + data = {f"state": binary_status, "attributes": {"device_class": "problem"}} + scheduler_tasks_home_assistant_post(sensor_name, data, "binary_sensor") def scheduler_tasks_update_home_assistant_shares(app):