Page 1 of 1
Motion Node not correctly recognized
Posted: Tuesday 20 June 2017 13:46
by coolnicklas
Hi,
I'm using MySensors with the ESP8266 Wifi gateway. I have added a Temp/Hum node which shows up nicely in Domoticz but my motion sensor is identified as a "Lightning 2" Type sensor with subtype "AC".
My intention is to add one or several relay switch nodes which shall be switched on/off when motion is detected.
Since the motion sensor node is not identified correctly, I can't create an "if -do" Control event. Any suggestions how to move forward?
Thanks
Nicklas
Re: Motion Node not correctly recognized
Posted: Tuesday 20 June 2017 15:26
by emme
can you post the node code?
Re: Motion Node not correctly recognized
Posted: Tuesday 20 June 2017 17:33
by coolnicklas
Pretty much straight out of the box from the MySensor example
Code: Select all
/**
// Enable debug prints
// #define MY_DEBUG
// Enable and select radio type attached
#define MY_RADIO_NRF24
//#define MY_RADIO_RFM69
#include <MySensors.h>
unsigned long SLEEP_TIME = 120000; // Sleep time between reports (in milliseconds)
#define DIGITAL_INPUT_SENSOR 3 // The digital input you attached your motion sensor. (Only 2 and 3 generates interrupt!)
#define CHILD_ID 1 // Id of the sensor child
// Initialize motion message
MyMessage msg(CHILD_ID, V_TRIPPED);
void setup()
{
Serial.println("setting up");
pinMode(DIGITAL_INPUT_SENSOR, INPUT); // sets the motion sensor digital pin as input
}
void presentation()
{
Serial.println("presentation");
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Motion Sensor", "1.0");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_MOTION);
}
void loop()
{
// Read digital motion value
bool tripped = digitalRead(DIGITAL_INPUT_SENSOR) == HIGH;
Serial.println(tripped);
send(msg.set(tripped?"1":"0")); // Send tripped value to gw
// Sleep until interrupt comes in on motion sensor. Send update every two minute.
sleep(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), CHANGE, SLEEP_TIME);
}
Re: Motion Node not correctly recognized
Posted: Tuesday 20 June 2017 17:43
by emme
Motion in mysensor library is handled as v_tripped (On/Off) and V_ARMED (quite useless in this scenario)
yes... it is handled as an ON/OFF switch but you have to ensure if the sensor works as low=1=On and high=0=Off...
if so you will have the switch OFF in motion and ON when not in motion....
to change this you can easly change the line
send(msg.set(tripped?"1":"0"));
to
send(msg.set(tripped?"0":"1"));
another issue is the SLEEP_TIME setted to 2mins... so the device does not send any status after 2 mons from the last sent
maybe set it from 120000 to 5000 (5 secs)
ciao
M