Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Gelöst: Script zur Abfrage der CPU Temp

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Gelöst: Script zur Abfrage der CPU Temp

    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      michihorn @Thomas Braun last edited by michihorn

      @thomas-braun Moin Thomas, dass ist mir etwas pauschal, kannst du konkreter werden, wie ich das anstelle?
      Was ist lm-sensors und wo installiere ich das?

      Thomas Braun 1 Reply Last reply Reply Quote 0
      • Thomas Braun
        Thomas Braun Most Active @michihorn last edited by

        @michihorn

        Das ist ein Paket, mit dem man diverse Sensoren auslesen kann.

        sudo apt install lm-sensors
        

        Ausgabe sieht dann ungefähr so aus:

        echad@chet:~ $ sensors
        cpu_thermal-virtual-0
        Adapter: Virtual device
        temp1:        +47.7°C  (crit = +110.0°C)
        
        rpi_volt-isa-0000
        Adapter: ISA adapter
        in0:              N/A
        
        echad@chet:~ $
        
        M 1 Reply Last reply Reply Quote 0
        • M
          michihorn @Thomas Braun last edited by

          @thomas-braun Klingt interessant und wie bringe ich die dann in Iobroker?

          Thomas Braun 1 Reply Last reply Reply Quote 0
          • Thomas Braun
            Thomas Braun Most Active @michihorn last edited by

            @michihorn

            Mit einem Skriptchen oder Blockly.

            M 1 Reply Last reply Reply Quote 0
            • M
              michihorn @Thomas Braun last edited by michihorn

              @thomas-braun also die Werte habe ich nun im Terminal, aber wie ich nun die Werte mit einem Script abrufen kann, weiß ich leider nicht.

              1 Reply Last reply Reply Quote 0
              • Thomas Braun
                Thomas Braun Most Active last edited by

                @michihorn

                Ich auch nicht.
                Mit dem EXEC-Baustein-Blockly vielleicht.

                M 1 Reply Last reply Reply Quote 0
                • M
                  michihorn @Thomas Braun last edited by

                  @thomas-braun okay dann forsche ich mal.Danke erst mal

                  T 1 Reply Last reply Reply Quote 0
                  • paul53
                    paul53 @michihorn last edited by paul53

                    @michihorn sagte: Abfrage der CPU Temperatur

                    Welche CPU? Raspberry Pi?

                    Thomas Braun 1 Reply Last reply Reply Quote 0
                    • T
                      ticaki Developer @michihorn last edited by

                      @michihorn

                      Ich hab sowas um zu checken ob ich online bin:

                      var con_active = false;
                      setInterval(function(){
                          con_active = false;
                          exec('ping -qc 2 www.google.com', callback)
                          exec('ping -qc 2 www.bing.com', callback)
                          exec('ping -qc 2 www.heise.de', callback)
                      },60000)
                      exec('ping -qc 2 www.google.com', callback)
                      exec('ping -qc 2 www.bing.com', callback)
                      exec('ping -qc 2 www.heise.de', callback)
                      
                      
                      
                      
                      
                      function callback(err, res) {
                          let should = res.substring(res.indexOf('statistics ---') + ('statistics ---').length, res.indexOf(' packets transmitted'));
                          should = Number(should)
                          let current = res.substring(res.indexOf('transmitted, ') + ('transmitted, ').length, res.indexOf('received'));
                          current = Number(current)
                          con_active = con_active || should && should == current
                          //log("test " + res)
                          setState('0_userdata.0.internet_connected', !!con_active, true);
                      
                      1 Reply Last reply Reply Quote 0
                      • Thomas Braun
                        Thomas Braun Most Active @paul53 last edited by

                        @paul53 sagte in Script zur Abfrage der CPU Temp:

                        Welche CPU? Raspberry Pi?

                        Beim Pi könnte man es auch per

                        vcgencmd measure_temp
                        

                        auslesen.

                        M 1 Reply Last reply Reply Quote 1
                        • M
                          michihorn last edited by

                          @paul53 Raspberry 4

                          Ich habe es mal so versucht:

                          schedule("* * * * *", function () {
                          exec('sensors', function (error, stdout, stderr) { setState('0_userdata.0.System.pitemp',stdout); }); 
                          });
                          

                          Dann wird der DP auch beschrieben mit:
                          cpu_thermal-virtual-0
                          Adapter: Virtual device
                          temp1: +44.3°C (crit = +110.0°C)

                          rpi_volt-isa-0000
                          Adapter: ISA adapter
                          in0: N/A

                          Also kann ich mit Substr, das sicher einkürzen, oder gibt es einen einfacheren Weg?

                          T 1 Reply Last reply Reply Quote 0
                          • T
                            ticaki Developer @michihorn last edited by

                            @michihorn

                            Ja das sollte mit regex gehen... muß das aber mal gerade selbst versuchen

                            1 Reply Last reply Reply Quote 0
                            • M
                              michihorn @Thomas Braun last edited by michihorn

                              @thomas-braun sagte in Script zur Abfrage der CPU Temp:

                              @paul53 sagte in Script zur Abfrage der CPU Temp:

                              Welche CPU? Raspberry Pi?

                              Beim Pi könnte man es auch per

                              vcgencmd measure_temp
                              

                              auslesen.

                              schedule("* * * * *", function () {
                              //exec('sensors', function (error, stdout, stderr) { setState('0_userdata.0.System.pitemp',stdout); }); 
                              exec('vcgencmd measure_temp', function (error, stdout, stderr) { setState('0_userdata.0.System.pitemp',stdout); }); 
                              });
                              

                              Das Ergebnis ist:
                              temp=44.8'C
                              Klappt...mit einer kleinen Hürde, denn ich habe eine Warnmeldung
                              hürde.png

                              Edit: War der falsche Datentyp im DP

                              Danke für die Hilfe 👍

                              T 1 Reply Last reply Reply Quote 0
                              • T
                                ticaki Developer @michihorn last edited by

                                @michihorn

                                Auch wenns schon geht:

                                const test = `cpu_thermal-virtual-0
                                Adapter: Virtual device
                                temp1: +44.3°C (crit = +110.0°C)
                                
                                rpi_volt-isa-0000
                                Adapter: ISA adapter
                                in0: N/A`
                                
                                const reg = /[0-9\.]+°C/;
                                const result = test.match(reg);
                                if (result) log(result[0])
                                
                                javascript.0 (619) script.js.Test.Skript_2: 44.3°C
                                
                                1 Reply Last reply Reply Quote 1
                                • First post
                                  Last post

                                Support us

                                ioBroker
                                Community Adapters
                                Donate

                                1.0k
                                Online

                                31.7k
                                Users

                                79.8k
                                Topics

                                1.3m
                                Posts

                                javascript
                                4
                                16
                                586
                                Loading More Posts
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes
                                Reply
                                • Reply as topic
                                Log in to reply
                                Community
                                Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                The ioBroker Community 2014-2023
                                logo