Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Pull request Compare This branch is 7 commits ahead, 1 commit behind fe01134:master.

Visualize IoT Asset Data in "Maximo Asset Monitor" using Python

In this Code Pattern we will show how to publish IOT Asset Data from external sources (Maximo) into the Watson IOT Analytics service. The data will allow us to then leverage Maximo Asset Monitor to observe individual building energy consumption and compare the performance of different buildings. The monitoring dashboards allow us to visualize energy consumption trends over time. This HTTP preload function could easily be modified to integrate to other IOT Platforms or data sources to allow you to quickly monitor your assets.

When the reader has completed this Code Pattern, they will understand how to:

The intended audience for this Code Pattern is application developers and other stakeholders who wish to utilize the power of Maximo Asset Monitor to quickly and effectively monitor any asset to ensure availability, utilization and efficiency.



  • Watson IOT Platform Analytics. This is a SaaS offering that allows you to register devices, collect IOT Data and build IOT applications. This add-on service extends "Watson IoT Platform" to include Maximo Asset Monitor. Sign up for an account here

  • Maximo. An IBM SAAS offering that allows you to register and manage assets. Sign up for a free trial here

  • HTTPPreload Python functions that allow you to collect IOT asset and sensor data from other IOT Platforms or data sources that can then be used to quickly monitor your assets in Watson IOT Platform Analytics.


  1. Setup your Python development environment
  2. Create an Entity Type in Watson IOT Platform
  3. Deploy function
  4. Schedule the function to collect asset data
  5. Create a Monitoring Dashboard to manage the asset
  6. View the Monitoring Dashboard with Building Energy Consumption


  • An account on IBM Marketplace that has access to Watson IOT Platform Analytics and Maximo Asset Monitor. This service can be provisioned here


Follow these steps to setup and run this Code Pattern.

  1. Setup your Python development environment
  2. Create an entity type
  3. Deploy Function
  4. Import data to source
  5. View Dashboard
  6. Update Function

1. Setup your Python development environment

Install Python

Mac comes with Python v2.7.9 recommend using Python v3.6.5 for using DB2. Launch Terminal

Install Brew, which is a package manager for Mac OS

/usr/bin/ruby -e "$(curl -fsSL”

Install Python

brew install python3

Verify version of Python is above v3

python --version

Install and Create a Virtual Environment

Launch Terminal

Install "pip". (Python Package Installer):

sudo easy_install pip

Install virtual environment to keep dependencies separate from other projects

sudo pip install virtualenv

Create a virtual environment

python3 -m venv env

Activate Virtual Environment, Install Python Dependencies and Verify Environment

Enter your Virtual Environment directory

cd env

Activate your virtual environment

source bin/activate

The result in Terminal should be something like:

(env) My-Mac: myuserid$

Clone this repository

git clone
cd watson-analytics-dashboard

Install dependencies

# Prereqs
pip install numpy
pip install sqlalchemy pandas ibm_db_sa urllib3 requests lxml sklearn ibm_db python-dotenv future

# Watson IOT Functions
pip install git+ --upgrade

pip install -r requirements.txt
  • Set PYTHONPATH to your project directory:
export PYTHONPATH="<root_project_directory>"

2. Create an entity type

Copy template.env and modify it to reflect your Maximo Credentials.

cp ./custom/template.env ./custom/.env

Copy your Watson IOT Platform Service credentials into a credentials.json file

Navigate to your Watson IOT Platform Analytics service

Explore > Usage > Watson IOT Platform Analytics > Copy to clipboard


If you've created a custom fork of this repo, modify your .custom/ to set your PACKAGE_URL as the forked Github repository:

PACKAGE_URL = 'git+'

# Change the class name if someone else has already published a function with the same name in your tenant function catalog.

class MaximoAssetHTTPPreload(BasePreload):
  • Invoke This script will create a "Buildings" Entity Type and execute the MaximoAssetHTTPPreload function to pull data from Maximo at a given interval:

3. Deploy Function

Next, we'll add our custom function to our newly created entity. This will enable the function to run every 5 minutes and pull the latest meter readings. Navigate to the "Add Data view", and select the MaximoAssetHTTPPreload function. We can get to this form by the following

Explore > Entity Types > Buildings > Add Data

Set values/credentials for your Maximo instance.

URL = <maximo_url>
usernam	= <username>
password = <password>
request = GET (select from drop down)

4. Populate data source

Here, we'll show how to add IoT data to a data source (Maximo). In this example, we'll use a Maximo instance. We'll begin by defining an "Asset Template". This will allow us to quickly generate multiple "Assets", which will represent buildings in this case. Access this form by searching for "Asset Templates" in the "Find Navigation Item" textbox in the upper left corner.

Each Asset can have multiple associated "Meters", which are used to track sensor readings over time. We'll add a "Temperature" meter and a "Energy" meter to our template.

Now that we have our asset template and associated meters defined, we can create a few building instances. We'll do this by clicking "Generate Building Assets". Provide a quantity and click "Ok".

After the building assets have been created, we can then look them up by clicking on "Assets" in the upper left menu. In the upper left "Find Asset" form, enter the number of one of the newly created assets.

Once the asset page loads, we can add data to the asset, select "Enter Meter Readings" in the lower left-hand menu, under the "More Actions" section. Provide values for the meters. In this example, be sure to add "temperature" values

Confirm the meter values have be saved by clicking "Manage Meter Reading History"

5. View Dashboard

Finally, we can view our dashboards by clicking the "Monitor" button on the left hand menu, and then selecting your newly created entity (maximoBuildings)

Next, select the default summary dashboard

This will show an overview of instance data for all registered entities.

6. Update Function (Optional)

If you're interested in pulling data from additional / alternative data sources, you'll need to make a few changes to the custom/ file, which drives the IoT Analytics logic.

In our case, we first added methods to query the Maximo api

def getBuildings (self ):
    q_endpoint = self.url + "/maximo/oslc/os/mxasset?" + "BUILDING"
    headers = { "maxauth": self.token }
    res = requests.get(q_endpoint, headers=headers)
    return buildings
def getMeters (self, asset_id = None):
    # hardcoding id for test TODO
    asset_id = "2112"
    q_endpoint = self.url + "/maximo/oslc/os/mxasset?" + asset_id
    headers = { "maxauth": self.token }
    res = requests.get(q_endpoint, headers=headers)
    meters = []
        meters = res.json()["rdfs:member"][0]["spi:assetmeter"]
        print(str(len(meters)) + " meters found")
        print("no meters found")
    return meters

These methods query the Maximo OSLC api to receive all buildings and meters that are associated with an Asset derived from the "Building" template

Next, we added these custom methods to the main execute method. The result of each method is then loaded into a response_data dictionary as a numpy array.

buildings = self.getBuildings()
response_data['building'] = np.array(buildings)
meterValues = self.getMeters()
response_data['temperature'] = np.array(meterValues)

Finally, commit and push these changes to git, and rerun the script to register the function changes

git add ./custom/
git commit -m "my function changes"
git push origin master

Learn more


This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ

You can’t perform that action at this time.