Temp gets rounded up or down

Moderator: leecollings

Post Reply
bickel
Posts: 12
Joined: Wednesday 14 January 2015 22:16
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Sirjansland, Netherlands
Contact:

Temp gets rounded up or down

Post by bickel »

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
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Re: Temp gets rounded up or down

Post by Flopp »

Can you put your code here, it can be that you don't include ",1" in the message to DZ
bickel
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

Post by bickel »

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
}
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Temp gets rounded up or down

Post by Flopp »

MsgTemp.set(temperature,0) change to MsgTemp.set(temperature,1) and it will send one decimal
bickel
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

Post by bickel »

:-) i knew id had to be simple...learning something new everyday.

thanks a lot for your solution, it works like a charm now!
Flopp
Posts: 279
Joined: Sunday 03 January 2016 14:55
Target OS: -
Domoticz version:
Location: Sweden
Contact:

Temp gets rounded up or down

Post by Flopp »

Great, you'r welcome
gniazdoj
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

Post by gniazdoj »

Flopp wrote: Monday 07 November 2016 21:50 MsgTemp.set(temperature,0) change to MsgTemp.set(temperature,1) and it will send one decimal
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
diegoflyer
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

Post by diegoflyer »

I have same problem with mysensors, is there anyone who solved the issue?
Raspberry Pi 3b+ - Domoticz 2023.1
NodeRED
Solaredge inverter
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest