Announcement

Collapse
No announcement yet.

Slowing Onewire updates

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Slowing Onewire updates

    Is there a way to slow the onewie updates? My sensors seem to go up and down .2 of a degree a lot, updating the values one or twice a minute would work for me.

    HS3pi. .478
    Arduino plugin, .148
    Device History plugin. .343

    #2
    I am also trying to figure this out

    Comment


      #3
      There are a couple of approaches I've used. One is to use a timer and only send updates to HS if the set time elapses. The other is to only send the updates if the temp changes by a predetermined amount. To the nearest degree is good enough for me, so I round and then only send to HS if it changes +/- 1° or more.

      Mike

      Comment


        #4
        I checked my code - I actually use both methods together, mainly because I am also feeding an OLED display and only want to update it every 2 seconds so it doesn't get flooded with data. I've deleted the OLED code from the code snippet below for clarity.

        Mike

        Code:
        //**************Declare your variables here*******************
        
        unsigned long startMillis;
        unsigned long currentMillis;
        const unsigned long period = 2000;  //the value is a number of milliseconds
        float previous_t = 0;
        
        /* for DS18B20 temperature sensor */
        #include <OneWire.h>
        #include <DallasTemperature.h>
        // Data wire for DS18B20
        #define ONE_WIRE_BUS 0 // esp8266 pin D3
        // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
        OneWire oneWire(ONE_WIRE_BUS);
        // Pass our oneWire reference to Dallas Temperature.
        DallasTemperature sensors(&oneWire);
        #include <Wire.h>  // Comes with Arduino IDE
        
        
        //****************************************************************
        
        
        
        void HSSetup() {
        
          //************************
          //Add YOUR SETUP HERE;
          //************************
          Serial.begin(9600);
          startMillis = millis();  //initial start time
        
          /* for DS18B20 temperature sensor */
          // Start up the DS18B20 library
          sensors.begin();
        
        }
        
        
        void HSloop() {
        
          //************************
          //Add YOUR CODE HERE;
          //************************
          /* To Send Data to Homeseer use SendToHS(Device,Value)
            Eg.. SendToHS(1,200); where 1 is the API device in homeseer and 200 is the value to send
            To Recieve data from Homeseer look up the FromHS array that is updated when the device value changes.
            Eg.. FromHS[5] would be the data from API Output device 5
            All code that is located just below this block will execute regardless of connection status!
            You can include SendToHS() calls, however when there isn't an active connection, it will just return and continue.
            If you only want code to execute when HomeSeer is connected, put it inside the if statement below.
          */
        
          /*Execute regardless of connection status*/
        
          /* for DS18B20 temperature sensor */
          sensors.requestTemperatures(); // get DS18B20 temperature
          float t = sensors.getTempFByIndex(0);
        
        
        /* send data to HS if 'period' has elapsed */
          currentMillis = millis();  //get the current "time" (actually the number of milliseconds since the program started)
          if (currentMillis - startMillis > period ) {
            if (IsConnected == true) {
              /*Execute ONLY when HomeSeer is connected*/
        
              /* send data to HS if it changed +/- 1° or more */
              if (round(previous_t) != round(t)) {
                SendToHS(1,t);
                previous_t = t;
              }
            }
            startMillis = currentMillis;  //IMPORTANT to save the start time of the current OLED state.
          }
        
        }

        Comment


          #5
          Thanks Mike, I might give this a try later today

          Comment

          Working...
          X