Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. RelayWithButtonActuator..what if Vera is offline?

RelayWithButtonActuator..what if Vera is offline?

Scheduled Pinned Locked Moved General Discussion
17 Posts 5 Posters 5.1k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mitekg
    wrote on last edited by
    #4

    @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..

    1 Reply Last reply
    0
    • hekH Offline
      hekH Offline
      hek
      Admin
      wrote on last edited by
      #5

      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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mitekg
        wrote on last edited by
        #6

        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
        
        hekH 1 Reply Last reply
        0
        • M mitekg

          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
          
          hekH Offline
          hekH Offline
          hek
          Admin
          wrote on last edited by
          #7

          @mitekg

          Strange, the example works for me.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mitekg
            wrote on last edited by
            #8

            @hek
            did u try it on latest lib version?

            hekH 1 Reply Last reply
            0
            • M mitekg

              @hek
              did u try it on latest lib version?

              hekH Offline
              hekH Offline
              hek
              Admin
              wrote on last edited by
              #9

              @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.

              1 Reply Last reply
              0
              • greglG gregl

                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

                petewillP Offline
                petewillP Offline
                petewill
                Admin
                wrote on last edited by
                #10

                @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?

                My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

                1 Reply Last reply
                0
                • greglG Offline
                  greglG Offline
                  gregl
                  Hero Member
                  wrote on last edited by
                  #11

                  @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

                  petewillP 1 Reply Last reply
                  0
                  • BulldogLowellB BulldogLowell

                    @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
                    }

                    greglG Offline
                    greglG Offline
                    gregl
                    Hero Member
                    wrote on last edited by
                    #12

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

                    BulldogLowellB 1 Reply Last reply
                    0
                    • greglG gregl

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

                      BulldogLowellB Offline
                      BulldogLowellB Offline
                      BulldogLowell
                      Contest Winner
                      wrote on last edited by BulldogLowell
                      #13

                      @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.

                      1 Reply Last reply
                      0
                      • greglG gregl

                        @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

                        petewillP Offline
                        petewillP Offline
                        petewill
                        Admin
                        wrote on last edited by
                        #14

                        @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.

                        My "How To" home automation video channel: https://www.youtube.com/channel/UCq_Evyh5PQALx4m4CQuxqkA

                        1 Reply Last reply
                        0
                        • hekH hek

                          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.

                          greglG Offline
                          greglG Offline
                          gregl
                          Hero Member
                          wrote on last edited by
                          #15

                          @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

                          BulldogLowellB hekH 2 Replies Last reply
                          0
                          • greglG gregl

                            @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

                            BulldogLowellB Offline
                            BulldogLowellB Offline
                            BulldogLowell
                            Contest Winner
                            wrote on last edited by
                            #16

                            @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?

                            1 Reply Last reply
                            0
                            • greglG gregl

                              @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

                              hekH Offline
                              hekH Offline
                              hek
                              Admin
                              wrote on last edited by
                              #17

                              @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).

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              20

                              Online

                              11.7k

                              Users

                              11.2k

                              Topics

                              113.1k

                              Posts


                              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • MySensors
                              • OpenHardware.io
                              • Categories
                              • Recent
                              • Tags
                              • Popular