d0ugal / hassio-dropbox-upload

Hass.io Dropbox Uploader
Apache License 2.0
39 stars 6 forks source link

Addon is checking every hour, fixed time or with a trigger possible? #46

Open Imperial-Guard opened 5 years ago

Imperial-Guard commented 5 years ago

Now my add-on is checking every hour. But would it be a possible to set a trigger or on a fixed time?

I make every night my backup, so for e.g. would be great to execute my upload a hour later.

d0ugal commented 5 years ago

Yeah, I think we need to change how this works. It is a little tricky.

Really I want the addon to run, backup the snapshots and stop. Then your automation would just start the backup after the snapshot is created. The problem is, you can trigger a snapshot but you don't know when it is ready. I can see three ways to handle this.

  1. In your automation you guess how long the snapshot will take to generate. So then it looks like... 1.1. Create snapshot 1.2. Wait for X minutes 1.3. Start snapshot backup

  2. The addon starts and waits for a new snapshot to be added. Once it finds one and upload it then it stops. Then the automation looks like this: 2.1 Create snapshot 2.2 Start addon. It will say something like "INFO: Waiting for new snapshot...." then it will upload it and then exit.

  3. Add a new event to HASS.io that happens when the snapshot creation is finished. We can then use that to start the addon. The automation then looks like... 3.1 Create snapshot 3.2 HASS.io finishes creating the snapshot and triggers event "snapshot_creation_finished" (or similar) 3.3 Second automation is triggered by this event and starts the backup addon.

I think option three is best, but that requires a change in HASS.io. Then option two and I think option one is worst :)

Either way, all of these options would be more efficient than the current approach of checking every X minutes all day long.

Imperial-Guard commented 5 years ago

@d0ugal Thanks for your quick reply and off course for creating this add-on.

I understand what you're saying. What do you recommend for time to check? And did you noticed any performance issues?

d0ugal commented 5 years ago

What do you recommend for time to check?

Do you mean how long should it check between uploads? I use hourly. If there is nothing to upload it is very quick and finishes fast

And did you noticed any performance issues?

I have not noticed any but I run HA on a fairly powerful server (not a pi).

d0ugal commented 5 years ago

I opened a HASS.io issue. Maybe we can look into adding the event there which would be nice. https://github.com/home-assistant/hassio/issues/839

dawiyo commented 5 years ago

Here's a solution I've been using. I have mins_between_backups set to 1500 which is 25 hours. I then use hassio.addon_restart to restart the plugin which manually triggers a backup.

d0ugal commented 5 years ago

@dawiyo That works, the downside is that the addon is still running and waiting to backup - wasting a small bit of resources.

dawiyo commented 5 years ago

@dawiyo That works, the downside is that the addon is still running and waiting to backup - wasting a small bit of resources.

I guess I could do hassio.snapshot_full, 10 min delay, hassio.addon_start, 10 min delay, hassio.addon_stop. It's hacky but might work.

d0ugal commented 5 years ago

Yup, that would do it!

I think adding an option to stop the add on after uploading would be a decent solution.