Skip to content

Commit

Permalink
Merge pull request #32 from agarbato/homeassistant
Browse files Browse the repository at this point in the history
Homeassistant
  • Loading branch information
agarbato authored Oct 17, 2022
2 parents ab26a3b + 4430938 commit fd08ef2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <your_username>`**

- **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**

<br>Before you can start using this tool you might want to test locally with [docker-compose](https://docs.docker.com/compose/install/).
Expand Down Expand Up @@ -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.

<br>
Expand Down
10 changes: 8 additions & 2 deletions app/scheduler_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit fd08ef2

Please sign in to comment.