This section walks you through getting FlexMeasures to run with the least effort. We’ll cover making a secret key, connecting a database and creating one user & one asset.
Install dependencies and the
flexmeasures platform itself:
pip install flexmeasures
Make a secret key for sessions and password salts¶
Set a secret key which is used to sign user sessions and re-salt their passwords. The quickest way is with an environment variable, like this:
(on Windows, use
set instead of
This suffices for a quick start.
If you want to consistently use FlexMeasures, we recommend you add this setting to your config file at
~/.flexmeasures.cfg and use a truly random string. Here is a Pythonic way to generate a good secret key:
python -c "import secrets; print(secrets.token_urlsafe())"
Set an environment variable to indicate in which environment you are operating (one out of development|testing|staging|production). We’ll go with
(on Windows, use
set instead of
echo "FLASK_ENV=development" >> .env
The default is
production, which will not work well on localhost due to SSL issues.
Preparing the time series database¶
Make sure you have a Postgres (Version 9+) database for FlexMeasures to use. See Handling data (section “Getting ready to use”) for instructions on this.
If you install this on localhost,
127.0.0.1and the port can be left out. (on Windows, use
Create the Postgres DB structure for FlexMeasures:
flexmeasures db upgrade
This suffices for a quick start.
For a more permanent configuration, you can create your FlexMeasures configuration file at
~/.flexmeasures.cfg and add this:
Add a user¶
FlexMeasures is a web-based platform, so we need a user account:
flexmeasures add user --username <your-username> --email <your-email-address> --roles=admin
This will ask you to set a password for the user.
Giving the first user the
adminrole is probably what you want.
Populate the database with some standard energy asset types, weather sensor types and a dummy market:
flexmeasures add structure
Add your first weather sensor¶
Weather plays a role for almost all use cases.
FlexMeasures supports a few weather sensor types out of the box (“temperature”, “wind_speed” and “radiation”), but you need to decide which ones you need and where they are located.
Let’s use the
flexmeasures CLI Commands to add one:
flexmeasures add weather-sensor --name "my rooftop thermometer" --weather-sensor-type-name temperature --unit °C --event-resolution 15 --latitude 33 --longitude 2.4
Add your first asset¶
There are three ways to add assets:
Head over to
http://localhost:5000/assets and add a new asset there.
Or, use the
flexmeasures CLI Commands:
flexmeasures add asset --name "my basement battery pack" --asset-type-name battery --capacity-in-MW 30 --event-resolution 2 --latitude 65 --longitude 123.76 --owner-id 1
Here, I left out the
--market-id parameter, because in this quickstart scenario I’m fine with the dummy market created with
flexmeasures add structure above.
For the ownership, I got my user ID from the output of
flexmeasures add user above, or I can browse to FlexMeasures’ user listing and hover over my username.
Finally, you can also use the POST /api/v2_0/assets endpoint in the FlexMeasures API to create an asset.
It’s finally time to start running FlexMeasures:
(This might print some warnings, see the next section where we go into more detail)
In a production context, you shouldn’t run a script - hand the
app object to a WSGI process, as your platform of choice describes.
Often, that requires a WSGI script. We provide an example WSGI script in continuous_integration.
You can visit
http://localhost:5000 now to see if the app’s UI works.
When you see the dashboard, the map will not work. For that, you’ll need to get your MAPBOX_ACCESS_TOKEN and add it to your config file.
You can use the POST /api/v2_0/postMeterData endpoint in the FlexMeasures API to send meter data.
issue 56 should create a CLI function for adding a lot of data at once, from a CSV dataset.
Also, you can add forecasts for your meter data with the
flexmeasures add command, here is an example:
flexmeasures add forecasts --from-date 2020-03-08 --to-date 2020-04-08 --asset-type Asset --asset my-solar-panel
You can also use the API to send forecast data.
Other settings, for full functionality¶
Set mail settings¶
For FlexMeasures to be able to send email to users (e.g. for resetting passwords), you need an email account which can do that (e.g. GMail). Set the MAIL_* settings in your configuration, see Mail.
Install an LP solver¶
For planning balancing actions, the FlexMeasures platform uses a linear program solver. Currently that is the Cbc solver. See FLEXMEASURES_LP_SOLVER if you want to change to a different solver.
Installing Cbc can be done on Unix via:
apt-get install coinor-cbc
(also available in different popular package managers).
We provide a script for installing from source (without requiring
sudo rights) in continuous_integration.
More information (e.g. for installing on Windows) on the Cbc website.
Start collecting weather data¶
To collect weather measurements and forecasts from the DarkSky API, there is a task you could run periodically, probably once per hour. Here is an example:
flexmeasures add external-weather-forecasts --location 33.4366,126.5269 --store-in-db
DarkSky is not handing out tokens anymore, as they have been bought by Apple (see issue 3).
Preparing the job queue database and start workers¶
To let FlexMeasures queue forecasting and scheduling jobs, install a Redis server and configure access to it within FlexMeasures’ config file (see above). You can find the necessary settings in Redis.
Then run one worker for each kind of job (in a separate terminal):
flexmeasures run-worker --queue forecasting flexmeasures run-worker --queue scheduling
You can also clear the job queues:
flexmeasures clear-queue --queue forecasting flexmeasures clear-queue --queue scheduling
When the main FlexMeasures process runs (e.g. by
flexmeasures run), the queues of forecasting and scheduling jobs can be visited at
http://localhost:5000/tasks/schedules, respectively (by admins).
When forecasts and schedules have been generated, they should be visible at
http://localhost:5000/analytics. You can also access forecasts via the FlexMeasures API at GET /api/v2_0/getPrognosis, and schedules via GET /api/v2_0/getDeviceMessage.