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. Controllers
  3. Domoticz
  4. relay as a switch not as a button (domoticz)

relay as a switch not as a button (domoticz)

Scheduled Pinned Locked Moved Domoticz
25 Posts 4 Posters 5.7k Views 6 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.
  • A Offline
    A Offline
    ago1980
    wrote on last edited by
    #1

    Hi,
    I need help for the 'relay Switch' code.
    you can help with this code, I would like to use relay as a switch not as a button .
    (I'm Italian, I'm sorry for the bad English).
    thanks to you.

    dbemowskD 1 Reply Last reply
    0
    • A ago1980

      Hi,
      I need help for the 'relay Switch' code.
      you can help with this code, I would like to use relay as a switch not as a button .
      (I'm Italian, I'm sorry for the bad English).
      thanks to you.

      dbemowskD Offline
      dbemowskD Offline
      dbemowsk
      wrote on last edited by
      #2

      @ago1980 Help us understand your question a little better. I am not sure what you mean by use the relay as a switch. What kind of switch?

      Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
      Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

      A 1 Reply Last reply
      0
      • dbemowskD dbemowsk

        @ago1980 Help us understand your question a little better. I am not sure what you mean by use the relay as a switch. What kind of switch?

        A Offline
        A Offline
        ago1980
        wrote on last edited by
        #3

        @dbemowsk hello I mean switches from classics from home. Thanks

        Boots33B 1 Reply Last reply
        0
        • A ago1980

          @dbemowsk hello I mean switches from classics from home. Thanks

          Boots33B Offline
          Boots33B Offline
          Boots33
          Hero Member
          wrote on last edited by
          #4

          Hi @ago1980 Is it the RelayWithButtonActuator sketch you are looking to modify so it can be used with a toggle switch instead of a push button?

          A 1 Reply Last reply
          0
          • Boots33B Boots33

            Hi @ago1980 Is it the RelayWithButtonActuator sketch you are looking to modify so it can be used with a toggle switch instead of a push button?

            A Offline
            A Offline
            ago1980
            wrote on last edited by
            #5

            @Boots33 I would like to use with switch, I find nothing on.

            Boots33B 1 Reply Last reply
            0
            • A ago1980

              @Boots33 I would like to use with switch, I find nothing on.

              Boots33B Offline
              Boots33B Offline
              Boots33
              Hero Member
              wrote on last edited by
              #6

              @ago1980 You can find the relay with button sketch Here

              That sketch uses a push button, to use that sketch with a toggle switch you should just need to make a couple of small changes in the loop part of the sketch.

              void loop() 
              {
                debouncer.update();
                // Get the update value
                int value = debouncer.read();
              
                /*
                if (value != oldValue && value==0) {
                    send(msg.set(state?false:true), true); // Send new state and request ack back
                }
                oldValue = value;
               */
              
              if (value != oldValue) {
                    send(msg.set(state?false:true), true); // Send new state and request ack back
                    oldValue = value;
                } 
              } 
              
              A 1 Reply Last reply
              0
              • Boots33B Boots33

                @ago1980 You can find the relay with button sketch Here

                That sketch uses a push button, to use that sketch with a toggle switch you should just need to make a couple of small changes in the loop part of the sketch.

                void loop() 
                {
                  debouncer.update();
                  // Get the update value
                  int value = debouncer.read();
                
                  /*
                  if (value != oldValue && value==0) {
                      send(msg.set(state?false:true), true); // Send new state and request ack back
                  }
                  oldValue = value;
                 */
                
                if (value != oldValue) {
                      send(msg.set(state?false:true), true); // Send new state and request ack back
                      oldValue = value;
                  } 
                } 
                
                A Offline
                A Offline
                ago1980
                wrote on last edited by
                #7

                @Boots33 ok, but then the status is updated Domoticz?
                thank you

                Boots33B 1 Reply Last reply
                0
                • A ago1980

                  @Boots33 ok, but then the status is updated Domoticz?
                  thank you

                  Boots33B Offline
                  Boots33B Offline
                  Boots33
                  Hero Member
                  wrote on last edited by
                  #8

                  @ago1980 Yes it should still update the status in domoticz when you use the switch.

                  A 1 Reply Last reply
                  0
                  • Boots33B Boots33

                    @ago1980 Yes it should still update the status in domoticz when you use the switch.

                    A Offline
                    A Offline
                    ago1980
                    wrote on last edited by
                    #9

                    @Boots33 ok, tomorrow I try and let me know. Thanks so much

                    1 Reply Last reply
                    0
                    • dbemowskD Offline
                      dbemowskD Offline
                      dbemowsk
                      wrote on last edited by
                      #10

                      I recently explained how to do this in this thread. https://forum.mysensors.org/topic/7849/relay-control-bistable-switch-instead-of-monostable/3

                      Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                      Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                      A 1 Reply Last reply
                      0
                      • dbemowskD dbemowsk

                        I recently explained how to do this in this thread. https://forum.mysensors.org/topic/7849/relay-control-bistable-switch-instead-of-monostable/3

                        A Offline
                        A Offline
                        ago1980
                        wrote on last edited by
                        #11

                        @dbemowsk ok thanks clear code explanation, but I did not understand well what to do to hardware part.

                        dbemowskD 1 Reply Last reply
                        0
                        • A ago1980

                          @dbemowsk ok thanks clear code explanation, but I did not understand well what to do to hardware part.

                          dbemowskD Offline
                          dbemowskD Offline
                          dbemowsk
                          wrote on last edited by
                          #12

                          @ago1980 So in the diagram below I show a wall switch and the push button switch that is normally used in this example. Simply remove the push button and attach the wall switch.
                          0_1509027939025_upload-89cb12d2-1378-4196-9fcd-93a24c352da6

                          Does this clear up the confusion?

                          Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                          Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                          A 1 Reply Last reply
                          0
                          • dbemowskD dbemowsk

                            @ago1980 So in the diagram below I show a wall switch and the push button switch that is normally used in this example. Simply remove the push button and attach the wall switch.
                            0_1509027939025_upload-89cb12d2-1378-4196-9fcd-93a24c352da6

                            Does this clear up the confusion?

                            A Offline
                            A Offline
                            ago1980
                            wrote on last edited by ago1980
                            #13

                            @dbemowsk So you just have to remove the button and put the switch on? or put the switch in parallel with the button?Thank you

                            dbemowskD 2 Replies Last reply
                            0
                            • A ago1980

                              @dbemowsk So you just have to remove the button and put the switch on? or put the switch in parallel with the button?Thank you

                              dbemowskD Offline
                              dbemowskD Offline
                              dbemowsk
                              wrote on last edited by
                              #14

                              @ago1980 Yes. If you use the switch, you will need to use the code changes that I pointed out in the other thread.

                              Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                              Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                              1 Reply Last reply
                              0
                              • A ago1980

                                @dbemowsk So you just have to remove the button and put the switch on? or put the switch in parallel with the button?Thank you

                                dbemowskD Offline
                                dbemowskD Offline
                                dbemowsk
                                wrote on last edited by
                                #15

                                @ago1980 With the switch in place you don't want to run it in parallel with the button. When the switch is in the on position, the connection will be shorted in which case the push button would not work. This is the reason for the code change. It is to detect when the switch changed from off to on, or on to off.

                                Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                                Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  ago1980
                                  wrote on last edited by
                                  #16

                                  I have a problem when the radio nrf24l01 loses contact with the gateway does not work the node, how can I do? thank you

                                  dbemowskD 1 Reply Last reply
                                  0
                                  • A ago1980

                                    I have a problem when the radio nrf24l01 loses contact with the gateway does not work the node, how can I do? thank you

                                    dbemowskD Offline
                                    dbemowskD Offline
                                    dbemowsk
                                    wrote on last edited by
                                    #17

                                    @ago1980 DO you have a capacitor on the nRF radio? How far away from the gateway is the node? Is there anything in between the gateway and the node such as windows or walls? If it is really far from the gateway, you will probably need a repeater node in between.

                                    Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                                    Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                                    A 1 Reply Last reply
                                    0
                                    • dbemowskD dbemowsk

                                      @ago1980 DO you have a capacitor on the nRF radio? How far away from the gateway is the node? Is there anything in between the gateway and the node such as windows or walls? If it is really far from the gateway, you will probably need a repeater node in between.

                                      A Offline
                                      A Offline
                                      ago1980
                                      wrote on last edited by
                                      #18

                                      @dbemowsk I mean if GATEWAY does not work for some problem the node does not work does not turn on light

                                      dbemowskD Boots33B 2 Replies Last reply
                                      0
                                      • A ago1980

                                        @dbemowsk I mean if GATEWAY does not work for some problem the node does not work does not turn on light

                                        dbemowskD Offline
                                        dbemowskD Offline
                                        dbemowsk
                                        wrote on last edited by
                                        #19

                                        @ago1980 Are you sure the problem is with the gateway? Can you post pictures of your node and your gateway? Having those will allow us to help you better.

                                        Vera Plus running UI7 with MySensors, Sonoffs and 1-Wire devices
                                        Visit my website for more Bits, Bytes and Ramblings from me: http://dan.bemowski.info/

                                        1 Reply Last reply
                                        0
                                        • A ago1980

                                          @dbemowsk I mean if GATEWAY does not work for some problem the node does not work does not turn on light

                                          Boots33B Offline
                                          Boots33B Offline
                                          Boots33
                                          Hero Member
                                          wrote on last edited by
                                          #20

                                          @ago1980 said in relay as a switch not as a button (domoticz):

                                          I mean if GATEWAY does not work for some problem the node does not work does not turn on light

                                          The original sketch relies on an ack from the gateway to trigger the relay, so if the gateway is not available the relay state cannot be changed by the local switch or even the controller.

                                          Under most circumstances it would be desirable to have the local switch function no matter what the state of the network is. To do this you will need to modify the sketch so it no longer relies on the ack to make the change.

                                          In MySensors 2.1.1 by default a node will not boot through to the loop section of your sketch if it cannot find the gateway, so the first thing you need to do is force it to move on.

                                          The line shown below will do just that. The number at the end is how long you want the node to wait for an uplink to be established before it will move on to the rest of your sketch. It is in milliseconds, so in the example below it will wait 5 seconds. This line needs to be inserted near the top of your sketch before the #include <MySensors.h> line.

                                          #define MY_TRANSPORT_WAIT_READY_MS 5000

                                          After adding that you will then need to change the sketch so it no longer relies on the ack to change the relay state. that is pretty straight forward and once done your relay will then be able to be switched by the local switch no mater what the uplink status is.

                                          The next problem you will encounter is trying to keep your controller in sync with the local node. As you can now change the state of the relay without a connection to the controller it may loose its sync to the node. So you may find your controller thinks the relay is on when it is actually off. This is where it gets a little trickier so if it is important to you that the controller stays in sync you may need to experiment a bit to find what will give you the best results.

                                          I have some examples of relay nodes that explore ways to switch locally and try to maintain sync with the controller.
                                          The last sketch I posted there uses requestTime() to check to see if the controller is available and though there is a trade off in how quickly you can flick the switch back and forward it at least confirms that the controller is available. Other methods may only check for the gateways presence.

                                          Have a look you may find something of use.

                                          Synchronising Light switch

                                          Its a bit of an old post but some of these issues (using a toggle switch and making the switch always work) were also discussed in this post

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


                                          19

                                          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