Time measurement in OH3

Hi there!

I just migrated to OH3. Everything fine so far, but I don’t get my sunshine calculation up and running as this changed in OH3. Unfortunately I did not get it to run even after quite some investigation.
Therefore I would like to ask for your support.

Here is the rule:

rule "Sonnenstundenzähler starten/stoppen"
    when
        Item iWetterHelligkeitGlobalstrahlung changed
    then

        logInfo("Wetter", "Sonnenstundenzähler logging")
        logInfo("Wetter", "Globalstrahlung neu:" + iWetterHelligkeitGlobalstrahlung.state)
        logInfo("Wetter", "Globalstrahlung alt:" + iWetterHelligkeitGlobalstrahlung.previousState(true,"influxdb").state)

        if((iWetterHelligkeitGlobalstrahlung.state>=120) &&
           (iWetterHelligkeitGlobalstrahlung.previousState(true,"influxdb").state<120)) {
            logInfo("Wetter", "Sonnenstundenzähler starten")
            iWetterSonnenstundenzaehlerStartZeit.postUpdate(new DateTimeType())
        }
      
        if((iWetterHelligkeitGlobalstrahlung.state<120) &&
           (iWetterHelligkeitGlobalstrahlung.previousState(true,"influxdb").state>=120)) {

            logInfo("Wetter", "Sonnenstundenzähler stoppen")
            var DateTimeType Einschaltzeit = iWetterSonnenstundenzaehlerStartZeit.state as DateTimeType
            var Number SonnenStundenDauerSekunden = Seconds::secondsBetween(new DateTime(Einschaltzeit.calendar.timeInMillis), now ).getSeconds()

            logInfo("Wetter","Sonnenscheindauer: " + SonnenStundenDauerSekunden + " secs.")                
            var Number SonnenstundenZaehlerSekunden = (iWetterSonnenstundenZaehlerSekunden.state as DecimalType) + SonnenStundenDauerSekunden

            logInfo("Wetter","Sonnenstundenzähler: " + SonnenstundenZaehlerSekunden + " secs.")
            iWetterSonnenstundenZaehlerSekunden.sendCommand(SonnenstundenZaehlerSekunden.floatValue)
        
            var Number SonnenstundenZaehlerMinuten = SonnenstundenZaehlerSekunden / 60
            iWetterSonnenstundenZaehlerMinuten.sendCommand(SonnenstundenZaehlerMinuten.floatValue)

            var Number SonnenstundenZaehlerStunden = SonnenstundenZaehlerMinuten / 60
            iWetterSonnenstundenZaehlerStunden.sendCommand(SonnenstundenZaehlerStunden.floatValue)
        }
end

The rule is triggered when then sun intension changes. The recording should start once the intension exceeds 120W/qm and stop if it falls below 120W/qm. All periods need to be accumulated. The variable will be reset at midnight, so I get the total sunshine time during the day.

I am aware that the line following line is the problem as it is still in Joda Time format:
var Number SonnenStundenDauerSekunden = Seconds::secondsBetween(new DateTime(Einschaltzeit.calendar.timeInMillis), now ).getSeconds()

Thanks a lot for your support!

Best regards,
Matthias

Anyone to support? It would be great
:blush:

Did you have a look into the release notes for OH3?
The information on GitHub describes how to change the time formats and commands.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.