Coder Social home page Coder Social logo

node-red-contrib-simple-weekly-scheduler's Introduction

node-red-contrib-simple-weekly-scheduler

A collection of nodes to do basic scheduling.

Simple Scheduler

A node to schedule a weeks worth of events. Multiple events can be scheduled Sun-Sat at a courseness of 15mins (e.g. and event can start at 10:00, 10:15, 10:30 or 11:00 and is a multiple of 15min in duration)

Events are scheduled by dragging out periods of time on a calendar style interface

The node will emit messages at the start and end of each event with a configurable payload for both messages.

Messages include an event object that includes the start and end times

{
  "topic": "some/topic",
  "event": {
    "start": "09:00:00 GMT+0100 (BST)",
    "end": "09:15:00 GMT+0100 (BST)"
  },
  "payload": "end",
}

The node can take a URL to pull a updated version of the calendar from. This URL is checked every 10 minutes and it replaces any events configured in the UI. The URL should return a JSON object similar to the following. The week in this object should start on Sunday 26th May 2009 in order to map to the same time slots as those in the UI.

[
  {
    "end": "2009-04-26T08:30:00.000Z",
    "id": 0,
    "start": "2009-04-26T06:15:00.000Z",
    "title": ""
  },
  {
    "end": "2009-04-28T08:00:00.000Z",
    "id": 1,
    "start": "2009-04-28T06:15:00.000Z",
    "title": ""
  },
  {
    "end": "2009-04-29T08:15:00.000Z",
    "id": 2,
    "start": "2009-04-29T07:15:00.000Z",
    "title": ""
  },
  {
    "end": "2009-04-30T06:15:00.000Z",
    "id": 3,
    "start": "2009-04-30T05:00:00.000Z",
    "title": ""
  },
  {
    "end": "2009-05-01T07:45:00.000Z",
    "id": 4,
    "start": "2009-05-01T06:00:00.000Z",
    "title": ""
  }
]

Simple Schedule Filter

This node filters messages based on timeslots over a week. The interface is the same as the Simple Schduler node but it will pass messages though to the first output if message arrives inside a marked zone and output to the second if it is outside.

node-red-contrib-simple-weekly-scheduler's People

Contributors

alexschwantes avatar hardillb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

node-red-contrib-simple-weekly-scheduler's Issues

Filter date comparison not working with timezone

To replicate this, it requires setting the system clock to a specific timezone and time.

The core of the problem is that when setting a schedule for the filter there is a case where it will incorrectly not trigger a success message on the first node.

Given that the local timezone is set to Europe (UTC +2).
Set the local time to be within the timezone period from midnight, ie set my local time to be between midnight and 2am. For this example it will be set to 1am.

change local time to Europe/Oslo via dpkg-reconfigure tzdata
Then set local time

sudo service ntp stop
sudo date -s "27 DEC 2016  01:00:00 CET"

Now create a simple schedule that starts on today (tuesday) at midnight and goes until 5am, or import the following flow:
[{"id":"4481daed.b74b64","type":"debug","z":"77d92c58.d74de4","name":"success","active":true,"console":"false","complete":"true","x":497,"y":220,"wires":[]},{"id":"c9d1c9c2.5e3f18","type":"debug","z":"77d92c58.d74de4","name":"failure","active":true,"console":"false","complete":"true","x":494,"y":268,"wires":[]},{"id":"50336f64.ea321","type":"time-filter","z":"77d92c58.d74de4","events":"[{\"start\":\"2009-05-11T22:00:00.000Z\",\"end\":\"2009-05-12T03:00:00.000Z\",\"title\":\"\",\"id\":0}]","topic":"","central":"","name":"","x":299,"y":242,"wires":[["4481daed.b74b64"],["c9d1c9c2.5e3f18"]]},{"id":"e831a93b.cea668","type":"inject","z":"77d92c58.d74de4","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":101,"y":234,"wires":[["50336f64.ea321"]]}]

The expected result is than an input message should be sent to the first 'success' output. However it instead gets sent to the second 'failure' output.

When the code gets to line 96 of timefilter.js it does a comparison to see if the day of schedule event matches the current day.
if (evtStart.getUTCDay() === day) { //same day of week

This fails as the utc time for the event is yesterday at 22:00, so evtStart.getUTCDay() will return yesterdays day, while "day" will return today so it gets evaluated to if (1 === 2) { It means that the event that was created in the flow above from midnight to 5am actually spans 2 utc days, which kind of breaks things.

This was verified by adding the following logging to the time-filter.js file along with the other logging already in there.

console.log("----");
console.log("evtStart.getUTCDay(): ",evtStart.getUTCDay());
console.log("day: ",day);

The result was

Now:  Tue Dec 27 2016 01:02:24 GMT+0100 (CET)
Now hour:  0
Now mins:  2
Start:  Tue May 12 2009 00:00:00 GMT+0200 (CEST)
Start hour:  22
Start mins:  0
End:  Tue May 12 2009 04:00:00 GMT+0200 (CEST)
----
evtStart.getUTCDay():  1
day:  2

A solution might be to change the comparison from UTC to be local time when assessing if the message should be allowed. I think this will make it clearer when testing the current time is within the start/end of the event. I'm experimenting with this at the moment and can add another pull request when I get it working.

Date comparison

Looks like the date comparison might be a bit off. The calendar saves to UTC, which is then converted to local time:

evtStart.setTime(Date.parse(node.events[i].start))

and then that is compared to the current UTC time.

simple scheduler

A few notes on the scheduler module:
Current configuration:

  • Start payload: boolean:true
  • End payload : boolean false
    Monday through friday is set to go on at 8:30 and off and 18:00

Issue:
When the program starts or if the Red-brick is rebooted it does not get the value from the scheduler. The value is only passed the software is online at the right time.
Also the area where you select the boolean or number value in start/end payload defaults back to string in the gui, however the value still passes ok and goes through the OR logic node and it still works.

Node-red crashes when using central list

Node-red crashes every 10 minute when using central list.
Log:

24 Aug 21:17:29 - [red] Uncaught Exception:
24 Aug 21:17:29 - ReferenceError: response is not defined
at Request._callback (/home/pi/.node-red/node_modules/node-red-contrib-simple-weekly-scheduler/time-planner.js:36:33)
at Request.self.callback (/home/pi/.node-red/node_modules/request/request.js:188:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request. (/home/pi/.node-red/node_modules/request/request.js:1171:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage. (/home/pi/.node-red/node_modules/request/request.js:1091:12)
at IncomingMessage.g (events.js:292:16)
at emitNone (events.js:91:20)
at IncomingMessage.emit (events.js:185:7)
at endReadableNT (_stream_readable.js:974:12)
at _combinedTickCallback (internal/process/next_tick.js:80:11)
at process._tickCallback (internal/process/next_tick.js:104:9)
nodered.service: main process exited, code=exited, status=1/FAILURE
Unit nodered.service entered failed state.
nodered.service holdoff time over, scheduling restart.
Stopping Node-RED graphical event wiring tool....

ENHANCEMENT: Event Title input and within node-red events raised please

I am building a sprinkler system and have played with google calendar to set sprinklers on/off.

To do this I wrote a pegjs parser to allow for a limited number of sprinklers (really relays ;) to be turned on at the start of a google calendar event.

The sprinklers to be turned on are listed, as a set of "commands", in the calendar event title string. Works a treat.

I have code then running on WEMOS D1 mini (single relay) and WEMOS D1 R2 (UNO) with quad relay board that I connect to the sprinkler solenoids.

I was looking for an alternative to google calendar, since not everyone will want to set up a google connection necessarily.

This simple-weekly-scheduler gets me almost there.

I note that the simple-weekly-scheduler does not allow for user entered title on html calendar widget. I suspect a prompt("enter title","title default") in the right place would fix that.

Otherwise, even if you use the url, which encourages you to use an calendar event title, the node-red event, that the simple-weekly-scheduler node generates, does not pump out the titles for the individual calendar events.

Any chance of adding the event title to the output event please?

While there, can we add a prompt to (I think) "eventNew", around line 170, within time-planner.html file. I am assuming that will allow user entered title as events are created. I hope that overcomes the default event title of time span ;). If not, then I guess some more work is needed.

So, while yes, I could use a calendar per sprinkler, the approach I have coded up provides a means to use the one calendar for any parseable commands in the calendar event title string.

Cheers,
B

Node doesn't work with NR 1.0.3

The Weekly scheduler node doesn't work any more with node-red 1.0.3.
The area in the node config where you should drag the desired events stays blanc, no rows visible and therefore unusable any more.

According the NR experts properly because NR updated the jquery version.

Filter returning more than 1 message

The Filter is not working as expected.

If I create 3 allowed time periods in the calendar, every time the filter receives an input it seems like it is outputting 3 messages on the second node (one for each time period created). I would have expected it to output only 1 message on either the first node OR the second node.

I've made some changes to fix this and will submit a bull request.

Schedule fires on deploy

I'm using Node Red with Home Assistant to turn the heater on and off. I have three separate schedules (for convenience) - one to turn on and off in the morning; and two to turn it off every couple of hours throughout the day if it was manually turned on. If I make a change (eg. just drag something a bit), when I deploy, the schedules all fire even though it's not the right time for any. Or am I doing it wrong?

Central list url dissapear

Hi,
I think of using this scheduler because of the central list json function.
The problem is: If I paste a link to a json file and press save, it just dissapears. If i open the node UI again it is gone. I write the url like this: http://www.******/jth/test.json
and the content is the same as in the example.
I hope some of you can test it.
Thanks,

-John

msg error when it first starts

The scheduler is connected to a Ind Digital Out bricklet ("FCU Enable"). When it is deployed or it first starts the tinkerforge node gives out the exception:

27/10/2016, 13:26:53 FCU Enable msg : errorTypeError: Cannot read property 'setValue' of undefined

After this it works ok and no more error messages are shown.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.