Ankündigung

Einklappen
Keine Ankündigung bisher.

Formatierung 0,03206667 unschön

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

    Formatierung 0,03206667 unschön

    Hallo zusammen,

    ich sende mir z.T. berechnete Werte per Telegram Message auf´s Handy. Soweit funktioniert das alles.
    Nur bekomme ich dort den ganzen Wert mit allen Nachkommastellen angezeigt.
    Das zieht sich über all durch. Auch in meinen iFrames im Habpanel.

    Kann mir vielleicht jemand einen Tipp geben, wie ich diese Ausgabe formatieren kann?
    telegram_energy.png
    (ich weiß, mit meinem Trockner stimmt was nicht ;-) das ist ein anderes Thema)

    Meine items (Ausschnitt):
    Code:
     [COLOR=#6a9955]//Waschmaschine[/COLOR]
      [COLOR=#569cd6]Switch [/COLOR][COLOR=#4ec9b0]iShellyPlugS_77_command[/COLOR][COLOR=#ce9178] "PlugS-3 Command"[/COLOR][COLOR=#d4d4d4]<[/COLOR][COLOR=#d4d4d4]washingmachine[/COLOR][COLOR=#d4d4d4]>[/COLOR][COLOR=#d4d4d4]    {[/COLOR][COLOR=#c586c0]channel[/COLOR][COLOR=#d4d4d4]=[/COLOR][COLOR=#ce9178]"mqtt:topic:oh2mqtt24:myPlugS:ShellyPlugS_77_command"[/COLOR][COLOR=#d4d4d4]}[/COLOR]
     [COLOR=#569cd6]Number [/COLOR][COLOR=#4ec9b0]iShellyPlugS_77_energy[/COLOR][COLOR=#ce9178] "PlugS-3 Energy [%.0f W/m]"[/COLOR][COLOR=#d4d4d4] <[/COLOR][COLOR=#d4d4d4]energy[/COLOR][COLOR=#d4d4d4]>[/COLOR][COLOR=#d4d4d4]            {[/COLOR][COLOR=#c586c0]channel[/COLOR][COLOR=#d4d4d4]=[/COLOR][COLOR=#ce9178]"mqtt:topic:oh2mqtt24:myPlugS:ShellyPlugS_77_energy"[/COLOR][COLOR=#d4d4d4]}[/COLOR]
    [COLOR=#569cd6]Switch [/COLOR][COLOR=#4ec9b0]waschen_aktiv[/COLOR][COLOR=#ce9178] "Waschprgramm [%s]"[/COLOR]  [COLOR=#569cd6]Number[/COLOR][COLOR=#4ec9b0]waschen_kosten[/COLOR][COLOR=#ce9178]"Waschkosten [%.0f EUR]"[/COLOR]
      [COLOR=#569cd6]Number [/COLOR][COLOR=#4ec9b0]waschen_energie[/COLOR][COLOR=#ce9178] "Waschenergie [%.2f kW/h]"[/COLOR][COLOR=#d4d4d4]<[/COLOR][COLOR=#d4d4d4]price[/COLOR][COLOR=#d4d4d4]>[/COLOR]
      [COLOR=#569cd6]Switch[/COLOR][COLOR=#4ec9b0] waschen_trocknen_RESET[/COLOR]
      [COLOR=#569cd6]Number [/COLOR][COLOR=#4ec9b0]iShelly_77_Letzter_Tagesverbrauch[/COLOR][COLOR=#ce9178] "Kosten [%.2f EUR]"[/COLOR][COLOR=#d4d4d4]<[/COLOR][COLOR=#d4d4d4]price[/COLOR][COLOR=#d4d4d4]>[/COLOR]
    In meiner Rules berechne ich den Energieverbrauch wie folgt (Ausschnitt):
    Code:
     [COLOR=#6a9955]//Waschmaschine: iShellyPlugS_77_energy[/COLOR]
      [COLOR=#569cd6]var[/COLOR][COLOR=#569cd6]Number[/COLOR][COLOR=#4ec9b0] letzterTagesverbrauch_77[/COLOR][COLOR=#d4d4d4]=[/COLOR][COLOR=#d4d4d4] ([/COLOR][COLOR=#4ec9b0]iShellyPlugS_77_energy[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]state [/COLOR][COLOR=#4ec9b0]as[/COLOR][COLOR=#569cd6]Number[/COLOR][COLOR=#d4d4d4]) [/COLOR][COLOR=#d4d4d4]-[/COLOR][COLOR=#d4d4d4] ([/COLOR][COLOR=#4ec9b0]iShellyPlugS_77_energy[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]historicState([/COLOR][COLOR=#4ec9b0]now[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]withTimeAtStartOfDay)[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]state [/COLOR][COLOR=#4ec9b0]as[/COLOR][COLOR=#569cd6]Number[/COLOR][COLOR=#d4d4d4])[/COLOR]
      [COLOR=#4ec9b0]letzterTagesverbrauch_77[/COLOR][COLOR=#d4d4d4]=[/COLOR][COLOR=#d4d4d4] ([/COLOR][COLOR=#4ec9b0]letzterTagesverbrauch_77[/COLOR][COLOR=#d4d4d4]) [/COLOR][COLOR=#d4d4d4]/[/COLOR][COLOR=#b5cea8]60000[/COLOR][COLOR=#6a9955]// Umrechnung von Watt-minute auf kWh[/COLOR]
      [COLOR=#c586c0]if[/COLOR][COLOR=#d4d4d4]([/COLOR][COLOR=#4ec9b0]energy_debug[/COLOR][COLOR=#d4d4d4]) logInfo([/COLOR][COLOR=#ce9178]"Energy >>>"[/COLOR][COLOR=#d4d4d4], [/COLOR][COLOR=#ce9178]"Stromverbrauch Waschen aktuell: "[/COLOR][COLOR=#d4d4d4]+[/COLOR][COLOR=#4ec9b0]iShellyPlugS_77_energy[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]state [/COLOR][COLOR=#d4d4d4]+[/COLOR][COLOR=#ce9178]" W/min"[/COLOR][COLOR=#d4d4d4])[/COLOR]
      [COLOR=#c586c0]if[/COLOR][COLOR=#d4d4d4]([/COLOR][COLOR=#4ec9b0]energy_debug[/COLOR][COLOR=#d4d4d4]) logInfo([/COLOR][COLOR=#ce9178]"Energy >>>"[/COLOR][COLOR=#d4d4d4], [/COLOR][COLOR=#ce9178]"Stromverbrauch Waschen heute: "[/COLOR][COLOR=#d4d4d4]+[/COLOR][COLOR=#d4d4d4] ([/COLOR][COLOR=#4ec9b0]iShellyPlugS_77_energy[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]historicState([/COLOR][COLOR=#4ec9b0]now[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]withTimeAtStartOfDay)[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]state) [/COLOR][COLOR=#d4d4d4]+[/COLOR][COLOR=#ce9178]" W/min"[/COLOR][COLOR=#d4d4d4])[/COLOR]
      [COLOR=#c586c0]if[/COLOR][COLOR=#d4d4d4]([/COLOR][COLOR=#4ec9b0]iShelly_77_Letzter_Tagesverbrauch[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]state [/COLOR][COLOR=#d4d4d4]!=[/COLOR][COLOR=#4ec9b0]letzterTagesverbrauch_77[/COLOR][COLOR=#d4d4d4])[/COLOR]
      [COLOR=#d4d4d4]        {[/COLOR]
      [COLOR=#4ec9b0]iShelly_77_Letzter_Tagesverbrauch[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]postUpdate([/COLOR][COLOR=#4ec9b0]letzterTagesverbrauch_77[/COLOR][COLOR=#d4d4d4])[/COLOR]
      [COLOR=#c586c0]if[/COLOR][COLOR=#d4d4d4]([/COLOR][COLOR=#4ec9b0]energy_log[/COLOR][COLOR=#d4d4d4]) logInfo([/COLOR][COLOR=#ce9178]"Energy >>>"[/COLOR][COLOR=#d4d4d4], [/COLOR][COLOR=#ce9178]"Stromverbrauch Waschen: "[/COLOR][COLOR=#d4d4d4]+[/COLOR][COLOR=#4ec9b0]iShelly_77_Letzter_Tagesverbrauch[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]state [/COLOR][COLOR=#d4d4d4]+[/COLOR][COLOR=#ce9178]" kWh"[/COLOR][COLOR=#d4d4d4])[/COLOR]
      [COLOR=#d4d4d4]            sendTelegram([/COLOR][COLOR=#ce9178]"TelegramBot"[/COLOR][COLOR=#d4d4d4], [/COLOR][COLOR=#ce9178]"Stromverbrauch Waschen: "[/COLOR][COLOR=#d4d4d4]+[/COLOR][COLOR=#4ec9b0]iShelly_77_Letzter_Tagesverbrauch[/COLOR][COLOR=#d4d4d4].[/COLOR][COLOR=#d4d4d4]state [/COLOR][COLOR=#d4d4d4]+[/COLOR][COLOR=#ce9178]" kWh"[/COLOR][COLOR=#d4d4d4])[/COLOR]
      [COLOR=#d4d4d4]        }[/COLOR]
    Zuletzt geändert von mortyPi; 17.12.2019, 08:25.

    #2
    Verwende eine Formatierung:
    Code:
    String::format("%.2f",(Shelly_77_Letzter_Tagesverbrauch.state as Number))
    Hast Du Dir mal angeschaut, wie das Logging mit log4j2 funktioniert? Es gibt verschiedene Logger, die man allesamt einzeln oder auch gemeinsam (hierarchisch) auf verschiedene Level setzen kann. Zur Laufzeit. Ohne, dass man dafür eine eigene Logik einbauen müsste

    Kommentar


      #3
      Danke für den Tipp.
      Ich habe meine log-Zeile wie folgt abgeändert:
      Code:
       logInfo("Energy >>>", "Stromverbrauch Waschen aktuell: " + String::format("%.2f",(iShellyPlugS_77_energy.state as Number)) + " W/min")
      Aber ich erhalte folgenden Error:
      Code:
      ==> /var/log/openhab2/openhab.log <==
      2019-12-17 12:43:12.846 [COLOR=red][ERROR][/COLOR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Letzter täglicher Stromverbrauch': f != org.eclipse.smarthome.core.library.types.DecimalType
      Habe ich da noch einen Fehler drin? Oder fehlt mir eine library?

      Bzgl: log4j2:
      Ja, ich habe schonmal einen Beitrag von Dir gelesen, indem es auch darum ging. Aber ich bin noch nicht dazu gekommen meine Log-Infos umzuschreiben.

      Kommentar


        #4
        So, ich habe noch etwas rum probiert und nun passt die Ausgabe.
        Code:
        logInfo("Energy >>>", "Stromverbrauch Waschen aktuell: " + String::format("%.2f",(iShellyPlugS_77_energy.state as DecimalType).floatValue()) + " W/min")
        https://community.openhab.org/t/solv...e-number/57844


        Aber kennt sich noch jemand mit HTML aus? Auch dort in meinem HABpanel gebe ich die Items in einem iFrame aus und sind nicht wirklich schön anzusehen:
        HTML-Code:
        <table class="table">
        <caption><span style="color: white; font-size: 12pt">Leistung:</span></caption>
          <tr>
            <td class="text-left"><span style="color: white; font-size: 8pt">Waschmaschine:</td>
            <td><strong><span style="color: white; font-size: 8pt">{{itemValue('waschen_aktiv')}} </strong></td>
            <td><strong><span style="color: white; font-size: 8pt">{{itemValue('iShellyPlugS_77_power')}} W</strong></td>
            <td><strong><span style="color: white; font-size: 8pt">{{itemValue('waschen_energie')}} kW/h</strong></td>
            <td><strong><span style="color: white; font-size: 8pt">{{itemValue('waschen_kosten')}} EUR</strong></td>
          </tr>
          <tr>
            <td class="text-left"><span style="color: white; font-size: 8pt">Trockner:</td>
            <td><strong><span style="color: white; font-size: 8pt">{{itemValue('trocknen_aktiv')}} </strong></td>
            <td><strong><span style="color: white; font-size: 8pt">{{itemValue('iShellyPlugS_78_power')}} W</strong></td>
            <td><strong><span style="color: white; font-size: 8pt">{{itemValue('trocknen_energie')}} kW/h</strong></td>
            <td><strong><span style="color: white; font-size: 8pt">{{itemValue('trocknen_kosten')}} EUR</strong></td>
          </tr>
          <tr>
            <td class="text-left"><span style="color: red; font-size: 8pt">Steckdosen:</td>
            <td><strong><span style="color: red; font-size: 8pt">{{itemValue('iShellyPlugS_77_command')}} {{itemValue('iShellyPlugS_78_command')}}</strong></td>
          </tr>
        </table>
        Zuletzt geändert von mortyPi; 17.12.2019, 15:11.

        Kommentar


          #5
          Ich hab´s rausgefunden!
          So geht´s mit 2 Nachkomma-Stellen:
          HTML-Code:
          <table class="table">
          <caption><span style="color: white; font-size: 12pt">Leistung:</span></caption>
            <tr>
              <td class="text-left"><span style="color: white; font-size: 8pt">Waschmaschine:</td>
              <td><strong><span style="color: white; font-size: 8pt">{{itemValue('waschen_aktiv')}} </strong></td>
              <td><strong><span style="color: white; font-size: 8pt">{{'%.2f ' | sprintf: itemValue('iShellyPlugS_77_power')}} W</strong></td>
              <td><strong><span style="color: white; font-size: 8pt">{{'%.2f ' | sprintf: itemValue('waschen_energie')}} kW/h</strong></td>
              <td><strong><span style="color: white; font-size: 8pt">{{'%.2f ' | sprintf: itemValue('waschen_kosten')}} EUR</strong></td>
            </tr>
            <tr>
              <td class="text-left"><span style="color: white; font-size: 8pt">Trockner:</td>
              <td><strong><span style="color: white; font-size: 8pt">{{itemValue('trocknen_aktiv')}} </strong></td>
              <td><strong><span style="color: white; font-size: 8pt">{{'%.2f ' | sprintf: itemValue('iShellyPlugS_78_power')}} W</strong></td>
              <td><strong><span style="color: white; font-size: 8pt">{{'%.2f ' | sprintf: itemValue('trocknen_energie')}} kW/h</strong></td>
              <td><strong><span style="color: white; font-size: 8pt">{{'%.2f ' | sprintf: itemValue('trocknen_kosten')}} EUR</strong></td>
            </tr>
            <tr>
              <td class="text-left"><span style="color: red; font-size: 8pt">Steckdosen:</td>
              <td><strong><span style="color: red; font-size: 8pt">{{itemValue('iShellyPlugS_77_command')}} {{itemValue('iShellyPlugS_78_command')}}</strong></td>
            </tr>
          </table>

          Kommentar

          Lädt...
          X