Tesla Realtime Dashboard – PowerBI and Powershell

November 9, 2021

The Mission

Fleetsu was proud to be a part of iDriveWA – Western Australia’s first zero emission fleet transition conference & exhibit. What better opportunity to showcase the groundbreaking work that we have been doing in the electric vehicle automotive data space?

Wherever Fleetsu goes, we go with lots of data, and the central question becomes: What is the most straightforward way to display electric vehicle data to a large audience?

Welcome to Part 3 of our series on data manipulation with the Fleetsu API (Be sure to check out Part 1 & Part 2!)

The Dashboard

Above, you can see the finished product – a PowerBI Dashboard connected to streaming data from a Tesla Model 3. Let us show you how you can do the same thing in quickly and easily with the power of Fleetsu’s API. 

Creating a dashboard like this requires several components working together:

Fleetsu’s API First Platform

Powershell Invoke-Request

Power BI Realtime Streaming

Oh and did I mention a Tesla? Just go out and grab one of those as well. 

PowerBI Realtime Streaming Dataset

This tutorial assumes that you have a PowerBI License, but if you don’t they offer a free trial that you can use to test this out.

Step 1. Log into your PowerBI Web portal and create a new Workspace. I have called mine “Tesla”.    

Step 2. Next, select Streaming dataset under the New menu.

Step 3. When prompted, choose API as the source of your data and continue by clicking on Next.

Step 4. You will then get a dialogue prompting a name for your Dataset, as well as all the different data types that you would like to display. The json object at the bottom is automatically generated, don’t worry if it looks a bit different.

You can see my selections below.  

Step 5. Once created, you will now see your newly named dataset appear in the table on the main screen. Click the 3 dot menu to the right of the Name column to reveal a dropdown menu.

Step 6. In the resulting menu, navigate to the bottom of the list and then click on API Info to display information that we need to connect to our other main components and create the dashboard.

This page gives us everything we need to push data into our currently empty streaming dataset. For this tutorial we are mainly interested in the Powershell script, so copy out everything that you can into a notepad application for later.

Getting the Data from Fleetsu via Powershell

Now that we have a painted target, we need a bow and arrow. The arrow is the Fleetsu API and the bow for our purposes is Powershell.

As our goal is to display the most current information against the asset as a whole (rather than just the most recent event) we are turning to the Extended Information Tab, as this displays all asset parameters and their latest values. If you do not have access to the Ext. Info Tab against assets please reach out to your Customer Success Manager for more information.

If you want to grab the same data, here’s the format of the API endpoint to use:

https://app.fleetsu.com/v1/assets/XXXXXXXX-XXXX-XXXX-XXXX-X/parameters?_extend%5Bevent/parameter/type%5D%5B_fields%5D=parameter%2Cdescription%2CparameterGroup%2Cunit&_extend%5B_sort%5D=parameterGroup%2Cdescription%2Cparameter&_sort=parameterGroup%2Cdescription%2Cparameter&_start=1&_limit=500&enabled=1

That’s Fleetsu taken care of, but what about Powershell?

Our first step, after launching Powershell, is to lay the foundation for using it to query Fleetsu. For this we need to give it our credentials, encode them, and give it the endpoint that we just defined. Here’s some example code for doing that:

#Set username and Password
$username = 'dale.wright@fleetsu.com'
$password = 'setecastronomy'

#Encode them pair to Base64 string
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($username):$($password)"))

#Set the Headers and url to Call
$headers = @{ Authorization = "Basic $encodedCredentials" }

#Set the URL to where we are getting the data
$url = 'https://app.fleetsu.com/v1/assets/XXXXXXXX-XXXX-XXXX-XXXX-X/parameters?_extend%5Bevent/parameter/type%5D%5B_fields%5D=parameter%2Cdescription%2CparameterGroup%2Cunit&_extend%5B_sort%5D=parameterGroup%2Cdescription%2Cparameter&_sort=parameterGroup%2Cdescription%2Cparameter&_start=1&_limit=500&enabled=1'

We’re now ready to make our first fateful call to the API so that we can get the data.

This involves adding the following lines to “ConvertFrom-Json” so we can obtain a JSON object in $extendedData

#Make the call and convert it to JSON
$extendedData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers -UseBasicParsing | ConvertFrom-Json 

Here’s a snippet of the results!

total start end results

—– —– — ——-

  172     1 172 {@{parameterKey=XXXXXXXX-XXXX-XXXX-XXXX-X-assetOdometer; deviceId=XXXXXXXX-XXXX-XXXX-XXXX-X; parameter=assetOdometer; value=14623.64;

The most important data in this packet is definitely the description and the parameters for what we are doing. To limit our results to just these bits issue the following command to stuff them into a $teslaParameters variable.

#Lets Select only the values I want into a Parameter Variable
$teslaParameters = $extendedData | select -expand results | select @{n="Description"; e={ $_.type.description } } ,value  

What follows is much easier to work with.

Now that we’ve got what we came for, let’s aim our payload at Power BI. To do this, we need to first select the parameters that we want from inside our variable.

#Create the Payload Dictionary
$payload = @{}

#Populate all the Values for my Dictionary
$payload.add("CurrentDate",(get-date))
$payload.add("Odometer",($teslaParameters | Where-Object Description -eq "Odometer" | select -ExpandProperty value))
$payload.add("Total DC Charge",($teslaParameters | Where-Object Description -eq "Total DC Charge" | select -ExpandProperty value))
$payload.add("Total AC Charge",($teslaParameters | Where-Object Description -eq "Total AC Charge" | select -ExpandProperty value))

The main part of this being:

$teslaParameters | Where-Object Description -eq "Odometer" | select -ExpandProperty value  

This simply draws information from the $teslaParameters object where the Description equals Odometer. The “ExpandProperty” bit afterwards tells it just to return the value only.  

That is our payload built and ready to go.

Hopefully by this stage you haven’t closed the text editor where you pasted data from our Power BI screen. This is where we need to put it. Lastly, we invoke the method to push the data. That’s it! We’re now ready to return to Power BI

#Define Power BI Realtime end point
$endpoint = "https://api.powerbi.com/beta/XXXXXX/datasets/XXXXXXXXX/rows?key=XXXXX"
#Call the Method and send data to PowerBI
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

Code Summary – PowerShell

Here’s the entire thing in one place.

#Set username and Password
$username = 'dale.wright@fleetsu.com'
$password = 'setecastronomy'

#Encode them pair to Base64 string
$encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes("$($username):$($password)"))

#Set the Headers and url to Call
$headers = @{ Authorization = "Basic $encodedCredentials" }
$url = 'https://app.fleetsu.com/v1/assets/XXXXXXXX-XXXX-XXXX-XXXX-X/parameters?_extend%5Bevent/parameter/type%5D%5B_fields%5D=parameter%2Cdescription%2CparameterGroup%2Cunit&_extend%5B_sort%5D=parameterGroup%2Cdescription%2Cparameter&_sort=parameterGroup%2Cdescription%2Cparameter&_start=1&_limit=500&enabled=1'

#Make the call and convert it to JSON
$extendedData = Invoke-WebRequest -Uri $url -Method Get -Headers $headers -UseBasicParsing | ConvertFrom-Json 

#Lets Select only the values I want into a Parameter Variable
$teslaParameters = $extendedData | select -expand results | select @{n="Description"; e={ $_.type.description } } ,value 
Write-Output($teslaParameters)

#Create the Payload Dictionary
$payload = @{}

#Populate all the Values for my Dictionary
$payload.add("CurrentDate",(get-date))
$payload.add("Odometer",($teslaParameters | Where-Object Description -eq "Odometer" | select -ExpandProperty value))
$payload.add("Total DC Charge",($teslaParameters | Where-Object Description -eq "Total DC Charge" | select -ExpandProperty value))
$payload.add("Total AC Charge",($teslaParameters | Where-Object Description -eq "Total AC Charge" | select -ExpandProperty value))

#Define Power BI Realtime end point
$endpoint = "https://api.powerbi.com/beta/XXXXXX/datasets/XXXXXXXXX/rows?key=XXXXX"

#Call the Method and send data to PowerBI
Invoke-RestMethod -Method Post -Uri "$endpoint" -Body (ConvertTo-Json @($payload))

Creating the Realtime Dashboard

Now that the hard part is done, we can start getting our dashboard laid out. Start off by returning to the main page of Power BI and selecting Dashboard from the New menu.

You should now see a blank canvas. From here, find the right-most ribbon button entitled Edit and select Add a tile.

On the popup menu that follows, drop down below the line to choose from Real-time Media and pick the only option which is Custom Streaming Data before hitting the Next button.

On the next page, there’s a section called Your Datasets that should contain whatever you called your dataset at Step 4 in the beginning. You can see in the screenshot below that we called ours “Tesla Dataset”. The Next button lets us get a bit more specific.

Within PowerBI, visualizations determine the nature of the tile, and include gauges, line graphs, or just integer values. For our purposes we’re choosing Card here so that we can display the most recent value as a number on the dashboard. It is worth noting that Power BI has a major limitation in that you can only display numbers in this way, and if your data transmits a text value you will need to convert it into a number that makes sense to viewers.

As for Fields, your options will correspond to the values defined back at Step 4 as well. Don’t click Next just yet.


Clicking on the paintbrush icon which sits as a sort of tab underneath the dropdown menu for Visualization Type switches your view to reveal the two options around how to display the number value. You can use the Display units to summarise by thousands or ten thousands for example, and the decimal places to control rounding. Our experience has not been good with the fidelity of rounding on these values, and we recommend that you choose two decimal places at least for most Fleetsu data.

Hitting Next will create the tile in your dashboard! Success!

Rinse and repeat for as many tiles as you have data-points.

The final step in the process is to schedule the Powershell script to automatically run at regular intervals. This can be achieved in several ways, but the most straightforward would be to register a scheduled job on a Windows server. So that we could demonstrate the state change of doors opening and closing, we set 3 seconds for our demonstration.

When your dashboard is finished, feel free to add image tiles and play with the look and feel – we got quite a few compliments on the day for our effort!

Tesla Dashboard

If you’re an existing Fleetsu customer and would like to start using the API please reach out to your Customer Success Manager for hands on assistance. If you’re not yet a Fleetsu customer, get in touch and you too can start capturing and using your own automotive data.

Share this post

Share on facebook
Share on twitter
Share on linkedin
Share on email

Get a quote

We offer the most scalable and feature rich solution on the market to suit fleets of any size

Get started with Fleetsu

Please take a moment to fill out this quick questionnaire and we will get in touch to discuss how we can help you.