How to specify specific times in Rules?

is it possible to specify a specific time (like 10:00PM) or does everything need to reference a ‘reference time’ like midnight, sunrise, etc. all the examples i see on the Sample-Rules all use reference times

Sample-RulesAPI

 {
                        "between": {
                            "value": {
                                "time": {
                                    "reference": "Now"
                                }
                            },
                            "start": {
                                "time": {
                                    "daysOfWeek": [
                                        "Mon",
                                        "Tue",
                                        "Wed",
                                        "Thu",
                                        "Fri"
                                    ],
                                    "reference": "**Midnight**",
                                    "offset": {
                                        "value": {
                                            "integer": -360
                                        },
                                        "unit": "Minute"
                                    }
                                }
                            },
                            "end": {
                                "time": {
                                    "daysOfWeek": [
                                        "Mon",
                                        "Tue",
                                        "Wed",
                                        "Thu",
                                        "Fri"
                                    ],
                                    "reference": "**Midnight**",
                                    "offset": {
                                        "value": {
                                            "integer": -180
                                        },
                                        "unit": "Minute"
                                    }
                                }
                            }
                        }
                    }

Please put topics about the rules API in the rules API section of the forum. I have moved this one for you.

1 Like

thank you @JDRoberts

1 Like

Hi, @AZSteve!
No, we cannot set a specific time, we need to set the time using the references available and the offset.

And the reference times are

  • sunrise
  • sunset
  • midnight
  • noon

Is that correct?

They start with capital letters as shown in the API reference (here):

And, you missed one:

  • Now
  • Midnight
  • Sunrise
  • Noon
  • Sunset

Thank you @nayelyz , you’ve been most helpful, as always.

maybe its me (it probably is) but i cannot find the instance of the reference you copied… i see the samples for Rules, List, Create, Get; but no parameter definitions or references… am i missing something? i hate asking such basic questions and i generally try to take a brute force, try-it-and-fail approach to things, its how i learn better (hopefully i don’t ever brick my hub :face_with_spiral_eyes:)

Don’t worry, @AZSteve, it’s ok.

In the API reference, whenever you see the symbol > next to a text in the diagram of “REQUEST BODY”, it means you can expand its content to get more details about it.

For example, here, the property “name” doesn’t have more elements under it, but “actions” does:
image

If you click on the text or the symbol, it will expand.

1 Like

ahhh… the devil is in the details :)… i didn’t notice the >

thanks again.

1 Like

Sorry to revive this but if I wanted to run an action only at a certain time and when a condition was met how would I write that?

if passed Sunset and front door opens, then turn on front porch light

Something like that for example.

Here is the rule’s structure

{
  "name": "Specific time >> Do something",
  "actions": [
     "every": {
        "specific": {
          "reference": "Sunset",
          "offset": {
            "value": {
              "integer": 0
			},
			"unit": "Minute"
		  }
		},
	  "actions": [
		{
		  "if": {




				"then": [
				  {





				  }
			   ]
		  }
		}
	  ]
	 }
  ]	
}

You can add other conditions and actions

1 Like

I could see two ways of interpreting your requirements as the description and example don’t really seem to match up.

If you want to do something at a fixed time you can use the every action and that can include further actions inside it. I don’t think that is what you had in mind.

Your example sounded more like describing something happening after a fixed time. There is a certain ambiguity to that. If you want a light to turn on if a door is opened after the time has passed sunset, at what time would you want it to stop turning on? Midnight? Sunrise the next morning? You can probably use the greaterThan condition with time operands and compare Now and sunset, and I’d guess it would probably only return true up until midnight but I don’t know. I’d use the between condition seen earlier in the thread where you explicitly compare the current time to a start and end time.

1 Like

I tried doing this for the time.

IF now is BETWEEN sunset to sunrise
THEN,
IF front_door is open OR motion_sensor is active
THEN,
turn ON porch_light
sleep 10min
turn OFF porch_light

So I know the second if works, I tested it out by itself. But the time part seems to not be working.

I reworked the script around

IF now is BETWEEN sunset to sunrise AND (front_door is open OR motion_sensor is active)

This way works properly. So I guess I can’t do an If between as a sole trigger.