Ankündigung

Einklappen
Keine Ankündigung bisher.

Regentonne Abstand in cm in Prozente (bzw. Number) umrechnen zur Visualisierung

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    Regentonne Abstand in cm in Prozente (bzw. Number) umrechnen zur Visualisierung

    Hallo,

    ich habe in einer Regentonne einen Wemos D1 mini mit Ultraschalsensor verbaut. Dieser sendet alle 2 Minuten auf meinen MQTT Broker seinen Abstandswert. Dieser kommt wiederum im openhab sauber an.
    Nun möchte ich (für eine bessere Visualisierung) diese Werte in % (bzw weiterhin als Number, es reicht in der Anzeige des Items das %).

    Somit habe ich mir eine Rule gebaut, in dieser ich die Werte umrechne.
    Aber es klappt nicht. ich glaube ich habe die falschen "von bis" eingebaut, finde aber auch mithilfe von google keinen passenden Beispiele :-\

    Rule:
    Code:
    rule "Regentonne 01 cm in Prozent umrechnen"
    when Item WemosD1_Abstand_Regentonne01 received update
    then
    {
        if (WemosD1_Abstand_Regentonne01.state <= 19.2 )
        {     Regentonne01_Prozent.postUpdate(100) }
        if (WemosD1_Abstand_Regentonne01.state >= 19.3 && <= 25.5 )
         {     Regentonne01_Prozent.postUpdate(90) }
        if (WemosD1_Abstand_Regentonne01.state >= 25.6 && <= 31.8 )
        {     Regentonne01_Prozent.postUpdate(80) }
        if (WemosD1_Abstand_Regentonne01.state >= 31.9 && <= 38.1 )
         {     Regentonne01_Prozent.postUpdate(70) }
        if (WemosD1_Abstand_Regentonne01.state >= 38.2 && <= 44.4 )
        {     Regentonne01_Prozent.postUpdate(60) }
        if (WemosD1_Abstand_Regentonne01.state >= 44.5 && <= 50.7 )
         {     Regentonne01_Prozent.postUpdate(50) }
        if (WemosD1_Abstand_Regentonne01.state >= 50.8 && <= 57.0 )
        {     Regentonne01_Prozent.postUpdate(40) }
        if (WemosD1_Abstand_Regentonne01.state >= 57.1 && <= 63.3 )
         {     Regentonne01_Prozent.postUpdate(30) }
        if (WemosD1_Abstand_Regentonne01.state >= 63.4 && <= 69.6  )
        {     Regentonne01_Prozent.postUpdate(20) }
        if (WemosD1_Abstand_Regentonne01.state >= 69.7)
         {     Regentonne01_Prozent.postUpdate(10) }
    }
    end
    im Prinzip entspricht der Abstand 13cm Abstand = Voll (100%) und der Abstand 76cm Abstand = leer (&lt;10%)

    Code:
     [TABLE="width: 190"]
     	 		[TR]
     			[TD][SIZE=15px][COLOR=black][FONT=Calibri]Abstand in cm[/FONT][/COLOR][/SIZE][/TD]
     			[TD][SIZE=15px][COLOR=black][FONT=Calibri]Füllstand in %[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]76[/FONT][/COLOR][/SIZE][/TD]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]0[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]69,7[/FONT][/COLOR][/SIZE][/TD]
     			[TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]10%[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]63,4[/FONT][/COLOR][/SIZE][/TD]
     			[TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]20%[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]57,1[/FONT][/COLOR][/SIZE][/TD]
     			[TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]30%[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]50,8[/FONT][/COLOR][/SIZE][/TD]
     			[TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]40%[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]44,5[/FONT][/COLOR][/SIZE][/TD]
     			[TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]50%[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]38,2[/FONT][/COLOR][/SIZE][/TD]
     			[TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]60%[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]31,9[/FONT][/COLOR][/SIZE][/TD]
     			[TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]70%[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]25,6[/FONT][/COLOR][/SIZE][/TD]
     			[TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]80%[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]19,3[/FONT][/COLOR][/SIZE][/TD]
     			[TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]90%[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     		[TR]
     			[TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]13[/FONT][/COLOR][/SIZE][/TD]
     			[TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]100%[/FONT][/COLOR][/SIZE][/TD]
     		[/TR]
     	 [/TABLE]
    folgender Fehler kommt:

    Code:
    2020-09-14 08:33:04.754 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'testrules.rules' has errors, therefore ignoring it:
    [32,56]: no viable alternative at input '='
    [32,58]: mismatched input '25' expecting '>'
    [32,63]: mismatched input ')' expecting '}'
    [34,56]: no viable alternative at input '='
    [34,58]: mismatched input '31' expecting '>'
    [34,63]: mismatched input ')' expecting 'end'
    wie kriege ich das zum laufen?
    DANKE!

    edit: ich habe dann doch noch ein beispiel gefunden, wo mit mehrere Werten gearbeitet wurde.
    Habe meinen Code aufbereitet und er funktioniert jetzt auch:

    Code:
    rule "Regentonne 01 cm in Prozent umrechnen"
    when Item WemosD1_Abstand_Regentonne01 received update
    then 
    {
        if ((WemosD1_Abstand_Regentonne01.state as Number) <19 )
        {     Regentonne01_Prozent.postUpdate(100) }
        if (((WemosD1_Abstand_Regentonne01.state as Number) >19 ) && (WemosD1_Abstand_Regentonne01.state as Number) <25 )
         {     Regentonne01_Prozent.postUpdate(90) }
        if (((WemosD1_Abstand_Regentonne01.state as Number) >25 ) && (WemosD1_Abstand_Regentonne01.state as Number) <31 )
        {     Regentonne01_Prozent.postUpdate(80) }
        if (((WemosD1_Abstand_Regentonne01.state as Number) >31 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 38 )
         {     Regentonne01_Prozent.postUpdate(70) }
        if (((WemosD1_Abstand_Regentonne01.state as Number) >38 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 44 )
        {     Regentonne01_Prozent.postUpdate(60) }
        if (((WemosD1_Abstand_Regentonne01.state as Number) >44 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 50 )
         {     Regentonne01_Prozent.postUpdate(50) }
        if (((WemosD1_Abstand_Regentonne01.state as Number) >50 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 57 )
        {     Regentonne01_Prozent.postUpdate(40) }
        if (((WemosD1_Abstand_Regentonne01.state as Number) >57 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 63 )
         {     Regentonne01_Prozent.postUpdate(30) }
        if (((WemosD1_Abstand_Regentonne01.state as Number) >63 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 69  )
        {     Regentonne01_Prozent.postUpdate(20) }
        if ((WemosD1_Abstand_Regentonne01.state as Number) > 69)
         {     Regentonne01_Prozent.postUpdate(10) }
    }
    end
    ich habe es vereinfacht, da der Abstand auch nur in vollen cm übergeben wird, habe ich die Rule nun auch nicht an die "tatsächlichen" Prozenzualen Werte angepasst, sondern gerundete ganze Zahlen genommen.
    Da der Tank noch voll ist, kann ich noch nicht sagen ob es richtig funktioniert. Aber ich habe jetzt schonmal auf dem item meine 100% Füllstand
    Zuletzt geändert von desidia; 14.09.2020, 08:29.

    #2
    Super das es soweit klappt.

    Aber möchtest du mit Absicht die Genauigkeit auf 10 %-Schritte reduzieren?

    Falls nicht, fitte dir doch mit Excel einfach eine Funktion, in dem Fall tut es eine einfach Gerade, und verwende diese. Damit kannst du den Code auf quasi eine Zeile reduzieren und hast eine deutlich höhere Genauigkeit.

    Image 15.jpg

    Kommentar


      #3
      Zitat von Intenos Beitrag anzeigen
      Falls nicht, fitte dir doch mit Excel einfach eine Funktion
      Das hätte ich vor einigen Wochen gut brauchen können, da habe ich eine halbe Ewigkeit für die Formel gebraucht. In Excel hat es gerade nur fünf Minuten gedauert ...

      Kommentar


        #4
        Na, dazu hätte es aber kein Excel gebraucht

        Minimum ist 76cm, Maximum ist 13cm, die Differenz ist 63cm, das ergibt als Formel:

        Füllstand = 100-((Messhöhe-13)/63*100)

        Dies setzt natürlich voraus, dass die Regentonne einigermaßen zylindrisch ist, bzw. der Füllstand linear ansteigt. Das tut die Näherung in Excel aber auch...

        Kommentar


          #5
          Zitat von udo1toni Beitrag anzeigen
          Na, dazu hätte es aber kein Excel gebraucht

          Minimum ist 76cm, Maximum ist 13cm, die Differenz ist 63cm, das ergibt als Formel:

          Füllstand = 100-((Messhöhe-13)/63*100)

          Dies setzt natürlich voraus, dass die Regentonne einigermaßen zylindrisch ist, bzw. der Füllstand linear ansteigt. Das tut die Näherung in Excel aber auch...
          DANKE!

          aber wenn ich es in eine Regel bringe, kommt kein Fehler im Log, aber es geschieht auch nichts im Log...? Denkfehler?

          Code:
          rule "Regentonne 01 cm in Prozent umrechnen"
          when Item WemosD1_Abstand_Regentonne01 received update
          then
          {
              var Number messhoehe = WemosD1_Abstand_Regentonne01.state as Number
              var Number fuellstand = 0
              fuellstand = 100 - (( messhoehe - 13) / 63 * 100)
              Regentonne01_Prozent.postUpdate(fuellstand)
          }
          end

          edit: es funktioniert doch!
          Zuletzt geändert von desidia; 16.09.2020, 08:25.

          Kommentar

          Lädt...
          X