Announcement

Collapse
No announcement yet.

Basic problem with SendToHS(x,x)

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

  • Basic problem with SendToHS(x,x)

    I'm trying to get the the API to send data to HS3 using SendToHS(x,x)

    To keep it simple, I added just one instruction to the API sketch to send the value of 64 to device ref ID 1185 in the /*Execute regardless of connection status*/ section :

    SendToHS(1185,64);

    but in Homeseer I get this error message:
    Warning = Arduino, Board:2, API Input:161 does not exist. Please create the device first.
    I do have an API Input Device created with Ref ID 1185.

    I have no idea what the error referencing input 161 is telling me.

    Any ideas???


    Rick

  • #2
    Device number should be plugin device number, not HomeSeer device number. So, if it’s your first or only plugin device, it would be ‘1’.

    Mike

    Comment


    • #3
      Thanks for the information.
      I made the change to plugin device number "1" and it worked! No more error, and the device was loaded with the value 64.

      Next I changed the value to load in to the device to 16, then recompiled and loaded the sketch. But for some reason I had to re-load it several times before the device value was updated to 16. I again changed the value, and the same result where the device value doesn't change. I'm using the NodeMCU, and I do reset after the download, but I can't get it to consistently update the device value.

      Any suggestions?

      Rick

      Comment


      • #4
        This may be beyond my ability to help, but it may be something in your sketch. Posting your code might make it easier to see what you're trying to do.

        Mike

        Comment


        • #5
          One more piece of information.....I can get the device value to update (after i upload the new code) if I select the "disconnect" button, then select the "connect" button. Is this considered normal operation??

          Rick

          Comment


          • #6
            Originally posted by Rmasci64 View Post
            One more piece of information.....I can get the device value to update (after i upload the new code) if I select the "disconnect" button, then select the "connect" button. Is this considered normal operation??

            Rick
            Again, seeing your code might help, but, if I understand your question, I'd say no. I'm new to this plugin, but I have mine connected to hard-wired alarm system door sensors. I use the API version and my sketch monitors the input pins for the door sensors and then sends the state (0 or 1) to Homeseer IF it changes. I don't send it constantly as I believe it floods the interface. So, I only send it if there is a change. I go one step further and send info back from Homeseer to the Arduino to make sure the change occurred. All of this happens, of course, without disconnecting and reconnecting the plugin.

            Mike

            Comment


            • #7
              Ultimately what I'm trying to do is read the A/D (A0) input on the NodeMCU when input D0 goes low, then write that value to a Homeseer device.

              I've verified the A/D, and D0 part of the code. Now I'm just trying to get variable "voltage" value written to the Homeseer device. My code is below....may not be pretty as I just taught myself today how to do this. I also need to figure out a way to execute the loop below just once each time D0 goes low.

              I'm a HW guy, not SW......so comments are welcomed!


              int pin = digitalRead(inputPin);

              if (pin == 0) {

              int reading = analogRead(0);
              float voltage = reading / 204.6;
              Serial.print ("Reading=");
              Serial.print (reading);
              Serial.print ("\t\tVolts=");
              Serial.println (voltage);

              Serial.print ("Input State=");
              Serial.println(pin);

              SendToHS(1,voltage);

              }


              Thanks

              Rick

              Comment


              • #8
                It may indeed be that you are flooding the Homeseer plugin with too much data. As long as your input pin remains at '0', the SendToHS line will send on each loop of the sketch. What you want to do is only send it when it changes. So you need to create another variable where you can store the last pin state and then compare it to the current pin state to see if it has changed. If it has not changed, skip the SendToHS command. If it has changed, send the change to Homeseer. So, try something like this (not tested!):

                Code:
                int lastPinState;
                
                void setup() {
                
                }
                
                void loop() {
                
                    int pin = digitalRead(inputPin);
                
                /* only execute if pin changes */
                    if (pin != lastPinState) {
                        /* only SendToHS if pin is 0 */
                        if (pin == 0) {
                            int reading = analogRead(0);
                            float voltage = reading / 204.6;
                            Serial.print ("Reading=");
                            Serial.print (reading);
                            Serial.print ("\t\tVolts=");
                            Serial.println (voltage);
                
                            Serial.print ("Input State=");
                            Serial.println(pin);
                
                            SendToHS(1,voltage);
                        }
                        /* reset the lastPinState */
                        lastPinState = pin;
                    }
                    /* pause for 50 milliseconds for pin bouncing and so you don't flood the Homeseer plugin
                    delay(50); // debounce
                }

                Comment


                • #9
                  Mike;

                  Thank you for all your help!

                  I understand what you are suggesting about flooding the plugin with too much data.

                  Thinking about it some more, maybe there is a better way to trigger the loop to read / send the data, rather than using a switch on D0.
                  I was thinking of using an API Output Device the plugin can create..... if I understand it correctly. I was thinking that setting or clearing the API Output Device device in HS3, would set or clear one of the digital output on the Arduino. But I can't seem to find which Arduino output the HS3 device controls. Is this how the API Output Device works?? Is there some code I need to add to the sketch to accept/receive the information from HS3??

                  If I can use the API Output device to trigger the loop, then I don't have to debounce the signal.....and it would work better in my overall application.

                  Thank you for your time

                  Rick

                  Comment


                  • #10
                    OK, I found my answer concerning the API Output devices. My understanding was incorrect. I found this explanation in another post:

                    To Receive Data from Homeseer use FromHS(Device) this is an array of the values of your output devices in Homeseer. You can then do what you want with the value. Eg.. digitalWrite(MyPin, FromHS[5]); would set MyPin to the same value as API Output device 5


                    Since I'm not a SW guy, I don't completely understand what I have to do. Is the parameter "(Device)" the output device number, i.e the first Output Device is "0" ??
                    Could someone post a sample sketch with that receives data from HS3 which I can dissect and learn from??


                    Rick

                    Comment


                    • #11
                      I got it to work....sort of.

                      When I try the digitalWrite command (see below) it doesn't get the HS3 device value.
                      digitalWrite(MyPin,FromHS[0]);

                      But if I set the MyPin variable equal to the specific array element, it works.
                      MyPin = FromHS[0];

                      Not sure why, but I can make this work for now.


                      Thanks for your help

                      Rick

                      Comment


                      • #12
                        My application (monitoring alarm door sensors) needs the debounce since they are physical switches, but yours certainly may not.

                        I think you are very close to understanding how it works. The Arduino plugin allows you to create input devices and output devices. For input devices, the Arduino sketch sends data to the Homeseer device to change its state, etc. If you want to send data to the Arduino sketch, you need to create an output device in the plugin, which will create another Homeseer device. And, yes, output devices are numbered starting at 0 (input devices starting at 1). Each time a Homeseer output device changes state, the plugin sends that data to the Arduino sketch and stores it in the FromHS[] array. Your sketch, then, has to watch for that change.

                        So, in your sample code above, instead of monitoring the digital input pin, you would monitor the FromHS[0] array value. Does that make sense?

                        Mike

                        Comment


                        • #13
                          Originally posted by Rmasci64 View Post
                          I got it to work....sort of.

                          When I try the digitalWrite command (see below) it doesn't get the HS3 device value.
                          digitalWrite(MyPin,FromHS[0]);

                          But if I set the MyPin variable equal to the specific array element, it works.
                          MyPin = FromHS[0];

                          Not sure why, but I can make this work for now.


                          Thanks for your help

                          Rick
                          This doesn't make sense to me. The FromHS[0] is the 'value' of the Homeseer device. MyPin is the Arduino output pin. This statement - digitalWrite(MyPin,FromHS[0]);, means set the pin (MyPin) to the value of FromHS[0]. Why would you set MyPin to the value of FromHS[0]?

                          Mike

                          Comment


                          • #14
                            "MyPIn" is just a variable name I grabbed from the example I found from the plugin's author:

                            digitalWrite(MyPin, FromHS[5])

                            What I am trying to do is assign the value of FromHS[0] to another variable....in this case the variable is named "MyPin". Is that a reserved name Adruino??

                            The "MyPin = FromHS[0];" instruction does work....just trying to understand why the digitalWrite didn't.


                            Rick

                            Comment


                            • #15
                              In your example, the MyPin variable holds the Arduino pin number, not the value that you want to send to the pin.

                              Mike

                              Comment

                              Working...
                              X