WebThingsIO / gateway

WebThings Gateway
http://webthings.io/gateway
Mozilla Public License 2.0
2.61k stars 337 forks source link

Scheduler Add-on/Feature #2347

Closed madb1lly closed 4 years ago

madb1lly commented 4 years ago

Hi @mrstegeman,

I've worked out that one of the things I really need is a timer. Ideally this would be a 7-day timer, so different days could have different on/off setting for the timer. A timer as part of the virtual things add-on seems like the most suitable place to have this so that multiple timers can be created for multiple purposes.

I know that the DateTime and Cron add-ons can be used to create timers, but they are not timers directly, so often multiple Things must be created and sit on the UI before a timer can be created. For example to create a 7-day timer for my heaters I have one DateTime thing, one virtual on/off switch and 8 Cron Things... and if I want to add more periods when the Timer output is On (true) then I need to add more Things, rather than just another period to an existing timer.

Cheers :)

mrstegeman commented 4 years ago

Have you tried the "Timer" add-on?

madb1lly commented 4 years ago

Hi @mrstegeman thank you for the reminder about the Timer add-on. In my use case that would not reduce the number of things particularly, as I would still need the same number of Cron "On" event Things and would need a different timer Thing for each different period of time I wanted.

Maybe "scheduler" is a better term for what I'm looking for. Here is an example of what I would like to do:

Most good heating or hot water controllers come with a scheduler which can be configured for multiple periods per day on different days of the week; that is what I'm looking for.

mrstegeman commented 4 years ago

This seems like it'd be better for a separate "Scheduler" add-on. The Virtual Things add-on is specifically meant for testing our schemas and new ones which are in development. The custom thing functionality was added as an extra little tool for users after we figured out that people were using this for other purposes.

madb1lly commented 4 years ago

Okay so I either write this myself or raise an feature request issue somewhere else? Considering I'm time poor and in this case skills poor too (!) where should I raise the request ;)

mrstegeman commented 4 years ago

@madb1lly I've moved this to the main gateway repo, so no need to raise another issue. 😄

tim-hellhake commented 4 years ago

8 Cron Things

Soon it will be 2 😬 https://github.com/tim-hellhake/cron-adapter/issues/2

tim-hellhake commented 4 years ago

@madb1lly How would you expect the settings to look like? How about a row per period with

egorio commented 4 years ago

Another possible UI:

               Sun Mon Tue Wed Thu Fri Sat
 6:30 -  8:00  [x] [x] [x] [x] [x] [ ] [ ]
 7:30 -  9:00  [ ] [ ] [ ] [ ] [ ] [x] [x]
 9:45 - 11:15  [ ] [x] [ ] [x] [ ] [ ] [ ]
18:30 - 20:00  [ ] [ ] [x] [ ] [x] [ ] [x]
     [+]

Inspired by the way you set an alarm on the mobile phone - chose a time, then select days you want to let it work.

madb1lly commented 4 years ago

Thanks @mrstegeman :)

@tim-hellhake, I would expect to be able to create multiple scheduler Things, not just a single one. Each scheduler Thing would allow multiple time periods within 24 hours to be set and the applicable day of the week for each time period.

@egorio I like your mockup, that's quite straightforward. I saw a a graphical representation with 7 bars and True or False indicated by colour: https://image.winudf.com/v2/image/Y29tLmdpendpdHMuaGVhdHp5X3NjcmVlbl8yXzE1NDAzNzU5NDNfMDIy/screen-2.jpg?fakeurl=1&type=.jpg

Note that scheduler app has 4 states, not just 2, but for a normal scheduler I would expect 2 states - if more states are needed then we need to have more than one scheduler thing.

benfrancis commented 4 years ago

@madb1lly Ideally the scheduler wouldn't need to expose virtual scheduler "things" that aren't actual devices, because that will just clutter the UI.

@mrstegeman I was thinking about how a scheduler add-on could be implemented. I can imagine a calendar style UI as an extension add-on, but there would also need to be a back end service for long-running timers. One challenge is that because of process isolation and the way HTTP request handlers are set up over IPC, an add-on can't easily call the Web Thing API for devices from the back end. Do you have any suggestions for how this could be implemented? E.g. such that a setTimeout in a NodeJS back end process in an add-on could somehow manipulate the properties of other web things?

mrstegeman commented 4 years ago

An add-on can very easily call the REST API, and several already do that. The only annoying part is that the user has to manually create a token to use for the add-on. That's what #2249 (and #2098) are for.

benfrancis commented 4 years ago

Oh OK sorry, that makes sense. I was assuming you'd want to call the API from the front end where you already have the JWT. But yes, if you give the add-on a JWT then I suppose it's just a case of doing an HTTP request. Is that usually via localhost/gateway.local or the tunnel? If it's the former then how do we deal with TLS certificates and if it's the latter would that not work if the Internet connection goes down?

2249 sounds like a good idea. I'm not really sure what level of access an add-on should get by default and whether the user should have to grant certain permissions (similar to the global settings discussion).

mrstegeman commented 4 years ago

Yes, I think most just use localhost and accept the certificate error.

madb1lly commented 4 years ago

@madb1lly Ideally the scheduler wouldn't need to expose virtual scheduler "things" that aren't actual devices, because that will just clutter the UI.

That will be fine with me @benfrancis, less clutter is good, so long as there's no limit to the number of things that can have their own independent schedule.

mrstegeman commented 4 years ago

@madb1lly https://github.com/mozilla-iot/addon-list/pull/592

madb1lly commented 4 years ago

@mrstegeman @tim-hellhake Seen it! Wow, super fast work! 😲

I've tried it out and found a problem: https://github.com/tim-hellhake/scheduler-adapter/issues/1

Cheers 🙂