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. Troubleshooting
  3. Combining relay and temperature sketch

Combining relay and temperature sketch

Scheduled Pinned Locked Moved Troubleshooting
76 Posts 9 Posters 14.2k Views 12 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.
  • rejoe2R Offline
    rejoe2R Offline
    rejoe2
    wrote on last edited by
    #67
    1. Wrt sending: your controller should show one temperature sensor with Child ID 10. As a consequence, the temp value should also be reported using this ID. So you should adopt this line appropriately, just use the same logic as in presentation() :grin: .
    send(msg.setSensor(i).set(temperature,1));
    
    1. For the non-blocking loop: As already mentionned, within this thread you just should follow @bluezr1 steps and some of my remarks :grinning: .
      The sketch in #63 should be a working solution, but when using dallas temp instead of the DHT, you have also to change the sleep(conversionTime) to wait().

    Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

    1 Reply Last reply
    0
    • pepsonP Offline
      pepsonP Offline
      pepson
      wrote on last edited by
      #68

      I am begginer. Can you give me ready sketch for dallas with one relay ? Please

      rejoe2R 1 Reply Last reply
      0
      • pepsonP pepson

        I am begginer. Can you give me ready sketch for dallas with one relay ? Please

        rejoe2R Offline
        rejoe2R Offline
        rejoe2
        wrote on last edited by
        #69

        @pepson Especially as a beginner you really should try to follow the necessary steps to develop combined sketches - it's easier than you may think by now.
        Otherwise you may run into the next unexpected trouble without any idea, how things fit together and - even more important - how to debug (or even where to attach what). So asking for ready sketches is not the best idea.

        If you are still convinced about the need of a ready sketch: There's - amongst others - a sketch with #101 using DS18B20 and 4 relays in my repo (link is already available in this thread). , BUT: this is work in progress, may use a modified version of the dallas lib and reports temperatures and relays under the same ChildID - my controller (FHEM) seems not to care about that...
        As I changed communication to RS485 last weekend, I most likely will not do any update, if there are issues or further enhancements on the code (I plan to do some).

        Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

        1 Reply Last reply
        0
        • pepsonP Offline
          pepsonP Offline
          pepson
          wrote on last edited by
          #70

          @rejoe2 said in Combining relay and temperature sketch:

          #10

          I try also ready sketch for only dallas fom mysensors.rg but it also not working:

          // Enable debug prints to serial monitor
          #define MY_DEBUG 
          
          // Enable and select radio type attached
          #define MY_RADIO_RFM69
          #define MY_RFM69_FREQUENCY RF69_868MHZ
          #define MY_IS_RFM69HW
          
          // Enabled repeater feature for this node
          #define MY_REPEATER_FEATURE
          
          // Node id defaults to AUTO (tries to fetch id from controller)
          #define MY_NODE_ID AUTO
          
          #include <SPI.h>
          #include <MySensors.h>  
          #include <DallasTemperature.h>
          #include <OneWire.h>
          
          #define COMPARE_TEMP 1 // Send temperature only if changed? 1 = Yes 0 = No
          
          #define ONE_WIRE_BUS 3 // Pin where dallase sensor is connected 
          #define MAX_ATTACHED_DS18B20 16
          unsigned long SLEEP_TIME = 30000; // Sleep time between reads (in milliseconds)
          OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
          DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. 
          float lastTemperature[MAX_ATTACHED_DS18B20];
          int numSensors=0;
          bool receivedConfig = false;
          bool metric = true;
          // Initialize temperature message
          MyMessage msg(0,V_TEMP);
          
          void before()
          {
            // Startup up the OneWire library
            sensors.begin();
          }
          
          void setup()  
          { 
            // requestTemperatures() will not block current thread
            sensors.setWaitForConversion(false);
          }
          
          void presentation() {
            // Send the sketch version information to the gateway and Controller
            sendSketchInfo("Temperature Sensor", "1.1");
          
            // Fetch the number of attached temperature sensors  
            numSensors = sensors.getDeviceCount();
          
            // Present all sensors to controller
            for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {   
               present(i, S_TEMP);
            }
          }
          
          void loop()     
          {     
            // Fetch temperatures from Dallas sensors
            sensors.requestTemperatures();
          
            // query conversion time and sleep until conversion completed
            int16_t conversionTime = sensors.millisToWaitForConversion(sensors.getResolution());
            // sleep() call can be replaced by wait() call if node need to process incoming messages (or if node is repeater)
            sleep(conversionTime);
          
            // Read temperatures and send them to controller 
            for (int i=0; i<numSensors && i<MAX_ATTACHED_DS18B20; i++) {
          
              // Fetch and round temperature to one decimal
              float temperature = static_cast<float>(static_cast<int>((getControllerConfig().isMetric?sensors.getTempCByIndex(i):sensors.getTempFByIndex(i)) * 10.)) / 10.;
          
              // Only send data if temperature has changed and no error
              #if COMPARE_TEMP == 1
              if (lastTemperature[i] != temperature && temperature != -127.00 && temperature != 85.00) {
              #else
              if (temperature != -127.00 && temperature != 85.00) {
              #endif
          
                // Send in the new temperature
                send(msg.setSensor(i).set(temperature,1));
                // Save new temperatures for next compare
                lastTemperature[i]=temperature;
              }
            }
            sleep(SLEEP_TIME);
          }```
          1 Reply Last reply
          0
          • rejoe2R rejoe2

            @pepson
            Imo there are several things to look at:

            1. Pin 3 seems to be used for button a + 1-wire? -> use a different one

            2. How many DS18B20 do you have attached?
              a) In case it's up to three, you try to report Relay and Temp info partly under the same Child_ID (1+2). Imo, it's better to chose a different starting Child ID, something like "present(i+10, S_TEMP)" or use a variable like "FIRST_TEMP_CHILD" (also use the same scheme for sending).
              b) You may also suffer from a wiring problem, if you are able to compile and flash this sketch. Just for testing you could add a debugg-message to serial with the numSensors

            3. Combining relays, debounced buttons and sleep() most likely will cause problems. Better use a non-blocking loop as described in post #45 and following.

            rejoe2R Offline
            rejoe2R Offline
            rejoe2
            wrote on last edited by
            #71

            @rejoe2 said in Combining relay and temperature sketch:

            b) You may also suffer from a wiring problem, if you are able to compile and flash this sketch. Just for testing you could add a debugg-message to serial with the numSensors

            Did you follow the instructions as described in the "build" section, attached the data line to PIN3 and used an appropriate resistor (measure it's value) ? Then it's most likely a damaged sensor...

            Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

            pepsonP 1 Reply Last reply
            0
            • rejoe2R rejoe2

              @rejoe2 said in Combining relay and temperature sketch:

              b) You may also suffer from a wiring problem, if you are able to compile and flash this sketch. Just for testing you could add a debugg-message to serial with the numSensors

              Did you follow the instructions as described in the "build" section, attached the data line to PIN3 and used an appropriate resistor (measure it's value) ? Then it's most likely a damaged sensor...

              pepsonP Offline
              pepsonP Offline
              pepson
              wrote on last edited by
              #72

              @rejoe2
              Yes i connected my sensors to PIN 3 and use resistor 4.7
              But in Domoticz on gateway not show any CHILDS for this NODE.

              rejoe2R 1 Reply Last reply
              0
              • pepsonP pepson

                @rejoe2
                Yes i connected my sensors to PIN 3 and use resistor 4.7
                But in Domoticz on gateway not show any CHILDS for this NODE.

                rejoe2R Offline
                rejoe2R Offline
                rejoe2
                wrote on last edited by
                #73

                @pepson Seems like the sensor is not detected, so the presentation() will have zero sensors to present...
                If you do not want to follow the proposal to print the numSensors to serial (most likely: 0) you should try to test the DS18B20-Hardware by using an example sketch (e.g. Simple.pde) from the dallas temperature lib (without the MySensors-framework) and have a look on the serial console of the IDE. Be aware: "as is", it uses PIN2 and a different baudrate.
                If there are no temperature values printed, it's either still a wiring problem or the sensor's just broken.

                Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                1 Reply Last reply
                0
                • MGHaffM Offline
                  MGHaffM Offline
                  MGHaff
                  wrote on last edited by
                  #74

                  Has anyone had any progress on sensor node with mysensors + multiple dallas temp sensors and multiple relays, combining the two codes? Any help would be greatly appreciated. I have been playing with this for a little more than a week, have tried everything suggested but still not working. A push in the right direction would be great!

                  1 Reply Last reply
                  0
                  • rejoe2R Offline
                    rejoe2R Offline
                    rejoe2
                    wrote on last edited by
                    #75

                    @mghaff said in Combining relay and temperature sketch:

                    Has anyone had any progress on sensor node with mysensors + multiple dallas temp sensors and multiple relays, combining the two codes?

                    Some older code; some rework might be necessary: https://github.com/rejoe2/MySensors_Small/blob/master/MyS101/MyS101.ino
                    There are some more DS18B20 examples in the repo, just have a look around...

                    Controller: FHEM; MySensors: 2.3.1, RS485,nRF24,RFM69, serial Gateways

                    MGHaffM 1 Reply Last reply
                    0
                    • rejoe2R rejoe2

                      @mghaff said in Combining relay and temperature sketch:

                      Has anyone had any progress on sensor node with mysensors + multiple dallas temp sensors and multiple relays, combining the two codes?

                      Some older code; some rework might be necessary: https://github.com/rejoe2/MySensors_Small/blob/master/MyS101/MyS101.ino
                      There are some more DS18B20 examples in the repo, just have a look around...

                      MGHaffM Offline
                      MGHaffM Offline
                      MGHaff
                      wrote on last edited by
                      #76

                      @rejoe2 Thanks! I will do that. the code i used was from the examples. My relays work fine but my temp sensors never register. Even in serial. but if i run the Dallas temp my-sensors code separate i always get reading. Its just been mind boggling. :)

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


                      9

                      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