Automatic return after power failure

Hi

I am running OH 4.2.0 on a Raspberry Pie. I live in the country where there are occasional power outages. I have a battery back up for the Pie, but it only lasts for a few hours, so if I am away for a few days, the Pie will have a power fail shut down. When this happens, the things such the power and water meters are accessible again and my rules continue to read values at regular times.

However, all the data contained in point variables such as times for irrigation zones, number of days between watering etc. is lost. I have the RRD4j persistence service enabled for charting different variables, but this historical data is also lost when the power fails. I think I remember reading that the persistence service only works if there is an orderly shut down of the server, not a power fail.

Is there any way of creating regular automatic saving of variables, with restoration on power return? This would seem like a basic function of a home automation system but I havn’t found it yet.

PJG

You should add an „every minute“ strategy to your persistence and change restoreOnStartup to be used with mapDB persistence. This service will persist any item state, whereas RRD4J persists numbers only.

Thank you for the reply. I did have mapDB persistence set up for the irrigation variables with restoreOnStartup. I have added every minute as you suggest, but the values are still not restored after the power fail. This the configuration in the UI. Is there any other global setting that I need to make this work?

Are you using openHABian with ZRAM enabled ?
If so, setup the zsync timer to run at regular intervals.I’ll sync the data from RAM to SD.

admin@mysmarthouse:~ $ systemctl list-timers zsync
NEXT                         LEFT     LAST                         PASSED  UNIT        ACTIVATES
Sat 2024-08-03 00:59:53 CEST 11h left Fri 2024-08-02 01:00:08 CEST 12h ago zsync.timer zsync.service

1 timers listed.
Pass --all to see loaded but inactive timers, too.

Thanks mstormi.

As far as I can tell, ZRAM has been enabled by default on all OpenHabian installations for some time now so I assume the update to version 4.2.0 would leave it enabled. If no data is being stored to the SD card, I can see why I loose all my data on a power fail. So I either turn off ZRAM and risk the problems with continuous SD card read/writes or try to sync the ZRAM data on a nightly or hourly basis.

I found your post on syncing ZRAM here

ZRAM nightly sync, openhab service restart - #11 by mstormi

However as I am not a UNIX person and the thread seems to full of warnings about system corruption, I don’t want to take the risk on my house system. Is there a simple step by step guide to how to set up the ZRAM sync with cron to do it?

PJG

if you have installed openHABian from scratch lately (rather than update you said) then a simple
systemctl enable --now zsync.service
should do

OK so I have used openhabian-config to create a backup of my system. Do I just use option 03-Install openHab to create a fresh install?

no that wasn’t the question.
if your setup is older and you want to reinstall you need to download and flash another SD after that you can import your config

I think it will be better to get a new Pie 4 with an Extreem SD card and build a separate system to test every thing out as I cannot risk problems with my house system. I can then disable the ZRAM during the setup process which should solve the problem, check it all out and then swop the system.

Thanks again for the suggestions.

PJG

You could use Network UPS Tools (NUT) to monitor the state of the UPS system if your system has a port that allows status monitoring.
It would allow you to orderly shutdown the PI prior to a loss of UPS power. That will preserve all persistent data.
I wrote a tutorial a while ago for OH2.5, [Guide to Network UPS Tools] (Guide to Network UPS Tools (NUT) on multiple Raspberry PI’s (Openhab 2.5 and other systems)). It’s a bit dated though the framework would be similar for more recent versions of OH. There’s another good tutorial at (Beginner's Guide to Network UPS Tools (NUT) on a Raspberry Pi) that has had more recent updates.

1 Like

Hello, @mstormi I know this is an older post, but having an issue enabling zsync.service. Running openhabian, openhab 4.2.2.

When I try to enable zsync.service with systemctl enable --now zsync.service, the response I get is:

The unit files have no installation config (WantedBy=, RequiredBy=, Also=,
Alias= settings in the \[Install\] section, and DefaultInstance= for template
units). This means they are not meant to be enabled using systemctl.

Possible reasons for having this kind of units are:
• A unit may be statically enabled by being symlinked from another unit’s
.wants/ or .requires/ directory.
• A unit’s purpose may be to act as a helper for some other unit which has
a requirement dependency on it.
• A unit may be started when needed via activation (socket, path, timer,
D-Bus, udev, scripted systemctl call, …).
• In case of template units, the unit is meant to be enabled with some
instance name specified.

I have searched for a solution, but unable to find the file changes necessary to enable the service.

A question like that to apply to some unknown-oldish-OS setup does not make sense to attempt answering so I won’t.
Flash a fresh openHABian.
And please refrain from pinging people, especially if the thread is ancient.