Skip to content

Schedules as automations - #2293

Draft
Flix6x wants to merge 18 commits into
feat/2288-automations-for-forecastsfrom
feat/2288-schedule-automations
Draft

Schedules as automations#2293
Flix6x wants to merge 18 commits into
feat/2288-automations-for-forecastsfrom
feat/2288-schedule-automations

Conversation

@Flix6x

@Flix6x Flix6x commented Jul 11, 2026

Copy link
Copy Markdown
Member

Description

Milestone 2 of #2288 (stacked on #2290): automations can now compute schedules on a recurring basis, alongside forecasts.

  • flexmeasures add automation --type schedules validates the parameters as a schedule trigger message (AssetTriggerSchema, i.e. what [POST] /assets/(id)/schedules/trigger accepts, without the asset id). Omitting start makes each run schedule from the run time (floored to the message's resolution, if given); a fixed start draws a warning since every run would compute the same period.
  • The runner dispatches to the same job creators as the API trigger endpoint (sequential/simultaneous), so asset-level flex config is honored — a minimal trigger message (e.g. just duration) suffices when the flex config lives on the asset.
  • Job provenance for scheduling jobs: the scheduling job creators accept an optional trigger dict stored as job meta; the API trigger endpoint records API, flexmeasures add schedule --as-job records CLI, and automations record automation + id. The status page's Created Via column picks this up automatically.
  • Automation job stats now count scheduling jobs (asset-level wrap-up jobs and per-sensor device jobs) for schedules automations.
  • UI: the Schedules tab on the automations page is now enabled; automations are filtered by type per tab.

How to test

echo 'duration: "PT12H"' > trigger-message.yml
flexmeasures add automation --asset <id> --name "Hourly schedules" --cron "0 * * * *" --type schedules --parameters trigger-message.yml
flexmeasures jobs run-automations

Tests: pytest flexmeasures/cli/tests/test_automations.py flexmeasures/data/tests/test_automations.py flexmeasures/api/v3_0/tests/test_asset_schedules_fresh_db.py

Notes for review

related items

closes #2370

🤖 Generated with Claude Code

https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX

Flix6x and others added 3 commits July 11, 2026 18:29
The scheduling job creators accept an optional trigger dict (stored as job
meta data), like the forecasting pipeline already does. The API trigger
endpoint records origin API; the CLI and automations follow in the next
commit. The status page's 'Created Via' column picks this up automatically.

Part of #2288

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX
Automations now also support the 'schedules' type:

- `flexmeasures add automation --type schedules` validates the parameters as
  a schedule trigger message (per the AssetTriggerSchema, as accepted by the
  API trigger endpoint, without the asset id). The schedule 'start' may be
  omitted, in which case each run schedules from the run time (floored to the
  message's resolution, if given) — a fixed start draws a warning.
- The runner dispatches schedules automations to the same job creators as the
  API trigger endpoint (sequential or simultaneous), recording trigger meta
  data (origin automation) on the queued jobs; `flexmeasures add schedule
  --as-job` now records origin CLI.
- Job stats for schedules automations are counted from the scheduling job
  cache (asset-level wrap-up jobs and per-sensor device jobs).
- The UI automations page's Schedules tab is now enabled, with automations
  filtered by type per tab.

Part of #2288

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Rbix8k1JfeUWNXEmHEZVpX
@BelhsanHmida BelhsanHmida linked an issue Jul 30, 2026 that may be closed by this pull request
Context:
- PR #2293 is stacked on the reviewed forecast automation branch.

Change:
- Merge the reviewed parent and preserve schedule automation behavior across the five semantic conflicts.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- Schedule automations do not use a data generator, but the reviewed forecast automation schema required one.

Change:
- Make the foreign key nullable while retaining a database check that forecasts always have a generator.
- Add a forward migration without weakening data-source deletion semantics.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- Review uncovered untested forecast-only options, invalid durations, and DST start calculation.

Change:
- Add CLI and trigger-preparation regressions while retaining forecast sensor validation.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- Persistence, inherited flex configuration, descendant statistics, and job counts lacked realistic coverage.

Change:
- Move automation service tests under the fresh-database fixture and add end-to-end schedule regressions.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- API provenance was not asserted across asset and sensor schedule jobs.

Change:
- Verify API trigger metadata on sequential descendants, wrap-up jobs, and sensor jobs.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- The asset automation page tests still targeted the former single table.

Change:
- Assert type-specific tables, error rendering, filters, and hidden-tab column adjustment.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- Minimal asset schedules lost stored defaults, invalid timing could execute, provenance was incomplete, and descendant jobs were miscounted.

Change:
- Validate and floor fixed durations safely, inherit stored flex configuration, preserve provenance, and count the jobs actually dispatched.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- Schedule automation creation silently accepted forecaster settings that could never affect scheduling.

Change:
- Detect supplied forecast-only options and return a user-facing usage error.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- DataTables initialized in the hidden schedule tab could render with stale column widths.

Change:
- Add tab accessibility state and adjust initialized table columns when a tab becomes visible.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- The feature guide linked only to the API root and omitted fixed-start and duration constraints.

Change:
- Document canonical fields, runtime start behavior, timing validation, and generator-free schedule automations.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- Manual testing exposed raw parser exceptions for malformed automation files.

Change:
- Require a user-facing usage error for invalid YAML in both config and parameter files.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- PyYAML parser errors escaped automation creation without a useful CLI message.

Change:
- Translate malformed config and parameter files into a normal Click usage error.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- Manual execution showed minimal automations failing for a one-device asset tree.

Change:
- Exercise both simultaneous and sequential dispatch using realistic flex configuration stored on the child asset.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- A one-device asset tree collapsed to sensor scheduling without a sensor, and sequential dispatch could not resolve its stored output.

Change:
- Preserve asset-triggered flex models as a list and resolve sequential device sensors from stored consumption or production outputs.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Context:
- Scheduling service docstrings did not distinguish single-job and sequential provenance behavior.

Change:
- Document where trigger metadata is stored and correct the simultaneous return description.

Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schedules as automations

2 participants