Device timer with reset

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.

Hi, @Positiveground

You can create this automation based on the Rules API. The next Rule example will handle the condition you have specified:

{
    "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 you’ll find a brief step-by-step to create your Rule automation.