Hello:
Hoping perhaps @martinhjelmare can help… I have put together an arduino multi sensor with PIR, DHT, Reed switch, and a Relay. Seems to be functioning ok based on serial output, and I can trigger the relay on / off from an MQTT broker. Some of the sensors are being presented to HASS, but some are not, ( for example the reed switch, or relay, and PIR ). The DHT seems fine… The IDE sketch I used is bellow, along with the serial output:
// Garage Door Relay ( Open/Close) + Motion (PIR), + DHT Temp/HUM, + Reed Switch
#define MY_DEBUG
#define MY_RADIO_NRF24
#define MY_NODE_ID 50
#define MY_REPEATER_FEATURE
#include <SPI.h>
#include <MySensors.h>
#include <Bounce2.h>
#include <DHT.h>
#define CHILD_ID_REL1 1
#define CHILD_ID_PIR 3
#define CHILD_ID_HUM 10
#define CHILD_ID_TEMP 11
#define REL1_PIN 4
#define RELAY_ON 1 // GPIO value to write to turn on attached relay
#define RELAY_OFF 0 // GPIO value to write to turn off attached relay
#define TOGGLE_INTERVAL 350 //Tells how many milliseconds the relay will be held closed
#define CLOSED 0
#define OPEN 1
#define PIR_PIN 3
#define HUMIDITY_SENSOR_DIGITAL_PIN 7
#define BUTTON_PIN_1 2 // Arduino Digital I/O pin for button/reed switch
#define CHILD_ID_SW 3
Bounce debouncer = Bounce();
int oldValue=-1;
MyMessage msgREL1(CHILD_ID_REL1, V_STATUS); // 2
MyMessage msgPir(CHILD_ID_PIR, V_TRIPPED);
MyMessage msgHum(CHILD_ID_HUM, V_HUM); // 1
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); // 0
MyMessage msgSW(CHILD_ID_SW,V_TRIPPED);
DHT dht;
bool StateREL=0, StateREL1=0;
const unsigned long tUpdate=30000; // update interval
unsigned long t0;
float Temp, Hum;
byte StatePIR=0;
byte oldStatePIR=0;
unsigned long tSetup=30000; // warming time
void presentation() {
sendSketchInfo("Garage Multi Sensor", "1.0");
present(CHILD_ID_REL1, S_BINARY);
present(CHILD_ID_PIR, S_MOTION);
present(CHILD_ID_HUM, S_HUM);
present(CHILD_ID_TEMP, S_TEMP);
present(CHILD_ID_SW, S_DOOR);
}
void setup() {
// Setup the button
pinMode(BUTTON_PIN_1,INPUT);
// Activate internal pull-up
digitalWrite(BUTTON_PIN_1,HIGH);
// After setting up the button, setup debouncer
debouncer.attach(BUTTON_PIN_1);
debouncer.interval(5);
pinMode(REL1_PIN, OUTPUT);
digitalWrite(REL1_PIN, StateREL1);
pinMode(PIR_PIN, INPUT_PULLUP);
dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN);
t0=millis();
}
void loop() {
debouncer.update();
// Get the update value
int value = debouncer.read();
if (value != oldValue) {
// Send in the new value
send(msgSW.set(value==HIGH ? 1 : 0));
oldValue = value;
}
StatePIR=digitalRead(PIR_PIN);
if (StatePIR != oldStatePIR) {
oldStatePIR=StatePIR;
send(msgPir.set(StatePIR ? "ON" : "OFF"));
}
if ((millis()-t0) > tUpdate) ServerUpdate();
}
void ServerUpdate() {
send(msgPir.set(StatePIR ? "ON" : "OFF"));
Hum = dht.getHumidity();
Temp = dht.getTemperature();
send(msgTemp.set(Temp, 1));
send(msgHum.set(Hum, 1));
t0=millis();
}
void receive(const MyMessage &message) {
// We only expect one type of message from controller. But we better check anyway.
if (message.type==V_STATUS) {
// Change relay state
digitalWrite(message.sensor-1+REL1_PIN, message.getBool()?RELAY_ON:RELAY_OFF);
digitalWrite( REL1_PIN, RELAY_ON );
//Keep the relay on for the amount of time defined by TOGGLE_INTERVAL
delay( TOGGLE_INTERVAL );
digitalWrite( REL1_PIN, RELAY_OFF );
//Added this to tell the controller that we shut off the relay
// Store state in eeprom
saveState(message.sensor, message.getBool());
// Write some debug info
Serial.print("Incoming change for sensor:");
Serial.print(message.sensor);
Serial.print(", New status: ");
Serial.println(message.getBool());
}
}
Serial Output:
Starting repeater (RNNRA-, 2.0.0)
TSM:INIT
TSM:RADIO:OK
TSP:ASSIGNID:OK (ID=50)
TSM:FPAR
TSP:MSG:SEND 50-50-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=bc:
TSP:MSG:READ 0-0-50 s=255,c=3,t=8,pt=1,l=1,sg=0:0
TSP:MSG:FPAR RES (ID=0, dist=0)
TSP:MSG:PAR OK (ID=0, dist=1)
TSM:FPAR:OK
TSM:ID
TSM:CHKID:OK (ID=50)
TSM:UPL
TSP:PING:SEND (dest=0)
TSP:MSG:SEND 50-50-0-0 s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=ok:1
TSP:MSG:READ 0-0-50 s=255,c=3,t=25,pt=1,l=1,sg=0:1
TSP:MSG:PONG RECV (hops=1)
TSP:CHKUPL:OK
TSM:UPL:OK
TSM:READY
TSP:MSG:SEND 50-50-0-0 s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=ok:0100
TSP:MSG:SEND 50-50-0-0 s=255,c=0,t=18,pt=0,l=5,sg=0,ft=0,st=ok:2.0.0
TSP:MSG:SEND 50-50-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=ok:0
TSP:MSG:READ 0-0-50 s=255,c=3,t=6,pt=0,l=1,sg=0:M
TSP:MSG:SEND 50-50-0-0 s=255,c=3,t=11,pt=0,l=19,sg=0,ft=0,st=ok:Garage Multi Sensor
TSP:MSG:SEND 50-50-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,ft=0,st=ok:1.0
TSP:MSG:SEND 50-50-0-0 s=1,c=0,t=3,pt=0,l=0,sg=0,ft=0,st=ok:
TSP:MSG:SEND 50-50-0-0 s=3,c=0,t=1,pt=0,l=0,sg=0,ft=0,st=ok:
TSP:MSG:SEND 50-50-0-0 s=10,c=0,t=7,pt=0,l=0,sg=0,ft=0,st=ok:
TSP:MSG:SEND 50-50-0-0 s=11,c=0,t=6,pt=0,l=0,sg=0,ft=0,st=ok:
TSP:MSG:SEND 50-50-0-0 s=3,c=0,t=0,pt=0,l=0,sg=0,ft=0,st=ok:
Request registration...
TSP:MSG:SEND 50-50-0-0 s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=ok:2
TSP:MSG:READ 0-0-50 s=255,c=3,t=27,pt=1,l=1,sg=0:1
Node registration=1
Init complete, id=50, parent=0, distance=1, registration=1
TSP:MSG:SEND 50-50-0-0 s=3,c=1,t=16,pt=2,l=2,sg=0,ft=0,st=ok:0
TSP:MSG:SEND 50-50-0-0 s=3,c=1,t=16,pt=0,l=2,sg=0,ft=0,st=ok:ON
TSP:MSG:SEND 50-50-0-0 s=3,c=1,t=16,pt=0,l=3,sg=0,ft=0,st=ok:OFF
TSP:MSG:READ 0-0-50 s=1,c=1,t=2,pt=0,l=1,sg=0:1
Incoming change for sensor:1, New status: 1
TSP:MSG:SEND 50-50-0-0 s=3,c=1,t=16,pt=0,l=2,sg=0,ft=0,st=ok:ON
TSP:MSG:READ 0-0-50 s=1,c=1,t=2,pt=0,l=1,sg=0:1
Incoming change for sensor:1, New status: 1
TSP:MSG:SEND 50-50-0-0 s=3,c=1,t=16,pt=0,l=3,sg=0,ft=0,st=ok:OFF
The following shows up for the relay:
And the DHT Data is here:
But I cannot find the PIR or Reed switch anywhere in the HASS configuration. Any help would be greatly appreciated! Thank you.