Deep sleep pin value1 high or low

Is there a way to have the imp deep sleep on both values of a reed switch.

`function TrySleep() {
  if ( == 0) {
    // if pin1 is low, we can sleep
   local data = { "button1": "CLOSED", "mykey": "23123faa5ba5ceee" }
agent.send("senddata", data);    
    imp.onidle(function() { imp.deepsleepfor(2419198); });
  } else {`

this works good on pin1 low but i can’t get it to on pin1 high.
I want it to send this data and go to sleep until pin1 is moved like the above code does local data = { “button1”: “Open”, “mykey”: “23123faa5ba5ceee” } any ideas?

You need to add an external XOR gate to generate a positive-going pulse on a state change. The hardware won’t enter sleep mode unless the pin is low.

Hi Hugo Yes i have added the xor gate. And once the reed switch is pulled apart the imp goes to a deep sleep but when i put the reed switch together this happens

`{ "mykey": "23123faa5ba5ceee", "button1": "CLOSED" }
2015-04-21 13:11:13 UTC+10	[Status]	Device connected; 4.87% program storage used
2015-04-21 13:11:13 UTC+10	[Status]	Device disconnected
2015-04-21 13:11:17 UTC+10	[Agent]	Imp was woken.
2015-04-21 13:11:17 UTC+10	[Agent]	{ "mykey": "23123faa5ba5ceee", "button1": "CLOSED" }
2015-04-21 13:11:17 UTC+10	[Status]	Device connected; 4.87% program storage used
2015-04-21 13:11:21 UTC+10	[Status]	Device connected; 4.87% program storage used
2015-04-21 13:11:22 UTC+10	[Agent]	Imp was woken.
2015-04-21 13:11:22 UTC+10	[Agent]	{ "mykey": "23123faa5ba5ceee", "button1": "CLOSED" }
2015-04-21 13:11:22 UTC+10	[Status]	Device disconnected`

I only want it to send to the agent once, not every 5 seconds. As it does once the reed switch is opened. If i change from 0 to 1 all it does is change the open to close. I am thinking is it the resistor that needs to be bigger? I’ll find the drawing of how i have set the xor up from @larryJ Thanks

here is LarryJ wiring there is a more effective one but i just wanted to get this one working first.

I put another 10k resistor in and that has worked. But now it will only say open on both states. any Ideas how to fix this?

Remember you should be reading pin2 for the actual reed switch state, not pin 1. Pin 1 will only give a short high pulse on a change, which is to wake the imp, not indicate the state.

Where did you add the 10k?

Oh yes thats fixed it thanks so much the only thing is it takes a while to goto sleep when the reed switch is closed. But Working really well now only took me a year ha ha.
i put the 10k next to the other one in pin1 and 2 of the xor gate?