within time - rdmtc/node-red-contrib-sun-position GitHub Wiki

within-time-example

[{"id":"bd9bd279.302eb","type":"inject","z":"de4e9c38.0d942","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":1180,"wires":["b5c283be.eb945"](/rdmtc/node-red-contrib-sun-position/wiki/"b5c283be.eb945")},{"id":"273eb4cb.2715fc","type":"debug","z":"de4e9c38.0d942","name":"out1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":590,"y":1180,"wires":[]},{"id":"78f068d6.2fe9f8","type":"debug","z":"de4e9c38.0d942","name":"out2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":590,"y":1220,"wires":[]},{"id":"b5c283be.eb945","type":"within-time-switch","z":"de4e9c38.0d942","name":"","positionConfig":"bdf7c4a.9ca6c38","startTime":"7:00","startTimeType":"entered","startOffset":0,"startOffsetMultiplier":"60","endTime":"9:00","endTimeType":"entered","endOffset":0,"endOffsetMultiplier":"60","property":"","propertyType":"none","startTimeAlt":"","startTimeAltType":"none","startOffsetAlt":0,"startOffsetAltMultiplier":"60","endTimeAlt":"","endTimeAltType":"none","endOffsetAlt":0,"endOffsetAltMultiplier":"60","x":330,"y":1180,"wires":["273eb4cb.2715fc"],["78f068d6.2fe9f8"](/rdmtc/node-red-contrib-sun-position/wiki/"273eb4cb.2715fc"],["78f068d6.2fe9f8")},{"id":"bdf7c4a.9ca6c38","type":"position-config","z":"","name":"","longitude":"13.71587","latitude":"51.01732","angleType":"deg"}]

within-time - Node settings

A simple node that routes messages depending on the time. If the current time falls within the range specified in the node configuration, the message is routed to output 1. Otherwise the message is routed to output 2.

within-time-settings

  • configuration connects to the central configuration node, which contains the current position, but also handles internal shared functions

  • Start time defines the start time of the time range with with different configuration possibilities

    • Start Offset allows to define a positive or negative offset in seconds, minutes or hours to the given Start Time. This will be useful for sun based times.
  • End time defines the end time of the time range with with different configuration possibilities

    • End Offset allows to define a positive or negative offset in seconds, minutes or hours to the given End Time. This will be useful for sun based times.
  • limit time allows to define days, months, a date range or special days, where the time should be valid. If the time is not a valid time, (example it is on a day or month not checked), the messsage is always routed to output 2.

    • the time limit is always evaluated first. All other time7alternate time settings will only be evaluated if the time is valid, so only one time limit setting exists for all.
    • The time limit can also be given by a msg property, flow or global context or an Environment variable. See below for more information.
  • Alternate start time optional defines an alternate start time of the time range which will be used if the conditions matches. This can be used for different times for example of holidays.

    • Start time alternate start time
    • Start Offset offset for the alternate start time
  • Alternate end time optional defines an alternate end time of the time range which will be used if the conditions matches. This can be used for different times for example of holidays.

    • End time alternate end time
    • End Offset offset for the alternate end time

node output

The output will be the ingoing message to output 1 if in the time or 2 if not in the time.

Additional in the message two properties will be set:

  • withinTimeStart - an object of the the time information of the start time stamp which was used
  • withinTimeEnd - an object of the the time information of the end time stamp which was used
  • withinTime - a boolean which is true if the message is in the time (was send to output 1) or false out of time (was send to output 2)

Example:

{
	"_msgid": "e34d667a.72cc58",
	"payload": false,
	"topic": "",
	"_srcid": "fd57f8a8.fba618",
	"_ts": 1601414185682,
	"withinTimeStart": {
		"value": "2020-09-29T05:39:16.728Z",
		"ts": 1601355856728.132,
		"name": "sunrise",
		"elevation": -0.833,
		"julian": 2459121.7113047238,
		"valid": true,
		"pos": 7,
		"fix": true,
		"id": 20356728
	},
	"withinTimeEnd": {
		"value": "2020-09-29T16:49:37.280Z",
		"ts": 1601398177280.3171,
		"name": "sunset",
		"elevation": -0.833,
		"julian": 2459122.2011259296,
		"valid": true,
		"pos": 13,
		"fix": true,
		"id": 60577280
	},
	"withinTime": false
}

time limit used from external

Starting from version 1.2.0 the time limit can also be given by a message property, flow or global context, an Environment variable, a json object or a jsonata expression. image image

The given property/data must result in a valid javascript object with one or more of the following properties:

  • days an array which can contains the number 0 (sunday), 1 (monday) to 6 (saturday)
    • If this property is not defined in the object the default (all days) will be used.
  • months an array which can contains the number 0 (january), 2 (february) to 11 (december)
    • If this property is not defined in the object the default (all month) will be used.
  • onlyOddDays an boolean, if true only odd days should be used.
    • If this property is not defined in the object the default (false) will be used.
  • onlyEvenDays an boolean, if true only even days should be used.
    • If this property is not defined in the object the default (false) will be used.
  • startDate and endDate a valid date of the format:
    • An integer value representing the number of milliseconds since January 1, 1970, 00:00:00 UTC (the ECMAScript epoch, equivalent to the UNIX epoch), with leap seconds ignored. Keep in mind that most UNIX Timestamp functions are only accurate to the nearest second.
    • A string value representing a date, specified in a format recognized by the Date.parse() method. (These formats are IETF-compliant RFC 2822 timestamps, and also strings in a version of ISO8601.)
      • Support for ISO 8601 formats differs in that date-only strings (e.g. "1970-01-01") are treated as UTC, not local.
    • Of these properties only the month and day information is used!
    • If both properties (startDate and endDate) is not defined in the object the default (no limitation) will be used.
    • If only the property endDate is defined, as startDate the default 1. January (0:00:01) of the current year will be used.
    • If only the property startDate is defined, as endDate the default 31. December (23:59:59) of the current year will be used.
    • If the month and day of the startDate is below the endDate a date will be valid if the date is between startDate and endDate of the current year.
    • If the month and day of the startDate is behind the endDate a date will be valid if the date is between 1. Janury (0:00:01) and endDate or startDate and 31. december (23:59:59) of the current year.

limit the days to Monday, Tuseday, Wednesday:

{
  "days": [1,2,3]
}

or only limit the months to February and March:

{
  "months": [1,2]
}

Full Example:

{
  "days" : [1,2,3,4,6,0],
  "months" : [0,1,2,3,4,5,6,7,8,9,10,11],
  "startDate": "2020-09-30",
  "endDate": "2020-10-22",
  "onlyOddDays" : false,
  "onlyEvenDays": false
}