Skip to content
  • 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. Announcements
  3. 💬 Temperature Sensor
  • Getting Started
  • Controller
  • Build
  • Hardware
  • Download/API
  • Forum
  • Store

💬 Temperature Sensor

Scheduled Pinned Locked Moved Announcements
171 Posts 40 Posters 54.7k Views 36 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.
  • gohanG Offline
    gohanG Offline
    gohan
    Mod
    wrote on last edited by
    #161

    Have you tried another controller like mycontroller?

    cashew75C 1 Reply Last reply
    0
    • gohanG gohan

      Have you tried another controller like mycontroller?

      cashew75C Offline
      cashew75C Offline
      cashew75
      wrote on last edited by
      #162

      @gohan No I have not. I have a RF-Link also connected to the HA and it's working great. As I said, if I use the same hardware that I used to control the Dallas sensor and change the sensor to a DHT sensor the DHT sensor is accepted by HA and shows up as a sensor. That's why I was asking if there is something in the code for the Temperature sensor sketch that has to be changed to be able to present it to HA.

      1 Reply Last reply
      0
      • gohanG Offline
        gohanG Offline
        gohan
        Mod
        wrote on last edited by
        #163

        pls post the code that is not working

        cashew75C 1 Reply Last reply
        0
        • gohanG gohan

          pls post the code that is not working

          cashew75C Offline
          cashew75C Offline
          cashew75
          wrote on last edited by
          #164

          @gohan Thanks for the quick reply! Well I've use the standard sketch for this Temperatur sensor. This is the code i've got.

          // Enable debug prints to serial monitor
          //#define MY_DEBUG 
          
          // Enable and select radio type attached
          #define MY_RADIO_NRF24
          //#define MY_RADIO_RFM69
          
          #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
          • pepsonP Offline
            pepsonP Offline
            pepson
            wrote on last edited by
            #165

            Anybody has sketch for sensors dallas DS18b20 with identify it with ID Dallas ?
            And i can change value 16 to more sensors ? Example 20 ?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              APL2017
              wrote on last edited by
              #166

              Looking at code example it seems to be sufficient to set bool metric = false to get readings in Fahrenheit, but node still returns readings in C. Any idea why?

              mfalkviddM 1 Reply Last reply
              0
              • A APL2017

                Looking at code example it seems to be sufficient to set bool metric = false to get readings in Fahrenheit, but node still returns readings in C. Any idea why?

                mfalkviddM Offline
                mfalkviddM Offline
                mfalkvidd
                Mod
                wrote on last edited by
                #167

                @apl2017 if I'm looking at the same sketch as you are looking at, the metric variable is never used. getControllerConfig() is used to fetch the controller's metric setting instead.

                1 Reply Last reply
                0
                • R Rene046

                  I sofar got the sketch running and giving good data on serial and into domoticz

                  i only could use some help with how to sent my Temperature in Celsius to domoticz to
                  i tried to use:
                  send(msgTemp.set(insideThermometer ,2));
                  and
                  send(msgTemp.set(tempC,2));

                  both without luck, the first did transmit some data but wrong numbers
                  second did nothing think because with this i done i does not know what address the DS1820 is on.

                  Im learning every day something new....

                  Maybe someone could help,

                  G Offline
                  G Offline
                  gniazdoj
                  wrote on last edited by
                  #168

                  @Rene046
                  Hi guys

                  Hi
                  can you advice how to manage Domoticz to display 2 decimals under Temperature sensors page, when following line MsgTemp.set(temperature,2) I can see on arduino serial monitor, mysensors sent 20.75 value, the same value i can see under child item with Hardware tab but not on sensor where 20.75*C is rounded to 20.8. its fine for general log but i want to have stable temperature for heating system. I have added code to count average from last X records like 20 or 40 with 0.25 steps, this stabilize Heating system and protect it against on/off to frequently.
                  Additionally when i use JSON it will present proper value under sensor page, same with ESPEasy and 2 decimal configuration on ESP.
                  do you know how i can changed domoticz to force him to present 2 decimals?

                  Mysensors 2.3.1/2.3.2
                  Domoticz 4.10717
                  raspberry pi

                  Thank you
                  Jakub

                  K 1 Reply Last reply
                  1
                  • G gniazdoj

                    @Rene046
                    Hi guys

                    Hi
                    can you advice how to manage Domoticz to display 2 decimals under Temperature sensors page, when following line MsgTemp.set(temperature,2) I can see on arduino serial monitor, mysensors sent 20.75 value, the same value i can see under child item with Hardware tab but not on sensor where 20.75*C is rounded to 20.8. its fine for general log but i want to have stable temperature for heating system. I have added code to count average from last X records like 20 or 40 with 0.25 steps, this stabilize Heating system and protect it against on/off to frequently.
                    Additionally when i use JSON it will present proper value under sensor page, same with ESPEasy and 2 decimal configuration on ESP.
                    do you know how i can changed domoticz to force him to present 2 decimals?

                    Mysensors 2.3.1/2.3.2
                    Domoticz 4.10717
                    raspberry pi

                    Thank you
                    Jakub

                    K Offline
                    K Offline
                    kimot
                    wrote on last edited by
                    #169

                    Domoticz globally or only with MySensors ?
                    My Domoticz is the same version like yours.
                    Temperatures from ESPeasy are with two decimals on Temperature sensors page, but on devices page only one decimal.
                    Exactly the opposite like you wrote.

                    G 1 Reply Last reply
                    0
                    • K kimot

                      Domoticz globally or only with MySensors ?
                      My Domoticz is the same version like yours.
                      Temperatures from ESPeasy are with two decimals on Temperature sensors page, but on devices page only one decimal.
                      Exactly the opposite like you wrote.

                      G Offline
                      G Offline
                      gniazdoj
                      wrote on last edited by gniazdoj
                      #170

                      @kimot
                      Hi
                      Thank you for feedback.
                      I have this issue only with mysensors. it's exactly like you wrote. Hardware tab, present 2 decimals ( for mysensors and espeasy). Device tab, present 1 decimal ( for all sensors), Temperature tab shows 2 decimal for esp easy and JSON updates but 1 decimal for mysensor. Not sure why.

                      Temporary I managed to workaround by using script taking data from Hardware page - child and sending JSON update all started by crone updating dummy sensor.

                      like this:

                      TEMP=`curl -s "http://X.X.X.X:XX/json.htm?type=command&param=mysensorsgetchilds&idx=40&nodeid=0"| awk 'NR>1{print $5}'| sed 's/"//g;s/^.//;s/)//g; s/,//g;/^$/d;s/]//g;' | sed -n '3,2p'`
                      IDX=255
                      curl -s "http://X.X.X.X:XX/json.htm?type=command&param=udevice&idx=$IDX&nvalue=0&svalue=$TEMP"
                      

                      but for sure this can be workaround by dzVents and JSON handling results but i'm not skilled enough for that :)

                      Thank you
                      Jakub

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        garubi
                        wrote on last edited by
                        #171

                        The note before the example sketch states that you should use the "modified" library from MySensors examples.
                        But as of today, with MySensors 2.3.2 and Arduino 1.8.15 I used the standard DallasTemperature library (provided by the Arduino's Libraries manger) with no problems at all.

                        Using the "standard" Arduino libraries is a grate advantage, so I the custom library is no more used, it could be useful to update the guidelines in the page.

                        Stefano

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


                        10

                        Online

                        11.7k

                        Users

                        11.2k

                        Topics

                        113.0k

                        Posts


                        Copyright 2019 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
                        • OpenHardware.io
                        • Categories
                        • Recent
                        • Tags
                        • Popular