RelayWithButtonActuator..what if Vera is offline?


  • Hero Member

    Hi all,

    Im actually trying to work on another sketch ( my heater project) but i think my question and hopefully the answer can better be explained using the RelayWithButtonActuator sketch as an example...

    so.. looking at the RelayWithButtonActuator sketch... say you are using this to switch on/off a light. You can use a button or control via Vera..but..
    What if vera is offline/uncontactable?

    How does the sketch need to be changed so the Relay can be toggled with the button? and when vera does come online get the arduino to send the current status to vera ( so it doesnt turn it off again)

    ( Ive been trying to work this out but ive confused the sh*t out of myself and now my brain hurts! ) - im sure its straightforward for someone who know this stuff!

    Also,.. can someone explain the logic here:
    digitalWrite(RELAY_PIN, state==1?RELAY_ON:RELAY_OFF);
    Is it saying "if state = 1 then toggle?

    Cheers,
    Greg


  • Contest Winner

    @gregl said:

    Hi all,

    Im actually trying to work on another sketch ( my heater project) but i think my question and hopefully the answer can better be explained using the RelayWithButtonActuator sketch as an example...

    so.. looking at the RelayWithButtonActuator sketch... say you are using this to switch on/off a light. You can use a button or control via Vera..but..
    What if vera is offline/uncontactable?

    How does the sketch need to be changed so the Relay can be toggled with the button? and when vera does come online get the arduino to send the current status to vera ( so it doesnt turn it off again)

    ( Ive been trying to work this out but ive confused the sh*t out of myself and now my brain hurts! ) - im sure its straightforward for someone who know this stuff!

    Also,.. can someone explain the logic here:
    digitalWrite(RELAY_PIN, state==1?RELAY_ON:RELAY_OFF);
    Is it saying "if state = 1 then toggle?

    Cheers,
    Greg

    I haven't tried this one but the expression is the c ternary operator combined with the digitalWrite command.

    digitalWrite(RELAY_PIN, state==1?RELAY_ON:RELAY_OFF);

    is C 'shorthand' for:

    If (state==1){
    digitalWrite(RELAY_PIN,RELAY_ON); //turn pin HIGH
    }
    else{
    digitalWrite(RELAY_PIN,RELAY_OFF); //turn pin LOW
    }


  • Admin

    This is actually a good (philosophical) question. Who should own the relay status?

    Right now the status information is only permanently stored in the controller and relay will fetch current relay-status from controller/vera at startup. It will retry forever until something answer this request for status.

    Another option is to store current status in EEPROM and send this to controller at startup or when user toggles status locally (or a command from controller is sent to the relay-node) to set a specific status. I would probably prefer this for a permanent solution. This way you can always toggle status locally and status is remembered even if controller is down and someone cuts the power to the arduino.

    One thing to remember is that the eeprom only has about 100,000 write/erase cycles.



  • @hek ,
    in void setup(), there is:
    gw.getStatus(RELAY_1+i, V_LIGHT);
    setRelayStatus(gw.getMessage()); // Wait here until status message arrive from gw

    is it everiything ok here?
    As i understand getStatus, return a status, but "setRelayStatus" wait for a message.. and didn't get it..


  • Admin

    getStatus sends an request to controller for a specific value. It will repeat this request until controller sends an answer that reaches the node. If none answer the program will wait here forever.

    You can alos use requestStatus which just sends the request but does not busy-wait for the answer.

    setRelayStatus is defined in the sketch and it updates the output pins to attached relay based on incoming message.



  • thx, @hek

    i see, BUT
    gw.getStatus(RELAY_1+i, V_LIGHT); - return the real value in char.

    gw.getMessage() didnt return any message!
    so i cant set an initial state of relays!
    For me now working code is:
    // Request/wait for relay status
    int status = atoi(gw.getStatus(RELAY_1 + i, V_LIGHT));
    setRelayStatus(RELAY_1 + i, status);

    	//message_s message = gw.getMessage();
    	//setRelayStatus(message); // Wait here until status message arrive from gw

  • Admin

    @mitekg

    Strange, the example works for me.



  • @hek
    did u try it on latest lib version?


  • Admin

    @mitekg

    Ah.. .I think I know... Darn.. there was a "bugfix" done some weeks ago in the RelayActuator. This might have broken the functionality.

    Try removing

    message.header.messageType==M_SET_VARIABLE && 
    

    from the if-statement in setRelayStatus.


  • Admin

    @gregl

    Funny, I was just working on something like this and I was wondering the same thing. My project is a little different in that I want to shut down a power supply if the temperature gets too high. Here's a little quick background to help you better understand my goal... I made a power supply out of a computer power supply to provide 12v, 5v and 3.3v current to my various sensors around the house. I'm a little nervous about leaving it running 24/7 and how hot it may get. So, I thought, why not use HEK's awesome sensors to add an overheat safety control. The thing is, I need to be able to shut it down with the attached DHT22 sensor in case the connection ever goes out between Vera and the child device. I'm thinking I'll have to modify the RelayWithButtonActuator code like this:

    1. Remove "gw.getStatus(CHILD_ID, V_LIGHT);" from setup() so it doesn't wait here when it first starts

    2. Change the button push if statment so it will immediately change the state of the relay then send an update to Vera
      if (buttVal == HIGH && switched == 0 && millis() - pressTime > debounce) {
      // Switch state if button pressed more than 200 msec
      state = state==1?0:1;
      gw.sendVariable(CHILD_ID, V_LIGHT, state); //change this code here
      switched = 1; // No more switches until button is released
      }
      Is this ok to do this way?

    3. Write another if statement that will check for the temperature of the DHT sensor and shut off the relay if it's too hot then send update to Vera.

    Thoughts?


  • Hero Member

    @petewill said:

    s a little quick background to help you better understand my goal... I made a power supply out of a computer power supply to provide 12v, 5v and 3.3v current to my various sensors around the house. I'm a little nervous about leaving it running 24/7 and how hot it may get. So, I thought, why not use HEK's awesome sensors to add an overheat safety control. The thing is, I need to be able to shut it down with the attached DHT22 sensor in case the connection ever goes out between Vera and the child device. I'm thinking I'll have to modify the RelayWithButtonActuator code like this:

    Hi Pete,

    Personally if i was worried about the powersupply getting too hot, then id be using a simple passive device rather than relying on my dodgy code..something like this: http://www.jaycar.com.au/productView.asp?ID=ST3821 The powersupply will likely already contain some protection...

    that said, unless you are doing something really dodgy, i doubt even a houseful of sensors will put more than a few amps of load on the powersupply, causing it to get hot. Unless of course there is a fault/short in your wiring! But if you are running cable around your house to power all these sensors from a central powersupply you will be using some fuses to protect the powersupply or worse...a fire starting. Better still some DC breakers like: http://www.jaycar.com.au/productView.asp?ID=SF2295

    But...since we love this stuff...sure put a thermometer there to monitor your p/s temp...but more exciting (imho) would be to put some current sensors on each line to see what sort of current you are drawing:
    http://www.ebay.com/itm/ACS712-20A-range-Current-Sensor-Module-Module-for-Arduino-Raspberry-pi

    Greg


  • Hero Member

    @BulldogLowell Thanks mate.
    Makes more sense now.... ill try to use it to help i sink in!


  • Contest Winner

    @gregl

    you will get there. Practice and making mistakes are key to learning a new language, spoken or computer.

    FYI a great (but pricey) book is "Beginning C for Arduino"

    perhaps your local library can get it for you. I'm lucky, we have a terrific, very well connected library and I can get almost any book for $1.00 for a month.


  • Admin

    @gregl said:

    Personally if i was worried about the powersupply getting too hot, then id be using a simple passive device rather than relying on my dodgy code..something like this: http://www.jaycar.com.au/productView.asp?ID=ST3821 The powersupply will likely already contain some protection...

    that said, unless you are doing something really dodgy, i doubt even a houseful of sensors will put more than a few amps of load on the powersupply, causing it to get hot. Unless of course there is a fault/short in your wiring! But if you are running cable around your house to power all these sensors from a central powersupply you will be using some fuses to protect the powersupply or worse...a fire starting. Better still some DC breakers like: http://www.jaycar.com.au/productView.asp?ID=SF2295

    But...since we love this stuff...sure put a thermometer there to monitor your p/s temp...but more exciting (imho) would be to put some current sensors on each line to see what sort of current you are drawing:
    http://www.ebay.com/itm/ACS712-20A-range-Current-Sensor-Module-Module-for-Arduino-Raspberry-pi

    Greg

    Wow, I didn't even think of a thermal fuse. That's a fantastic idea! Good call on the current monitoring too! I don't have the time for it now but will definitely consider it for the future. I do have everything running through fuses. Hopefully all this won't be necessary but you can never be too safe.


  • Hero Member

    @hek
    Hi Hek,

    Personally i think the owner should be the RelayActuator. Also i dont think the status needs to be "saved" between sketch restart...obviously this could be an option.

    I'm thinking of a use case where the sketch would be doing the same job as a zwave light controller ( aeon/fibraro ) -these operate independant of Vera, but will obviously accept commands and tell vera any updates made locally, but i dont believe they ask Vera what was my last status when they reboot? ( or am i wrong?) -too late to test /play with mains voltage for me!

    Cheers, Greg


  • Contest Winner

    @gregl

    this seems safer to me but is it consistent with the switch paradigm for vera?

    what happens if you switch a zwave wall outlet and vera is off, but went off in the ON state?


  • Admin

    @gregl

    Yep, agree..
    Distribute logic as far as possible out in the actuator-grid.
    So I would opt in for "remembering" the state in case of power-fail.. That is how I've configured all my z-wave devices and works like old "dumb" switches (=high WAF).


Log in to reply
 

Suggested Topics

  • 4
  • 8
  • 9
  • 2
  • 9
  • 15

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts