Here is my code for doing something equivalent. You seem to have the pinMode line missing in setup()
// Initialize motion message
MyMessage msg(CHILD_ID, V_TRIPPED);
void setup() {
pinMode(MOTION_SENSOR_PIN, INPUT_PULLUP); // sets the motion sensor digital pin as input
}
void presentation() {
// Present locally attached sensors here
// Send the sketch version information to the gateway and Controller
sendSketchInfo("Motion Sensor", "1.1");
// Register all sensors to gw (they will be created as child devices)
present(CHILD_ID, S_MOTION);
}
boolean pinstate = false;
void loop() {
boolean newstate = (digitalRead(MOTION_SENSOR_PIN) == HIGH);
if (newstate != pinstate) {
if (newstate == true) {
send(msg.set("1"));
Serial.println("Motion Started");
pinstate = newstate;
} else {
send(msg.set("0"));
Serial.println("Motion Stopped");
pinstate = newstate;
}
}
}