Exec persist seems not working at least with OH 2.5.4

Using latest openhabian ISO on a PI 4, I’m trying to persist items update through the exec persist solution but nothing happens.

Used configuration (/etc/openhab2/persistence/exec.persist) :

Strategies {
  everyMinute   : "0 * * * * ?"
  default = everyUpdate
}
Items {
  * -> "/etc/openhab2/persistence/exec-persist.sh \"%2$tY-%2$tm-%2$td %2$tT : %1$s\"" : strategy = everyUpdate
}

Run script command (/etc/openhab2/persistence/exec-persist.sh) :

 #!/bin/bash
echo $* >> /tmp/results.log

But I didn’t get anything, all access rights and file ownerships are well set, no errors or warnings in logs file; the exec.persist is well taken into account as shown in OpenHab logs :

2020-05-05 19:54:52.249 [vent.ItemStateChangedEvent] - TEMPERATURE_HUMIDITY_BAROMETRIC45569_Temperature changed from 18.1 to 18.0

2020-05-05 19:55:45.242 [vent.ItemStateChangedEvent] - TEMPERATURE_HUMIDITY_BAROMETRIC45569_Pressure changed from 998.0 to 999.0

==> /var/log/openhab2/openhab.log <==

2020-05-05 20:00:49.810 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'exec.persist'

2020-05-05 20:00:50.847 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'exec.persist'

==> /var/log/openhab2/events.log <==

2020-05-05 20:01:37.271 [vent.ItemStateChangedEvent] - TEMPERATURE_HUMIDITY64769_Humidity changed from 77 to 78

2020-05-05 20:02:49.236 [vent.ItemStateChangedEvent] - TEMPERATURE_HUMIDITY_BAROMETRIC45569_Humidity changed from 73 to 74

2020-05-05 20:03:34.274 [vent.ItemStateChangedEvent] - TEMPERATURE_HUMIDITY64769_Temperature changed from 17.6 to 17.5

Any idea why my script command is not executed ? A bug or did I miss something ?

regards,
David.

  • Platform information:
    • Hardware: Raspberry PI-4, 4Gb
    • OS: openhabian - openhabian-pi-raspbian-201908050414-gitca0976f-crc6a66b5a1.img
    • Java Runtime Environment: OpenJDK Runtime Environment (Zulu8.40.0.178-CA-linux_aarch32hf) (build 1.8.0_222-b178)
    • openHAB version: 2.5.4
  • Issue of the topic: Exec persistence seems not working
  • Please post configurations (if applicable):
    • Items configuration related to the issue
    • Sitemap configuration related to the issue
    • Rules code related to the issue
    • Services configuration related to the issue
  • If logs where generated please post these here using code fences:

In all the years I’ve been using OH and supporting it on this forum this is the first I’ve encountered anyone trying to use the Exec persistence. I have no idea whether or not it actually works, though I have no reason to believe it wouldn’t work. And unfortunately the docs leave much to be desired. As far as I can tell your .persist file is correct though.

Have you installed the Exec persistence addon? It might be the case that you need to also install the legacy Exec 1.x version addon as well. Some of the older niche addons like this have a dependency on a correctly installed and configured 1.x version binding. Usually that is documented in the readme but as you’ve seen, the readme for this particular addon is pretty spare.

Access writes and file ownerships for which user, openhabian or openhab?

Thanks, I’ve been able to select the “exec” persistency in paper UI configuration once the legacy addons package has been installed (apt-get install openhab2-addons-legacy)

but still nothing, I’m continuing to try to understand why. For information, I want to use the exec persistence service just to send items value changes to a Kafka server, and I thought it was quite an easy way to do it, … in theory.

Log4j2 has a Kafka appender. You should be able to configure the events logger to output straight to Kafka.

There is a whole host of things that could go wrong here. You need to narrow the problem down. Create a Rule that calls the script using executeCommandLine. This will tell you whether or not the problem is related to permissions.

thanks for the suggestion :

# cat debug.rules 

rule "exec persist debug"
when
  Item TEMPERATURE_HUMIDITY64769_Temperature received update
then
  executeCommandLine("/bin/sh /etc/openhab2/persistence/exec-persist.sh "+TEMPERATURE_HUMIDITY64769_Temperature.state)
end

so with a rule it run fine and I can get the item temperature in the results.log file, in the logs I get

2020-05-06 16:52:12.189 [vent.ItemStateChangedEvent] - TEMPERATURE_HUMIDITY64769_Temperature changed from 19.200000000000003 to 19.1
2020-05-06 16:52:12.297 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine '/bin/sh /etc/openhab2/persistence/exec-persist.sh 19.1'

Rules may become an interesting work around to my Exec persist issue, but it looks like the rule engine is quite more limited than the one I’m using almost everyday which is “drools”. But by using group (member of “group” trigger) I might be able to create 1 rule to trigger my command line for each sensors…

Or using Kafka log appender as you suggest :slight_smile:

Limited in what ways?

Also note that you have Python, JavaScript or Groovy available to you for writing Rules. There shouldn’t be anything that can be done with a computer that you can’t do with Rules.

But comparing relatively general purpose programming languages to a BRMS is really more of an apples to oranges comparison. OH Rules are not intended to address that problem space.

Indeed, you can use a Group and Member of Trigger to implement this. But don’t jump too far ahead. This was just an experiment to eliminate the root cause of the problem being that the openhab user was unable to execute the script for some reason. It was never intended to be an alternative solution. But if you are planning on using an alternative solution anyway that’s fine too.

1 Like

thanks for all your answers, it helps me to understand OH as I’m a new user :slight_smile: one last question, in which git repo/branch can I take a look if I want to help to fix the root issue ? I did some git clone on some repos and some find exec grep… but didn’t find any clue of where the exec persistence mechanism is implemented.
David.

We have to identify what’s actually the root issue first. At this point all we really know is that it isn’t that openHAB doesn’t have permission or is otherwise unable to execute the script. There can be a whole host of other problems including:

  • the add-on is simply broken
  • the add-on wasn’t actually installed or installed correctly
  • there is an undocumented dependency that’s not installed
  • there was a problem with the .persist file that isn’t being reported

There is a lot more that would need to be done to determine whether the problem is caused by configuration or by a bug.

The source code for this add-on is at openhab1-addons/bundles/persistence/org.openhab.persistence.exec at main · openhab/openhab1-addons · GitHub. But take note that this repo is closed. All of the persistence add-ons will either be rewritten or moved (probably to openhab-addons) at some point prior to OH 3 coming out. In OH 3, 1.x add-ons will no longer be supported.

If you were to spend the time messing with the code, I wonder if a native Kafka add-on would be a better use of your time.

1 Like

You didn’t say if that actually resulted in the data arriving at the remote service.
Just because the log said the command line wasexecuted doesn’t mean it did anything useful. If there was an error response, your rule chooses to ignore it.

data is well sent when using the rule

1 Like