emsesp/EMS-ESP32

Feature: call schedule entries via command

Closed this issue · 5 comments

From an earlier discussion:

I'm thinking, @MichaelDvP, shall we extend the Scheduler so you can execute the event? Even if its disabled. That way you could create quite complex commands and conditions, keep it disabled and invoke it manually via the API.

Michael said:

Something like a new type of schedule: single action: inputs just activate, name, command and value: executes one time after activation and sets active to false. Activating in the dialogue means execution on the ok update button; in the list, it is always deactivate. Or we add a button for execution and skip the checkbox.

But you can also do this now: use trigger onChange with a custom value. By changing the custom value by command, you'll trigger the schedule. Or use condition 1,but then you have to send on and off within 10 seconds to have a one-time execution.

Originally posted by @proddy in #1835 (reply in thread)

Some more thoughts about that:

  • A single action command does not have a schedule trigger, so only show command, value, and name if no trigger is selected:
    grafik
  • The Execute button make it active. In the list the schedule and tme field is empty.
    grafik
    On Apply Changes the command is send and the schedule is deactivated.grafik
  • You can call a command from mqtt/api/terminal to activate and the schedule-command is executed and deactivated again:
ems-esp-s3:# call scheduler info
{
  "webtest": 0,
  "singleshot": 0
}
ems-esp-s3:# call scheduler singleshot
{
  "name": "singleshot",
  "active": 0,
  "command": "custom/test",
  "value": "custom/test + 3",
  "readable": true,
  "writeable": true,
  "visible": true
}
ems-esp-s3:# call scheduler singleshot on
Command executed. Check log for messages.
000+00:01:11.485 I 1: [command] Called command scheduler/singleshot (enable schedule item) with value on
000+00:01:11.485 I 2: [command] Called command custom/test (set custom value on ems) with value 8
ems-esp-s3:# call scheduler singleshot
{
  "name": "singleshot",
  "active": 0,
  "command": "custom/test",
  "value": "custom/test + 3",
  "readable": true,
  "writeable": true,
  "visible": true
}
ems-esp-s3:#

( BTW: i still don't like the Command executed. Check log for messages. message in console)

This is easy to implement, it only needs in scheduler::loop

    for (ScheduleItem & scheduleItem : *scheduleItems_) {
        if (scheduleItem.active && scheduleItem.flags == 0) {
            command(scheduleItem.name.c_str(), scheduleItem.cmd, compute(scheduleItem.value));
            scheduleItem.active = false;
        }
    }

That would work nicely, just checking for flags = 0. And I'll think about how we can make the WebUI more intuitive so you knows it's an "on command" type.

Please feel free to change or remove the "Command executed" console message.

@MichaelDvP I've made some small changes to the Web Scheduler, I'll do PR so you can test.

#1900

There's also a demo online at https://ems-esp.derbyshire.nl/scheduler - let me know what you think

I will add the translations to the web and then we can close this new feature

translations tracked here: #1920