Rules and Persistance Trigger

Nothing. Simply nothing don’t put anything related to this item in the .persist file the rule will persist when the pump is on every 5 minutes


is it true?


This is the code in the Rule file

The file Bar_G_Inlet.persist would never be taken into account the files persist have to be named based on the database used

Recap. The whole point of persistance is to define the strategies for when and under what condition item are stored in a database of choosing. Now your request demand that an item state is stored every 5 minutes while another item state is on Wich is what the rule is doing meaning you don’t need to define any strategy for persistance for that item you want to persist.

The rules goes in the folder rules with a .rules file extension

The persistance folder should not have anything in it related to that item as a strategy. Also you should have defined a default database for persistance in the webui or openhab conf file.

If any of this doesn’t make any sense I don’t know what further help can be provided to you unless you give out what have you done so far like post the .rules content the .persistance file also and more explanation

Perfect that is all you need and make sure the jdbc.persist doesn’t persist your Bar_G_Inlet.

homerules.txt (6.6 KB)
Bar_G_Inletpersist.txt (637 Bytes)
jdbcpersist.txt (6.3 KB)

I’m using OH4, how can I make a filter?

And here:

I don’t see any obvious problem also delete the Bar_G_Inlet.persist. What now you want filters but that will not help to only record when the pump is on ?

I’m sorry I couldn’t do it.

Can you help me if I give you anydesk?

What you cannot do ? Give more details.

This forum is not a help desk if that is what you need you are better off using a paid solution for what you are trying to do.

1 Like

couldn’t do what I explained, because I couldn’t see any examples. I am not a professional. We are rookies, there are many people like me.

I would also like to thank you for your interest and concern.

I understand you are a beginner I am trying to help you but anydesk is out of the question I am just a user like you a rookie. Explain what did not work with picture configuration logs etc. It’s also a learning experience for you and for others on the forum. If language is a barrier you can always use Google translate and post here the translation. But so far regarding your request you have receiving all the information needed to accomplish what you asked in the first post.

What I wanted in the first post was “I have two items below; How can I save the Inlet Bar values to the database when the Water Pump is On. I want it to not record when the Water Pump is Off.” I still didn’t get it.

Thank you very much. I know there are more professional people to help this program develop. But they avoid helping.

But that is exactly what that rule does.

Post openhab logs when the pump is on to see if the inlet bar is actually persisting every 5 minutes.

To make more more easy here here is a debug rule that will post a bunch of info in the logs of openhab.

rule "Persist Bar_G_Inlet When Water_Pump is ON"
    Time cron "0 */5 * * * ?"  // Removed extra '?' in cron expression causing problem ?
    // Logging to show the current state of Water_Pump
    logInfo("Debug", "Water_Pump state is: " + Water_Pump.state.toString)

    if (Water_Pump.state == ON) {
        // Logging to show the state of Bar_G_Inlet before persisting
        logInfo("Debug", "Bar_G_Inlet state before persisting: " + Bar_G_Inlet.state.toString)
        // Persist Bar_G_Inlet
        // Logging to confirm that Bar_G_Inlet has been persisted
        logInfo("Debug", "Bar_G_Inlet has been persisted.")
    } else {
        // Logging to show that the Water_Pump is OFF, so Bar_G_Inlet will not be persisted
        logInfo("Debug", "Water_Pump is OFF. Bar_G_Inlet will not be persisted.")

1 Like

Or if you don’t have a default persistance define do:


That is what the rule should do.
The rule will be triggered every 5 minutes.
During each execution ( every 5 minutes ) it checks if the pump is ON.
If it is ON it will persist a value.
If it is not ON nothing will be done.

/******************G A R D E N   R U L E S*********************************/
rule "Persist Bar_G_Inlet When Water_Pump is ON"
    Time cron "0 */5 * * ? * ?"
    if Water_Pump.state == ON {

The files you uploaded contain Windows line endings. So that may be a problem.
Have a look to the openhab.log file for error messages and or warnings.
That should give an information about if there is any problem.
A suggested add additional logging to see if the rule is called and if it would persist a value.

2023-09-09 15:50:00.565 [INFO ] [org.openhab.core.model.script.Debug ] - Water_Pump state is: ON

2023-09-09 15:50:00.569 [INFO ] [org.openhab.core.model.script.Debug ] - Bar_G_Inlet state before persisting: 0.54

2023-09-09 15:50:00.580 [INFO ] [org.openhab.core.model.script.Debug ] - Bar_G_Inlet has been persisted.

Thank you, that’s what I wanted. I am thankful to you.