Help with RPI Openhab full hang. (WAS Rule for longest ever uptime?)

@vzorglub

I have installed it yes

I have just put the log in debug mode it is saying stuff about

got DecimalType value 24.61

got onoff type value 1

I have been using the frontail Web log and haven’t seen anything there or should I check somewhere else?

PLEASE NOTE

I’m not trying too be rude or short I’m just very tired I do actually appreciate the help from you all

InfluxDB is a whole separate thing from OH. rrd4j and mapdb are what are called embedded databases. They run inside of OH. InfluxDB is its own software with its own places to store data and such. It doesn’t store anything in the persistence folder of OH. It actually stores it’s data in /var/lib/influxdb/data. You should see an openhab_db folder in there. You can dig further but the folders and files and such will make no sense to you (or me for that matter).

It is accessible on localhost:8086 using InfluxDB’s protocol. That doesn’t mean it runs a webpage on that port. That is how OH talks to InfluxDB. The way you talk to InfluxDB is through the interface that you typed in the command to create the database and such previously.

So you can either run a query from that influx command prompt, see the InfluxDB docs for how to do that (I don’t know off the top of my head). Or you can run a query from the OH REST API under persistence. Just be sure to supply influxdb and your Item name for the /persistence/items/{itemname} endpoint.

If there are no errors it is either not installed, not configured, or working just fine. Since you installed the influxdb binding, configured an influxdb.persist file and influxdb.cfg file then it is probably working.

Rich

Thank you

I already knew some of that but the parts I didn’t have filled in alot of gaps mainly the way I talk too influx and the way oh does and where the files are stored

I could not have asked for a better explanation

I’m going too look in the location for the dB file you said

@rlkoshak

OK found the file openhab_dB does exist in the folder you said

Should I be able too use the rules posted above now

I would assume so.

I’m going too try later now I’m more refreshed

I have moved one of my timeline graphs over in habpannel seems too be working thanks for helping lastnight my brain was fried

I have changed my graphs and persistence from rrd4j and uninstalled rrd4j working fine not tried grafana yet although my graphs are already alot nicer now

But I have tried the rule posted above getting an error about NULL

2018-07-17 21:46:21.082 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Test Rule': An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.BusEvent.sendCommand(org.eclipse.smarthome.core.items.Item,java.lang.String) on instance: null

I have created the new item and added this too the influx persistence
Item

Number Longestuptime28days "Longest uptime in 28 days" <calander>

edited rule from above

rule "Test Rule"
when
    Item Systemuptime changed
then
    Longestuptime28days.sendCommand(Systemuptime.maximumSince(now.minusDays(28)))
end

persistence file shortened
is this setup right i wanted too persist items on changes only but my graphs didnt work when removing everyminute

Strategies {
    everyMinute : "0 * * * * ?"
}

Items {
    .......
    .......
    Longestuptime28days,
    Systemuptime,
    .......
    .......
    Ghouse_Light_Level : strategy = everyChange, everyMinute
}

IIRC, you would need a value from 28 days ago to do maximumSince(now.minusDays(28)). So, you will need to wait, or put an entry in the database with an appropriate date.

Hi again

Thanks for your help again

If that’s the case that’s perfectly fine i just thought it was wrong should i change it too something like 2 days too get a test result faster 28 day wait is a long time i might forget i’m waiting lol

but im going too have too wait for ever for the forever result

i would prefer too leave it i dont have the correct data anyway

Systemuptime is also a Number? I would assume so but it is always good to check.

I’m assuming that maximiumSince returns a Number Object, but perhaps it returns a primitive.

Or this is one of those cases where the Rules DSL just can’t figure out that there is a toString method it can call.

Or maybe it’s returning a HistoricState Item.

In the interest of time I would try the following until it works or doesn’t.

  • Systemuptime.maximumSince(now.minusDays(28).toString // sendCommand can always take a String
  • Systemuptime.maximumSince(now.minusDays(28) as Number // should already be a Number but perhaps it isn't
  • Systemuptime.maximumSince(now.minusDays(28).state // need to call .state if it is a HistoricItem

Double check that you are actually getting a value and not null. Calls to persistence will return null if there is a problem.

Have you change the default persistence to influxdb? If not you need to tell OH what persistence to query.

Systemuptime.maximumSince(now.minusDays(28, "influxdb")) // I forget whether the db name goes first or second

everyMinute is only required by rrd4j. But in Grafana you have lots of options to select from on how to deal with gaps in the data. In particular pay attention to the fill option for the data point. By default it is “null” which means don’t put a point on the graph if there isn’t one in the DB. If you choose something like last then it will bridge the gap in the graph using the previous value.

Doing experiments like this should be your number one tool to grab when trying to figure out a problem. It’s such a trivial change to make you could of had your answer in the time it took you to ask the question in the first place. Don’t be afraid to experiment. The backups are there for a reason.

Hi Again

I have also tried String , Yes its a Number Item

I will try and post back im not sure about the formatting of the brackets i have tried them all but the brackets might be off

Longestuptime28days.sendCommand(Systemuptime.maximumSince(now.minusDays(28))).toString
Longestuptime28days.sendCommand(Systemuptime.maximumSince(now.minusDays(28).toString))
Longestuptime28days.sendCommand(Systemuptime.maximumSince(now.minusDays(28) as Number))

Could you point me in the right direction on how too do this ?

Yes and uninstalled the rrd4j persistence and deleted its db files and persistence file

I will try this too

so i can actually remove this then i’m definitely not using rrd4j now but i’m also not using grafana yet either i’m just using timelines on habpannel and also interactive charts on habpannel

i would still have too wait two days if @5iver is right about having too wait just 2 days is less wait than 28 :wink:

Error Received trying
Longestuptime28days.sendCommand(Systemuptime.maximumSince(now.minusDays(28) as Number))

 Validation issues found in configuration model 'New.rules', using it anyway:

Cannot cast from DateTime to Number

2018-07-17 22:42:21.455 [vent.ItemStateChangedEvent] - Systemuptime changed from 1453.6 to 1457.6

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

2018-07-17 22:42:21.793 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Test Rule': Could not cast 2018-07-16T22:42:21.779+01:00 to java.lang.Number; line 61, column 63, length 26

Error Received trying
Systemuptime.maximumSince(now.minusDays(28).state

2018-07-17 22:46:21.488 [vent.ItemStateChangedEvent] - Systemuptime changed from 1457.6 to 1461.6

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

2018-07-17 22:46:22.194 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Test Rule': 'state' is not a member of 'org.joda.time.DateTime'; line 61, column 63, length 22

I also changed the days from 28 to 1

I’m missing closing parens in my post above. But let me try to give you the tools to figure out how these parens work.

Parens define the set of arguments passed to a function. So lets work our way from the inside to the outside.

  • now.minusDays(28) This is the innermost function. We are calling the function minusDays on the Object now and passing in the argument 28

  • Systemuptime.maximumSince() This is the next function. We want to pass in the result from the previous section (now.minusDays(28)) as the argument so we put that inside the parens associated with our call to maximumSince on the Systemuptime Object. Systemuptime.maximumSince(now.minusDays(28))

  • The original problem above is that the result of the call to maximumSince is not working as an argument to sendCommand so I presented three options for transforming/casting the result to see if we can make the result acceptable. Let’st stick with toString. We want to pass the result of calling toString on the result to the call to Systemuptime.maximimSince, i.e. Systemuptime.maximumSince(now.minusDays(28)).toString to the sendCommand function on the Object Longestuptime28days. Longestuptime28days.sendCommand(Systemuptime.maximumSince(now.minusDays(28)).toString)

Notice how at each step the previous line is wholly contained within the parens for the function call.

logInfo("test", "Last28days from DB is " + Systemuptime.maximumSince(now.minusDays(28)))

There are trade offs. If all you plan on doing is using the data for graphing, an everyXminutes strategy is pretty reasonable as it will fill in missing data points and prevent the graph from having gaps and such without you needing to configure the the fill on the chart.

However, if you need to know things like the previousState or even more importantly when the previous state occurred, sumSince, or any other calls that expects the data in the database to be storing discrete values then a periodic saving might cause these calls not to work.

So use now.minusMinutes(2). You should at least have a few hours of data in there my now. You are just trying to see if there is any data in there and whether the problem is that you are trying to pull data from before there is any in the database.

Second to last closing paren needs to go after minusDays(28).

Longestuptime28days.sendCommand(Systemuptime.maximumSince(now.minusDays(28)) as Number)

See above.

I got back to my computer and tested this… I was wrong. You should still be able to get a value without having to wait. BUT, you’ll need to use this…

Longestuptime28days.sendCommand(Systemuptime.maximumSince(now.minusDays(28)).state.toString)

or

Longestuptime28days.sendCommand(Systemuptime.maximumSince(now.minusDays(28)).state as Number)

That one seemed too fix it straight away

@rlkoshak

Thanks for that i will save your post and keep it for reference

Thanks @vzorglub

Ok, so the since functions returns a HistoricState. I would assume the calls that do math just return a number.

The documentation for the persistence extensions lays it out pretty well…

Not really.

Gets the maximum value of the State of a persisted Item since a certain point in time

I read that to mean that I’m getting a value, i.e a Number, not a HistoricItem. There really isn’t anything in that statement that tells me I need to call state to get the value not does it tell me the good parts like I can get the time when it was at the max as well as the state.

Now compare that to the description for deltaSince

Gets the difference in value of the State of a given Item since a certain point in time.

I’m pretty sure this returns a Number and not a HistoricItem. But the verbiage is very similar. So similar that at first look I would expect them to will very similarly.

I’m not at a computer where I can see what VSCode says they return. I think that is what I usually rely on so it never occurred to me that the docs were so ambiguous in this regard.

It would be nice too add that I hasent even tought about it myself what’s the point of knowing what the longest uptime is if you don’t know when that was how would I go about adding this?

I would also like too add last updated too my motion sensors I’m assuming you use the last updated command

Would you recomend replacing MAPDB with Influx I have been using mapdb for only restore on startup

Mapdb persists everything and restores on startup

Influx persists specific items for charts, rules

An interesting way to deal with a Raspberry Pi that has gone unresponsive: install the watchdog timer so it will reboot itself:

“This guide describes how to install the hardware watchdog, a system that knows when your raspberry is down, and will automatically reboot it in case this happens.”

https://www.domoticz.com/wiki/Setting_up_the_raspberry_pi_watchdog

2 Likes

Hi Thanks for the reply

This is by no means a fix I thought it was an easy addition and could help me too troubleshoot

Thanks for that I will have a look does the rpi normally go unresponsive? Is this common?

I lost access too ssh the webpage everything the network light was still flashing and so was the green light