Hi, i recently build some temp/hum sensors with arduinos and the dht22 sensor and got them in domoticz.
But i wonder why i only get rounded temperatures in domoticz.
Fi, if i monitor a sensor vai de serial monitor i see that it sends a temp of 21.80 but in domoticz i see that the temp is 22.00 degrees, while the humitidy is showing the same values that i see in the serial monitor.
Can i change this myself and if so..how?
Gr,
Ronald
Temp gets rounded up or down
Moderator: leecollings
-
- Posts: 279
- Joined: Sunday 03 January 2016 14:55
- Target OS: -
- Domoticz version:
- Location: Sweden
- Contact:
Re: Temp gets rounded up or down
Can you put your code here, it can be that you don't include ",1" in the message to DZ
-
- Posts: 12
- Joined: Wednesday 14 January 2015 22:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Sirjansland, Netherlands
- Contact:
Re: Temp gets rounded up or down
Yes, her it is:
#include <SPI.h>
#include <MySensor.h>
/** Libraries foor temp/hum */
#include <DHT.h>
// Defines for temp/hum
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define HUMIDITY_SENSOR_DIGITAL_PIN 3 /** Digital Input for temp/hum 1 */
int ReadTempHumTime=12; //read temphum every nn X Sleep_TIME seconds
unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds)
MySensor gw;
DHT dht;
float lastTemp;
float lastHum;
boolean metric = true;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
int teller=0;
void setup()
{
gw.begin();
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Send the Sketch Version Information to the Gateway
gw.sendSketchInfo("Woon.Kmr.TempHum", "1.0");
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_HUM, S_HUM);
gw.present(CHILD_ID_TEMP, S_TEMP);
metric = gw.getConfig().isMetric;
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
if (teller == ReadTempHumTime) {
float temperature = dht.getTemperature();
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DHT");
} else if (temperature != lastTemp) {
lastTemp = temperature;
gw.send(msgTemp.set(temperature, 0));
Serial.print("T1: ");
Serial.println(temperature);
}
float humidity = dht.getHumidity();
if (isnan(humidity)) {
Serial.println("Failed reading humidity from DHT1");
} else if (humidity != lastHum) {
lastHum = humidity;
gw.send(msgHum.set(humidity, 1));
Serial.print("H1: ");
Serial.println(humidity);
}
teller=0;
} else { teller++; }
gw.sleep(SLEEP_TIME); //sleep a bit
}
#include <SPI.h>
#include <MySensor.h>
/** Libraries foor temp/hum */
#include <DHT.h>
// Defines for temp/hum
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define HUMIDITY_SENSOR_DIGITAL_PIN 3 /** Digital Input for temp/hum 1 */
int ReadTempHumTime=12; //read temphum every nn X Sleep_TIME seconds
unsigned long SLEEP_TIME = 5000; // Sleep time between reads (in milliseconds)
MySensor gw;
DHT dht;
float lastTemp;
float lastHum;
boolean metric = true;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
int teller=0;
void setup()
{
gw.begin();
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
// Send the Sketch Version Information to the Gateway
gw.sendSketchInfo("Woon.Kmr.TempHum", "1.0");
// Register all sensors to gw (they will be created as child devices)
gw.present(CHILD_ID_HUM, S_HUM);
gw.present(CHILD_ID_TEMP, S_TEMP);
metric = gw.getConfig().isMetric;
}
void loop()
{
delay(dht.getMinimumSamplingPeriod());
if (teller == ReadTempHumTime) {
float temperature = dht.getTemperature();
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DHT");
} else if (temperature != lastTemp) {
lastTemp = temperature;
gw.send(msgTemp.set(temperature, 0));
Serial.print("T1: ");
Serial.println(temperature);
}
float humidity = dht.getHumidity();
if (isnan(humidity)) {
Serial.println("Failed reading humidity from DHT1");
} else if (humidity != lastHum) {
lastHum = humidity;
gw.send(msgHum.set(humidity, 1));
Serial.print("H1: ");
Serial.println(humidity);
}
teller=0;
} else { teller++; }
gw.sleep(SLEEP_TIME); //sleep a bit
}
-
- Posts: 279
- Joined: Sunday 03 January 2016 14:55
- Target OS: -
- Domoticz version:
- Location: Sweden
- Contact:
Temp gets rounded up or down
MsgTemp.set(temperature,0) change to MsgTemp.set(temperature,1) and it will send one decimal
-
- Posts: 12
- Joined: Wednesday 14 January 2015 22:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Sirjansland, Netherlands
- Contact:
Re: Temp gets rounded up or down

thanks a lot for your solution, it works like a charm now!
-
- Posts: 279
- Joined: Sunday 03 January 2016 14:55
- Target OS: -
- Domoticz version:
- Location: Sweden
- Contact:
Temp gets rounded up or down
Great, you'r welcome
-
- Posts: 7
- Joined: Monday 13 January 2020 21:16
- Target OS: Linux
- Domoticz version: 2023.1
- Location: Poland
- Contact:
Re: Temp gets rounded up or down
Hi
can you advice how to manage Domoticz to display 2 decimals under Temperature sensors page, when following this MsgTemp.set(temperature,2) i can see on arduino serial monitor, mysensors sent xx.xx 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, same with ESPEasy and 2 decimal configuration on ESP.
do you know how i can changed that?
Mysensors 2.3.1/2.3.2
Domoticz 4.10717
raspberry pi
Thank you
Jakub
-
- Posts: 8
- Joined: Wednesday 31 January 2018 13:39
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2023.1
- Location: IT
- Contact:
Re: Temp gets rounded up or down
I have same problem with mysensors, is there anyone who solved the issue?
Raspberry Pi 3b+ - Domoticz 2023.1
NodeRED
Solaredge inverter
NodeRED
Solaredge inverter
Who is online
Users browsing this forum: No registered users and 1 guest