rstrouse / ESPSomfy-RTS-HA

Control your somfy shades in Home Assistant
The Unlicense
125 stars 9 forks source link

Include data from ESPSomfy RTS in Home Assistant backups #33

Closed weisserd closed 8 months ago

weisserd commented 8 months ago

It would be nice to easily integrate the backup of the configuration of the ESPSomfy RTS controllers in the central home assistant backup.

Currently I have to backup every controller on its own and it would be very convenient if this were integrated in the Home Assistant backup process.

I already tried to find the relevant information (e.g. remote address, timings, last rolling code) somewehere in Home Assistant (e.g. the home-assistant_v2.db), but I was not able to locate it. I was just able to see the according entities and eventes being sent/processed but no config values: image

rstrouse commented 8 months ago

Currently these are written to the homeassistant directory. I cannot find any documentation regarding how to write the backups but will do some more research.

weisserd commented 8 months ago

In which directory exactly? Then I might assist - There are different backup solutions for Home Assistant?

rstrouse commented 8 months ago

It is the directory named homeassistant on my both my systems.

weisserd commented 8 months ago

Is that somewhere underneath the standard directory structure?

image

rstrouse commented 8 months ago

It is in the same location as the log and the configuration.yaml on my production and dev systems. Note the two ESPSomfy RTS files. These are generated when the firmware is installed from HA. There is no guidance that I have found for persisting data to the platform outside of the config.

image

weisserd commented 8 months ago

Ok, so this is the config folder - However I don't have any ESPSomfy file there. But I have not installed the firmware from HA and there was also no update (yet) triggered from HA.

So the folder is correct and will be included in backups.

Probably I have to wait for the first update triggered from within HA.

rstrouse commented 8 months ago

Yeah I have a pre-release of 2.3.1 so when I get this finalized it will show up as a firmware update. During this process it will write the file. Maybe I can figure out how to add a backup task to the device maybe I just need to add a service then you can do it from an automation.

weisserd commented 8 months ago

That would probably be the best solution. To expose a service that triggers the backup of each ESPSomfy RTS device and stores it in the HomeAssistant folder.

rstrouse commented 8 months ago

I will add that service in the next release. All I need to figure out is how to target the device not the entity.

weisserd commented 8 months ago

II think this falls under the category of a device action - https://developers.home-assistant.io/docs/device_automation_action

A simple example that I found would probably be here: https://github.com/home-assistant/core/blob/dev/homeassistant/components/adguard/__init__.py

rstrouse commented 8 months ago

Thanks I will have to take a deep dive into this. I suppose this might be the place to add reboot, restore, and backup.

rstrouse commented 8 months ago

As it turns out these device actions always resolve to an entity. All they appear to do is add the service for all entities on the device. I now understand what they are doing which is why I need to have an update entity to update the device.

So I will look at adding a backup entity to it but there is no base object in Home Assistant for a backup entity other than the one defined to backup the system. No chance of using that as it appears to be protected by dragons.

rstrouse commented 8 months ago

Ok so I got the backup and restore services working. I will post v2.3.1 of the integration in the next day or so. I also added button entities (because you really cannot have a service without an entity) for backup and reboot. I still cannot figure out how to create a restore entity.

I also moved the backup files to a location under the config directory for those folks that have more than one device (hub). That way when I figure out how to add a dropdown and button entity in one I can create the restore function. I can only imagine that it is probably a flow initiated by a button press.

rstrouse commented 8 months ago

v2.3.1 of the integration has been released. It contains the reboot and backup functions discussed.

weisserd commented 8 months ago

Thank you very much. I'll check the coming weekend.

weisserd commented 8 months ago

I was able to trigger the backup service but I was not able to then find a file (e.g. in the config folder)

image

rstrouse commented 8 months ago

These are in a subdirectory under the config directory. You will find them in ESPSomfyRTS_<chipid for the esp> in a file with the extension .backup

rstrouse commented 8 months ago

Also select the backup entity as selecting the device is not correct since HA requires an entity for operations such as this.

weisserd commented 8 months ago

Thanks for implementation and clarification. That worked flawlessly: image