Announcement

Collapse
No announcement yet.

How to go from sketch to api

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

  • How to go from sketch to api

    Greg...first I want to say thanks for the GREAT plugin. Opened up my homeseer world to a whole new level. I do have some trouble however going from a sketch found on the web to implementing into an api sketch. It would be great if there was a "how to" tutorial to take a sketch off the web and cut/paste the parts into the api and "at least get close" to making it work. maybe what I am wanting is not possible?

  • #2
    What do you want to do?

    The problem is you might need different bits depending on what you want to do. I am not sure how to write this up. If you post what you want I am sure we can point you in the correct direction.

    Greig.

    Sent from my SM-G950F using Tapatalk

    Zwave = Z-Stick, 3xHSM100 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
    X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
    Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
    Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
    Scripts =
    Various

    Comment


    • #3
      Originally posted by enigmatheatre View Post
      What do you want to do?

      The problem is you might need different bits depending on what you want to do. I am not sure how to write this up. If you post what you want I am sure we can point you in the correct direction.

      Greig.

      Sent from my SM-G950F using Tapatalk
      Here is an example that I am planning on soon. This is an example sketch for a flame sensor and I want to have one for each stove top burner. I would prefer nodemcu. If I had to use a Uno then I would hope to get all three flame sensors into the arduino. so which parts to I cut and paste into the api Greg?

      int flamePin = A0; // flame sensor sensor input
      int ledPin = 13; // select the pin for the LED
      int flameValue = 0; // variable to store the value coming from the photocell val
      //unsigned long interval=1000; // the time we need to wait
      //unsigned long previousMillis=0; // millis() returns an unsigned long.
      void setup() {
      Serial.begin(9600);
      pinMode(ledPin, OUTPUT);
      digitalWrite(ledPin, LOW);
      }
      void loop() {
      // read the value from the flame sensor:
      flameValue = analogRead(flamePin);
      flameValue = constrain(flameValue, 0, 1023); //adjust depending on environment.
      Serial.println(flameValue); //print our value
      //prevents entire program from slowing down /w a ' delay() '
      //allows continous readings consistent speed even with conditions
      //if ((unsigned long)(millis() - previousMillis) >= interval) {
      //previousMillis = millis();
      if(flameValue > 700){ // if the flame reading is greater than 300,alert with buzzer and LED
      digitalWrite(ledPin, !digitalRead(ledPin)); //turn led on
      }
      else if (flameValue < 700){
      digitalWrite(ledPin, LOW);//turn led off
      }
      // }
      }

      Comment


      • #4
        This is quite an easy one to start with.
        1. You need all the variables set up and placed where it says "Declare your variables here"
        2. In the void HSSetup you need to set up the led pin (I guess you still want the LED?) We do not need the Serial data as we are sending the data to HS now.
        3. in void HSloop under /*Execute regardless of connection status*/ we put the code to control the LED so there is always indication even if not connected to HS.
        4. In void HSloop under /*Execute ONLY when HomeSeer is connected*/ we send the data to HS using the SendToHS function. There is also the code for a delay in there so the data is not sent to HS on every loop.

        so you should end up with something like this:


        Code:
        //**************Declare your variables here*******************
        
        int flamePin = A0; // flame sensor sensor input
        int ledPin = 13; // select the pin for the LED
        int flameValue = 0; // variable to store the value coming from the photocell val
        unsigned long interval=10000; // the time we need to wait
        unsigned long previousMillis=0; // millis() returns an unsigned long.
        
        
        //****************************************************************
        
        void HSSetup() {
        
        pinMode(ledPin, OUTPUT);
        digitalWrite(ledPin, LOW);
        
        }
        
        
        void HSloop() {
        
        
        
          //************************
          //Add YOUR CODE HERE;
          //************************
          /*Execute regardless of connection status*/
        flameValue = analogRead(flamePin);
        flameValue = constrain(flameValue, 0, 1023); //adjust depending on environment.
        
        if(flameValue > 700){ // if the flame reading is greater than 300,alert with buzzer and LED
        digitalWrite(ledPin, !digitalRead(ledPin)); //turn led on
        }
        else if (flameValue < 700){
        digitalWrite(ledPin, LOW);//turn led off
        }
        
        
            /*Execute ONLY when HomeSeer is connected*/
          if (IsConnected == true) {
        
        
        //prevents entire program from slowing down with a ' delay() '
        //allows continous readings consistent speed even with conditions
        if ((unsigned long)(millis() - previousMillis) >= interval) {
        previousMillis = millis();
        
        SendToHS(1,flameValue);
        
          }
        
        }
        }

        Greig.
        Zwave = Z-Stick, 3xHSM100 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
        X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
        Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
        Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
        Scripts =
        Various

        Comment


        • #5
          Thanks Greg! I have so much to learn about arduino, but the possibilities are endless.,..

          Comment


          • #6
            what about one like this Greg? do I delete the Serial.print and Serial.printin?



            // defines pins numbers
            const int trigPin = 2; //D4
            const int echoPin = 0; //D3

            // defines variables
            long duration;
            int distance;

            void setup() {
            pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
            pinMode(echoPin, INPUT); // Sets the echoPin as an Input
            Serial.begin(9600); // Starts the serial communication
            }

            void loop() {
            // Clears the trigPin
            digitalWrite(trigPin, LOW);
            delayMicroseconds(2);

            // Sets the trigPin on HIGH state for 10 micro seconds
            digitalWrite(trigPin, HIGH);
            delayMicroseconds(10);
            digitalWrite(trigPin, LOW);

            // Reads the echoPin, returns the sound wave travel time in microseconds
            duration = pulseIn(echoPin, HIGH);

            // Calculating the distance
            distance= duration*0.034/2;
            // Prints the distance on the Serial Monitor
            Serial.print("Distance: ");
            Serial.println(distance);
            delay(2000);
            }

            Comment


            • #7
              Yes, you need to remove the Serial.print and add a SendToHS(1,distance). as this is the value you want to see in HS. The only problem with this one is it uses Delay and this will stop the Arduino communicating. You need to replace all the Delays with something like what you had in the first sketch. See https://www.makeuseof.com/tag/arduin...-shouldnt-use/

              Greig.
              Zwave = Z-Stick, 3xHSM100 7xACT ZDM230, 1xEverspring SM103, 2xACT HomePro ZRP210.
              X10 = CM12U, 2xAM12, 1xAW10, 1 x TM13U, 1xMS13, 2xHR10, 2xSS13
              Other Hardware = ADI Ocelot + secu16, Global Cache GC100, RFXtrx433, 3 x Foscams.
              Plugings = RFXcom, ActiveBackup, Applied Digital Ocelot, BLDeviceMatrix, BLGarbage, BLLAN, Current Cost, Global Cache GC100,HSTouch Android, HSTouch Server, HSTouch Server Unlimited, NetCAM, PowerTrigger, SageWebcamXP, SqueezeBox, X10 CM11A/CM12U.
              Scripts =
              Various

              Comment


              • #8
                Thank you Greg for your help!

                Comment


                • #9
                  I need some help Greg...yet again... Not too sure about which/what serial.prints I should be deleting and what to be sending to hs. Does it do any harm to leave them?

                  I'm connected to hs. I have pin2 as an input in the plugin. opening a screen in the arduino IDE I can see which pin is touched, but I am getting nothing to change in the plugin on hs.
                  Attached Files

                  Comment


                  • #10
                    HI Mate

                    You probably should read the documentation and read the comments in the plugin. That will give you lots of guidance.....The serial prints send data out the arduino serial port, great for debugging however simply not needed as we are not using the serial port on the arduino.

                    SendToHS(1,distance) this is where all the magic happens, its the routine that sends the value to Homeseer.....Have you defined this in your homeseer plugin as a device ?

                    Pete
                    HS 2.2.0.11

                    Comment

                    Working...
                    X