FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Stateful timeseries by townsen · Pull Request #1980 · emoncms/emoncms · GitHub

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 commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

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 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

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 commented May 4, 2026

Copy link
Copy Markdown
Contributor Author

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:

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:

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.

Copy link
Copy Markdown
Member

Sorry for the delay @townsen thanks for coming back to me with the above.

In many ways I think your solution to this is elegant and clearly functional - but if I'm honest Im currently of the mind that I would like to ultimately deprecate PHPTimeSeries and limit Emoncms to PHPFina fixed interval only (removing all the other engines as well). I also try to avoid virtual feeds unless for simple quick calculations . The reason for this is that once data is in PHPFina format - which matches the way we collect all our data at fixed interval - access and post processing of that data becomes very efficient (post processing being something we're doing more and more e.g for the MyHeatpump and the new MyElectricFlow dashboards) - and so I want to explore if there are any alternative approaches that we could use to meet your same requirements before merging this and increasing project scope.

One option could be just to record the tariff information to PHPFIna at hourly resolution, I appreciate in many ways that's overkill in terms of disk storage but I think it would be possible to work out a solution that solved it this way.

Another - which is probably the way I would do it personally is to build a custom emoncms app with a nice UI interface to enter new tariff change points - you could do quite a lot more in an app such as calculate summaries/totals for longer periods etc. This could be a custom app for your own use rather than included in the public repo though you could also share it if any others have the same requirements..

Do you think either of these could be a solution to your requirements?

townsen commented Jun 18, 2026 via email

Copy link
Copy Markdown
Contributor Author

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL