@maddhin Any version 2 sketch with HTU21D should work as slim node is atmgea328 based. I use adafruit lib for mine and it works well. To conserve battery energy follow all the steps on the battery power page in here and send data as infrequently as you can for your needs.
here is the code I use to test with - you can safely remove all the "force n updates" to reduce memory use ( I always do). It also only send if the temp or hum has changed since last reading to further reduce battery consumption....
/**
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*******************************
*
* REVISION HISTORY
* Version 1.0: Andrew Sutcliffe
*
* DESCRIPTION
* This sketch provides an example of how to implement a humidity/temperature
* sensor using a HTU21DF Sensor.
*
* For more information, please visit:
* http://www.mysensors.org/build/humidity
*
* Connect Vin to 3-5VDC
* Connect GND to ground
* Connect SCL to I2C clock pin (A5 on UNO)
* Connect SDA to I2C data pin (A4 on UNO)
*
*/
// Enable debug prints
#define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
//#define MY_RS485
#include <MySensors.h>
#include <Wire.h>
#include "Adafruit_HTU21DF.h"
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
// Set this offset if the sensor has a permanent small offset to the real temperatures
#define SENSOR_TEMP_OFFSET 0
// Sleep time between sensor updates (in milliseconds)
static const uint64_t UPDATE_INTERVAL = 15*60000;
// Force sending an update of the temperature after n sensor reads, so a controller showing the
// timestamp of the last update doesn't show something like 3 hours in the unlikely case, that
// the value didn't change since;
// i.e. the sensor would force sending an update every UPDATE_INTERVAL*FORCE_UPDATE_N_READS [ms]
static const uint8_t FORCE_UPDATE_N_READS = 10;
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
float lastTemp;
float lastHum;
uint8_t nNoUpdatesTemp;
uint8_t nNoUpdatesHum;
bool metric = true;
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
void presentation()
{
// Send the sketch version information to the gateway
sendSketchInfo("HTU21DF-TemperatureAndHumidity", "1.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID_HUM, S_HUM);
present(CHILD_ID_TEMP, S_TEMP);
}
void setup()
{
Serial.begin(9600);
Serial.println("HTU21D-F test");
if (!htu.begin()) {
Serial.println("Couldn't find sensor!");
while (1);
}
}
void loop(){
// Get temperature from HTU21DF library
float temperature = (htu.readTemperature());
if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
// Only send temperature if it changed since the last measurement or if we didn't send an update for n times
lastTemp = temperature;
// Reset no updates counter
nNoUpdatesTemp = 0;
temperature += SENSOR_TEMP_OFFSET;
send(msgTemp.set(temperature, 1));
#ifdef MY_DEBUG
Serial.print("T: ");
Serial.println(temperature);
#endif
}
else {
// Increase no update counter if the temperature stayed the same
nNoUpdatesTemp++;
}
// Get humidity from HTU21DF library
float humidity = (htu.readHumidity());
if (humidity != lastHum || nNoUpdatesHum == FORCE_UPDATE_N_READS) {
// Only send humidity if it changed since the last measurement or if we didn't send an update for n times
lastHum = humidity;
// Reset no updates counter
nNoUpdatesHum = 0;
send(msgHum.set(humidity, 1));
#ifdef MY_DEBUG
Serial.print("H: ");
Serial.println(humidity);
#endif
}
else {
// Increase no update counter if the humidity stayed the same
nNoUpdatesHum++;
}
// Sleep for a while to save energy
sleep(UPDATE_INTERVAL);
}
Hope it helps you get up and running.