HTTP-Shortcuts icon indicating copy to clipboard operation
HTTP-Shortcuts copied to clipboard

Allow to execute a shortcut periodically

Open googol42 opened this issue 3 years ago • 15 comments

Is your feature request related to a problem? Please describe. I use HTTP-Shortcuts to control my vacuum cleaner running valetudo. I have shortcuts to change the absorbency and water usage. Shortcuts to start and pausing actions. I have a shortcut to display all valetudo notifications. Currently I cannot reflect the robots state in HTTP-Shortcut. Note, some actions (like a full clean up) take quite some time, so the state will change at some point, but a state change can happen now or in 1 hour. Or can be triggered by another user (which e.g. uses the Valetudo UI).

I would like that my shortcuts reflect the current state. E.g. the number of unread notifications should be shown in brackets in the actions title. The "start" action should be disabled when the robot is currently not idling....

Describe the solution you'd like In addition to "global scripting" there should be a list of shortcuts which are (like multi shortcuts) executed one after the other. This list should be executed on a periodic basis (polling). The interval should be configurable. This would allow me to keep track of the current state and update my shortcuts accordingly.

Describe alternatives you've considered I created an action to update (some parts) of the state and executed this shortcut in the "Run before Execution" phase. But this makes the actual shortcuts slower and the state is updated too late. Remember, that the state changes can be triggered externally (e.g. other users) and can take very long. Also the UX wasn't great as the UI was often blocked. I also tried to execute this "update" shortcut in global scripting.

Additional context When implementing this a few things have to be considered:

  • I think neither successful execution nor failures should be reported to the user. At most there should be toast about an error. Otherwise one might get spammed by full screen dialogs once the polling started.
  • Maybe some parts of javascript should not be possible. E.g. user interaction.
  • Or a circuit breaker is needed: Display the first error, display the second error, and maybe the third, but then decrease the polling interval.
  • Polling should only be active when the app is a) open and b) the user is not editing shortcuts or changing settings.

googol42 avatar Sep 14 '22 16:09 googol42

The need for some kind of scheduling or repeated execution mechanism has come up a lot in feature requests, and I definitely want to look into this at some point, so thank you for your inputs and suggestions. I currently can't work on this, but will keep it open for when I hopefully have some more time and focus again.

Waboodoo avatar Sep 26 '22 09:09 Waboodoo

@Waboodoo I created a proof-of-concept (very bad code!) here: https://github.com/Waboodoo/HTTP-Shortcuts/pull/296 Can you have a look at it?

googol42 avatar Oct 07 '22 17:10 googol42

@googol42 I'll have a look at it when I have the time, which will likely be in a few weeks.

Waboodoo avatar Oct 09 '22 09:10 Waboodoo

To give an update here: I have not forgotten about this, I just haven't found much time and/or energy to work on this, and there have been other features and bugfixes I wanted to look at first.

I looked at your PR, and I think I can take some inspiration (in particular regarding the UI), but I won't be able to use the approach you use there, as it will not work reliably (in particular, it will only work while the app's process is still running). I have tried a few other approaches and found none so far that worked well enough with the existing scheduling setup that the app already has, so I'll need to make some improvements there first.

I still definitely want to make this feature happen, especially given that it's the most frequently requested one by far, but it will be some more time before it will become a reality.

Waboodoo avatar Dec 22 '22 10:12 Waboodoo

I've got a similar usecase / idea so I'm not sure if I should open another issue for it or add it to this one. Feel free to delete if you'd prefer me to open a new one.

I'd like to propose live widgets showing regularly updated values fetched by Webrequests. In my usecase I'd regularly fetch some of my tasmota hosts sensors like energy usage or temperature. I didn't find any appliable android software for this usecase online. In KDE Plasma I use the Command Output Widget: https://github.com/Zren/plasma-applet-commandoutput

Thanks for developing this awesome piece of software!

PureIncompetence avatar Dec 29 '22 14:12 PureIncompetence

@PureIncompetence Thanks for the input. I've thought about this before, to add some kind of widget that could display the curent value of a variable. So far I didn't get around to it, and I figured this would only really start to make sense once there's better support for running shortcuts automatically, such as on a schedule like this issue proposes. As such, I we can keep your idea here as part of the same issue, but the feature will likely only come at a later point.

Waboodoo avatar Jan 06 '23 11:01 Waboodoo

A first version of a periodic execution feature is now available with the release of version 2.30.0. You can find it in the shortcut's "Trigger & Execution Settings" section. I will keep this issue open, as I want to improve this feature a bit further, as well as adding something to support the usecase proposed by @PureIncompetence. Any additional feedback and inputs about the feature are welcome.

Waboodoo avatar Feb 15 '23 19:02 Waboodoo

Great to hear. I gave it a try and then realized that my use-case is not covered by the new feature. My use-case requires much shorter intervals (maybe execute every 5 seconds) and does not require the shortcut to be executed in the background but only in the foreground. But still, nice to see the progress :-)

googol42 avatar Mar 04 '23 10:03 googol42

@googol42 You should be able to achieve this via the already existing enqueueShortcut() function. Go to your shortcut's Scripting section and add the following code snippet to the appropriate code block:

enqueueShortcut(null, null, 5000);

The first argument to the function denotes the name or ID of the shortcut that you want to enqueue. You can pass null or an empty string to enqueue the current shortcut. The second argument is for variables you want to pass to that shortcut. You can pass null if you don't need to pass anything. The third argument is the number of milliseconds by which to delay the execution.

More information here: https://http-shortcuts.rmy.ch/scripting#trigger-shortcut

Waboodoo avatar Mar 04 '23 12:03 Waboodoo

Sorry, I don't understand how that would help me. I would need a feature to activate the shortcut automatically if and only if the app is running in foreground. Can you provide more details how that would be possible?

googol42 avatar Mar 04 '23 12:03 googol42

@googol42 Ah, then I misunderstood your use case. There is currently no support for having the shortcut exection repeat if and only if the app is open. But I'll keep that in mind as I further extend this feature in the future.

Waboodoo avatar Mar 04 '23 14:03 Waboodoo

Hi. So I tried to use this new feature to send my current position, so it desired to run it in the background. With the current implementation however (loading spinner being visible during execution) this causes my full-screen video playback (Netflix) to become minimized. Is it possible to achieve full background execution without any implications on the UI?

Owlbertz avatar Mar 17 '23 08:03 Owlbertz

@Owlbertz Unfortunately, currently this is not possible. There some large technical limitations here that I have not yet found a good solution for, so I likely won't be able to fix this issue any time soon. It is on my radar though and I want to look into it eventually.

Waboodoo avatar Mar 17 '23 12:03 Waboodoo

@googol42 , to accomplish this, you can install the Widgetify application. Through this application, you can have a page or a section of it as a widget on your mobile screen. It also offers various customization options. For example, you can set it to refresh the page every few seconds or specify the hours and days when this action should not be performed.

Of course, it would be great if @Waboodoo could implement this feature within the same application, eliminating the need to install any other application.

ehsansabet avatar Sep 08 '23 18:09 ehsansabet

Waiting for this as well. I have a simple case of an on/off switch which I would like to keep in sync with the actual state (by polling)

SpajicM avatar May 30 '24 19:05 SpajicM