# Device timer with reset

**URL:** <https://community.smartthings.com/t/device-timer-with-reset/197266>\
**Category:** SmartApps & Automations\
**Created:** [June 16, 2020, 12:17am UTC](https://community.smartthings.com/t/device-timer-with-reset/197266 "2020-06-16T00:17:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Positiveground](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@Positiveground](https://community.smartthings.com/u/Positiveground)\
**Post date:** [June 16, 2020, 12:17am UTC](https://community.smartthings.com/t/device-timer-with-reset/197266/1 "2020-06-16T00:17:01Z")

</div>

I need a simple timer that will turn a light off after 30 minutes but will reset for another 30 minutes if the light is turned off then on again. Currently I’m finding that just setting the device to turn off after 30 minutes does not cancel the previous timer causing the light to always turn off 30 minutes after it is first turned on regardless if it is turned off and on again prior to the first 30 minutes expiring.

---

<div class="post-metadata">

**Author:** ![erickv](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/erickv/32/230792_2.png) [@erickv](https://community.smartthings.com/u/erickv)\
**Post date:** [June 16, 2020, 9:16pm UTC](https://community.smartthings.com/t/device-timer-with-reset/197266/2 "2020-06-16T21:16:46Z")

</div>

Hi, @Positiveground

You can create this automation based on the [Rules API](https://smartthings.developer.samsung.com/docs/rules/rules-breakdown.html). The next _Rule_ example will handle the condition you have specified:

```auto
{
    "name": "Timer Rule - Turn off light after 30 minutes",
    "actions": [
        {
            "if": {
                "equals": {
                    "left": {
                        "device": {
                            "devices": ["<deviceId>"],
                            "component": "main",
                            "capability": "switch",
                            "attribute": "switch"
                        }
                    },
                    "right": {
                        "string": "on"
                    }
                },
                "then": [
                    {
                        "sleep": {
                            "durations": {
                                "value": {
                                    "integer": 30
                                },
                                "unit": "Minute"
                            }
                        }
                    },
                    {
                        "command": {
                            "devices": ["<deviceId>"],
                            "commands": [
                                {
                                    "component": "main",
                                    "capability": "switch",
                                    "command": "off",
                                    "arguments": []
                                }
                            ]
                        }
                    }
                ],
                "else": []
            }
        }
    ]
}

```

At [this thread](https://community.smartthings.com/t/run-pump-x-min-on-x-min-off-on-continuous-loop/192200/35) you’ll find a brief step-by-step to create your Rule automation.
