Finally home to OH - now how to organize filechanges / deployments etc?


(Marc) #1

hey,
i discovered OH a month ago and was able do build a basic automation for my lights and rollershutter (audio still in progress). a few questions here:

  1. while coding the templates and changing values (im using VS Code) in different setting-files (.items, .things etc) i ended up a little confused about versioning and organising uploads to my rasp3(where my OH server sits)
    atm. im changing files direct on the samba share. how do you guys set up your IDEs for OH

  2. if you are “finished”, ie. finished configuration, built nice panels and evrthing is working as it should. what do you do to ensure it stays this way after f.e. a power outage, how can i set up the persistence the right way?
    what do you guys do to backup your settings, and what files do you backup ?

thanks for your answers in advance,
markus


(anonymous.one) #2

I’ve found that my spouse is the largest variable and understand that my OH setup will never be a finished solution, I just have to keep modifying it to fit the new challenge dropped in my lap. I have found though within the rules to leverage a ‘//’ and setup a new line within the actions in case I need to roll back a bad idea or il-logic that seemed like logic at the time. :slight_smile:

Panels within habpanel should stay the same as they were after a power outage, I assume the BasicUI would re-read what you have in the sitemap.
As for persistence of items I have found mapdb to work for all of my needs, when you start hitting more complex hardware that provide more than simple ON/OFFs, I think that is when you have to look into a more SQL persistence configuration.


(Marc) #3

haha, i like that - same here.
i think a project like “automating your home” is never fnished, thus im looging for a a good way to move on my development to the next stage.
im no developer, but can ready and understand code (im learning fast tho). i just try to understand how the real “pro´s” are organizing theyr work on their smarthomes. im using " // " excessive in my docs to document my functions and procedures
thanks anyways - will have a closer look on the persistence concept of OH


(Vincent Regaud) #4

I have a text file in the root of the openHAB conf folder will all important setting and things to remember
One of these is:

Back up your set-up regularly:

**************************************
**              BACKUP              **
**************************************

Running this script will store all of the configurables made in paperUI or through textual configuration. It will attempt to backup the list of installed addons and bindings, and the settings for those bindings too.

cd $OPENHAB_HOME or cd /usr/share/openhab2
sudo ./runtime/bin/backup                            ## Creates a backup file in the default location with a timestamp.
sudo ./runtime/bin/backup /opt/backups/myconfig.zip  ## Creates a backup file in the specified location.
sudo ./runtime/bin/backup --help                     ## Brings up the help information

USE:
sudo ./runtime/bin/backup /etc/openhab2/backup.zip

The default path to store the zip files in is in $OPENHAB_HOME/backups/ (/var/lib/openhab2/backups for apt/yum users). You can change this default path by specifying the $OPENHAB_BACKUPS environment variable (again use /etc/default/openhab2 if you’re using apt/yum)

**************************************
**              RESTORE             **
**************************************

The restore script restores a zip file created using process above and uses it to completely replace your openHAB configuration. Any newer changes that weren’t in the backup get removed.

*Note: This will not backup the runtime folders. If you’re trying to repair openHAB, it’s best to download a new instance, and then try the restore script to load your configuration.

cd $OPENHAB_HOME
./runtime/bin/restore /opt/backups/myconfig.zip  ## Restores the openHAB config from the specified zipfile
./runtime/bin/restore --help                     ## Brings up the help information

(Mark) #5

VS Code integrates nicely with Git, which is a version control system. This allows you to maintain a history of changes to your openHAB config files. There also are VS Code extensions that allow you to view the history of changes.

You can read more about it here.


(Rich Koshak) #6

I edit direct on my production OH. I’ve designed my home automation such that if OH goes down or has problems, the house still works. Lights can still be turned on and off, the heat still comes on, etc. Just some of the automations will stop working. So for me the risk of messing up my production OH is really low.

I do use git to source control my configs though and any time I complete building something I check it in with appropriate comments. I can then see the history of changes and go back and see old versions of files and such.

I’m currently at a stage of my home automation where most of the changes I make are small or done through PaperUI so I don’t actually use VSCode that much right now.

No one is ever finished. :slight_smile:

But “the right way” is going to depend on what your requirements are. Does it make sense to restore ALL your Items to the state they had before OH went down? What if OH was down for a day or a week. Does that old value still make sense? If not then you should write your Rules to handle the fact that sometimes that Item can be NULL or UNDEF.

If it does make sense, then the general recommendation is to use MapDB for restoreOnStartup as it will be the fastest and will never grow since it only saves the last value. See Design Pattern: Group Based Persistence.

Backup is handled all sorts of ways. If you are running openHABian then Amanda is highly recommended. If you are running on an SD card, many will periodically take images of their cards as a backup. If running on a VM then taking VM snapshots is a popular approach.

Personally, I use git and Ansible configs so when I need to rebuild my machine I just use Ansible to rebuild the machine and check out the latest versions of the configs from git.

For just the OH configs you need all of $OH_CONF (/etc/openhab2) and much of $OH_USERDATA (/var/lib/openhab2). If you have an installed OH as opposed to a manually installed OH, you can use sudo openhab-cli backup to generate a tar file containing a backup of all the configs in both folders. However, it is the rare home automation enthusiast who is only running OH. You need to make sure you backup the configs for all the services you use (Mosquitto, external databases, Grafana, etc). This is why SD card images, snapshots, and Amanda are recommended.

Well since you asked…

  • ESXi Type 1 Hypervisor running on a desktop form server
  • Ubuntu 18.04 Server VM to host all my home automation services (other VMs host other services like media, NAS, etc)
  • All services are run in Docker
  • All VMs are created and configured using Ansible
  • All configurations including the Ansible scripts are checked into a local git server
  • I have cron scripts that run periodically to export the contents of important databases for backup

I don’t worry about backing up the VMs themselves because I can quickly and easily rebuild them. So I only backup the minimum necessary which includes the configs (git) and the databases (cron jobs).

It works for me. But what lead me down this path is that I have a ton of other services I use that have nothing to do with home automation I’ve consolidated on this one machine. Most users’s local network is larger than just their home automation.


(Marc) #7

@vzorglub thanks for the idea. defntly worth thinking that over.
@mhilbush thanks for the hint, i already tried to set this up - problem i have is, that the editor on my win10 machine has obviously no permissions on my raspi

i tried in the vs code terminal:

PS Z:> git init
Z:/.git: Permission denied

@rlkoshak
thanks for your hints and tips, from your former posts and howto´s (which are great btw) i see you have a really holistic approach on this topic. i have to read your post a few times to really understand it correct :smiley:


(Lucky) #8

Where is your Z drive pointed to? A Samba/network share? I have my git on the \openhabianpi\openHAB-share\openhab2-conf location

It’s actually uploaded (pushed) to a remote repo for redundancy


(Marc) #9

@luckymallari
thanks - fixed it now, i initialized the git repo via network mapping in win10