Skip to content

Stateful timeseries#1980

Open
townsen wants to merge 9 commits into
emoncms:masterfrom
townsen:stateful_timeseries
Open

Stateful timeseries#1980
townsen wants to merge 9 commits into
emoncms:masterfrom
townsen:stateful_timeseries

Conversation

@townsen
Copy link
Copy Markdown
Contributor

@townsen townsen commented Jan 29, 2026

Making a PHPTimeSeries feed Stateful

The TimeSeries feeds in EmonCMS contain datapoints at irregular time intervals. When used
for graphing the values of those feeds at times within these intervals is usually 'null'
(unless by chance a datapoint exists within the interval). However when such a
TimeSeries represents the state of a system or a tariff cost the value at any point in
time is the most recent datapoint, even if that falls before the interval.

To help solve these two related problems we introduce four new Virtual Feed processes.

See the file STATEFUL_TIMESERIES.md for a full description

With these features you can create feeds that represent point-in-time tariff changes and graph your energy cost over time including standing charges and accurately reflected costs over long periods. There is a small limitation discussed in the document which would require more significant changes to alleviate. This is a start.

* Document in DEBUG.md
* Use HTTP API to update tariff data inputs
* More documentation about using stateful timeseries for costs
  and standing charges

* Use PHP DateInterval specifications for standing charge process
@townsen townsen force-pushed the stateful_timeseries branch from 98748b8 to 23ada1d Compare February 1, 2026 16:03
* Tests on PHP7.4 failing due to use of named parameters
* Keep the test happy even though precedence of the operators
  is explicitly defined in
  https://www.php.net/manual/en/language.operators.precedence.php
@TrystanLea
Copy link
Copy Markdown
Member

Hello @townsen

Thanks for this pull request, appreciate your interest in furthering emoncms development!

I'd be really interested in some more detail on how you are using this, are you using this with flat tariffs that only change e.g once a year? Do you use custom dashboards to visualise or are you able to use the emoncms apps?

@townsen
Copy link
Copy Markdown
Contributor Author

townsen commented May 4, 2026

Hi trystan,
I've been using emoncms for a few years now and find it rock solid. I use it to monitor my single phase electricity and gas consumption. I created this pull request as I wanted to see a graph of the cost of these items on a monthly, daily, hourly basis. The problem I faced with the simple dashboard is that they only allow a single specification of the rates (which change somewhat irregularly over time), and don't have a facility for the 'standing charges' that are part of the total bill. So I now manually enter 4 inputs into a variable feed timestamped with the date they become effective: electricity kWh rate, electricity daily standing charge rate, gas kWh rate and gas daily standing charge rate. These remain valid until the next date that they change. Then I setup some of the new processors like so:

Screenshot 2026-05-04 at 20 35 52

The results can then be plotted on a graph showing my total energy bill and breaking it down into its 4 constituent parts, like so:

Screenshot 2026-05-04 at 20 37 08

Another use I have for these processors is to graph the duty cycle of my underfloor heating - which is obviously either on or off and turns on or off at irregular times. Again this goes to a variable timeseries and by using the 'state' process I can producesa graph that shows the state of the UFH over time. The 'step' option on graphing can do a similar thing but if the transition occurred before the current time window then the step graph will not show the correct results, nor will it show the state extending into the future..

There are some issues with the conversion of variable times into fixed times which I discuss in the notes, but in practice they can be ignored. To fix those would require a more complex approach (apportioning a value that changes in the middle of a fixed interval) which I don't have the energy to try and implement right now.

I hope this helps.

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.

2 participants