# Power Saving modes

**URL:** <https://community.particle.io/t/power-saving-modes/32419>\
**Category:** Getting Started\
**Created:** [May 6, 2017, 1:59am UTC](https://community.particle.io/t/power-saving-modes/32419 "2017-05-06T01:59:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bscuderi](https://avatars.discourse-cdn.com/v4/letter/b/4491bb/32.png) [@bscuderi](https://community.particle.io/u/bscuderi)\
**Post date:** [May 6, 2017, 1:59am UTC](https://community.particle.io/t/power-saving-modes/32419/1 "2017-05-06T01:59:54Z")

</div>

I have a project that is solar and battery powered. Attached to my particle is a single channel relay. My code is simple as I just have my smartthings home automation controller sending the on and off command to the particle. I don’t need this project running 24/7 and would like to make sure I get a good runtime from the small battery and pannel. I tried reading the other posts on deep sleep mode etc and just ended up ultimately confused as I have no coding experience.

How where and what would I need to paste into my code to say make the particle deep sleep from 2am til 9am? I could use UTC if that is easier as well…

Secondly is there a mode that I could put the particle in that would sleeps everything except waiting for the on command to be recieved. If so how could I achieve that as it would be perfect for this project.

I have attached my code below for the photon. I can also provide my smartthings groovy device handler if it’s needed.

```cpp
// A Spark function to parse the commands

int relay4(String command);

// We name pins 
int r4 = D3;

// This routine runs only once upon reset
void setup() 
{
  //Register Spark functions
  Spark.function("strelay4", relay4);
  
  // Initialize output pins
  
  pinMode(r4, OUTPUT);
  
  // take control of the LED
  RGB.control(true);
  
  // the following sets the RGB LED to light green:
  RGB.color(0, 0, 0);
}

// This routine loops forever 
void loop()
{
  // nothing here
}

//acts based on messages from spark cloud
int relay1(String command)
{

int relay4(String command)
{
  if (command == "1") 
    {   
    digitalWrite(r4, HIGH); // Turn ON the relay
    return 1;
    } 
  else 
    {               
    digitalWrite(r4, LOW); // Turn OFF the relay
    return 0;
  }
}

```

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [May 6, 2017, 3:50am UTC](https://community.particle.io/t/power-saving-modes/32419/2 "2017-05-06T03:50:02Z")

</div>

You got some unfinished busines with your `int relay1()` function in that code.  
When you click the ✏ icon at the bottom of your post you can edit your code.

I’ve also reformatted your code block. Have a look at it how to post a code block correctly.

Also have a look here  
[Forum Tips and Tricks](https://community.particle.io/t/forum-tips-and-tricks/3999)

BTW, in the other thread I already posted some suggestions of which I can’t see any sign in your current code.

---

<div class="post-metadata">

**Author:** ![bscuderi](https://avatars.discourse-cdn.com/v4/letter/b/4491bb/32.png) [@bscuderi](https://community.particle.io/u/bscuderi)\
**Post date:** [May 6, 2017, 5:24am UTC](https://community.particle.io/t/power-saving-modes/32419/3 "2017-05-06T05:24:49Z")

</div>

oops yeah that relay(1) function is supposed to be erased I will fix that!

---

<div class="post-metadata">

**Author:** ![KyleG](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/kyleg/32/11077_2.png) [@KyleG](https://community.particle.io/u/KyleG)\
**Post date:** [May 7, 2017, 5:04pm UTC](https://community.particle.io/t/power-saving-modes/32419/4 "2017-05-07T17:04:48Z")

</div>

Thanks for the help @ScruffR!
