sorted works a treat now. My bad, used a sketch I had tinkered with in the past. sketches melded now. Finished sketch below for them that might need. The sketch is for domestic light swith.
#define MY_NODE_ID 5
#define MY_DEBUG
#define MY_RADIO_NRF24
#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>
#include <DHT.h>
#define DHT_DATA_PIN 7
#define CHILD_ID 3
#define BUTTON_PIN 3
#define SENSOR_TEMP_OFFSET 0
#define CHILD_ID_TEMP 1
Bounce debouncer = Bounce();
static const uint64_t UPDATE_INTERVAL = 5000;
static const uint8_t FORCE_UPDATE_N_READS = 2;
float lastTemp;
unsigned long interval = 5000;
unsigned long previousMillis = 0;
uint8_t nNoUpdatesTemp;
int oldValue = -1;
bool metric = true;
MyMessage msg(CHILD_ID, V_LIGHT);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
DHT dht;
void presentation()
{
sendSketchInfo("kitchen Lights", "1.1");
present(CHILD_ID, S_LIGHT);
present(CHILD_ID_TEMP, S_TEMP);
metric = getConfig().isMetric;
}
void setup()
{
pinMode(BUTTON_PIN, INPUT);
digitalWrite(BUTTON_PIN, HIGH);
debouncer.attach(BUTTON_PIN);
debouncer.interval(5);
dht.setup(DHT_DATA_PIN);
if (UPDATE_INTERVAL <= dht.getMinimumSamplingPeriod()) {
Serial.println("Warning: UPDATE_INTERVAL is smaller than supported by the sensor!");
}
}
void loop()
{
debouncer.update();
int value = debouncer.read();
if (value != oldValue) {
send(msg.set(value == HIGH ? 1 : 0));
oldValue = value;
}
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis - previousMillis) >= interval) {
dht.readSensor(true);
float temperature = dht.getTemperature();
if (isnan(temperature)) {
Serial.println("Failed reading temperature from DHT!");
} else if (temperature != lastTemp || nNoUpdatesTemp == FORCE_UPDATE_N_READS) {
lastTemp = temperature;
if (!metric) {
temperature = dht.toFahrenheit(temperature);
}
nNoUpdatesTemp = 0;
temperature += SENSOR_TEMP_OFFSET;
send(msgTemp.set(temperature, 1));
#ifdef MY_DEBUG
Serial.print("T: ");
Serial.println(temperature);
#endif
} else {
nNoUpdatesTemp++;
}
previousMillis = millis();
}
}