Announcement

Collapse
No announcement yet.

Basic problem with SendToHS(x,x)

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

  • bdraper
    replied
    This is a picture of the an Arduino configuration page using an API sketch. The SendToHS uses the "Input No" column on this screen This sends the data from the Arduino pin back to the HomeSeer device. The SendToHS does not use the HomeSeer device ref number, but the "Input No" below...

    Hope this helps.

    Click image for larger version

Name:	Annotation 2019-05-04 073013.jpg
Views:	15
Size:	123.6 KB
ID:	1302927

    Leave a comment:


  • Andre221164
    replied
    Thanks a lot,that could help me

    Leave a comment:


  • Rmasci64
    replied
    Andre;

    Below is a sample of my code to write to the API.
    The command is "SendToHS(1,reading)" where "1" is plugin device number, not the HS3 device number.



    if (Convert == 255){
    if (count == 0){
    for (i=0; i<1; i++){

    int reading = analogRead(0);

    Serial.print ("Reading=");
    Serial.print (reading);

    SendToHS(1,reading);

    count ++;
    }

    }
    }

    Leave a comment:


  • Andre221164
    replied
    Hello,
    How to you write the result to the API Output Device?
    Do you have an Example?

    Andre

    Leave a comment:


  • Mike Johnson
    replied
    You’re welcome. Glad you got it working. Sounds like a cool project and a great use of HomeSeer!

    Mike

    Leave a comment:


  • Rmasci64
    replied
    I got all to work!

    I'm posting the code here if anyone is interested. It's nothing fancy....but for other code newbies it might be helpful.

    In summary the code runs once when triggered by the the API Input device "Convert", when it = 255.
    Once triggered the NodeMCU converts the A/D input, then writes the result to the API Output Device.

    With this code (along with a load cell strain gauge), I can now measure the weight of the propane tank on my gas grill. From that measured analog value, I'll create a gas gauge type display (Jon00 Dashboard add on) in HS touch to display the propane tank level. In addition, when the tank is near empty an email will be sent to remind me to fill the tank!

    Mike; thank you for all your help!!

    Rick


    ------------------------------------------------------------
    Convert = FromHS[0];

    if (Convert == 0){
    count=0;
    }

    if (Convert == 255){
    if (count == 0){
    for (i=0; i<1; i++){

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

    SendToHS(1,voltage);


    count ++;
    }

    }
    }

    Leave a comment:


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

    Mike

    Leave a comment:


  • Rmasci64
    replied
    "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

    Leave a comment:


  • Mike Johnson
    replied
    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

    Leave a comment:


  • Mike Johnson
    replied
    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

    Leave a comment:


  • Rmasci64
    replied
    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

    Leave a comment:


  • Rmasci64
    replied
    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

    Leave a comment:


  • Rmasci64
    replied
    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

    Leave a comment:


  • Mike Johnson
    replied
    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
    }

    Leave a comment:


  • Rmasci64
    replied
    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

    Leave a comment:

Working...
X