Tesla climate control based on agenda using Flow

Since last week I have been the proud driver of a Tesla Model 3. After first trying Autopilot and then experiencing the acceleration capacity, I started looking at the Tesla app. In it you can control everything on the car, but what you can’t do is create a schedule when the climate control must be turned on and off. After some research I found out that a Tesla API could be used and that is how I came up with the idea to heat / cool the Tesla based on my agenda.

Now I also block my travel time in my agenda so I can use that as a trigger. At every meeting in my agenda, Flow checks 5 minutes before time to see if the word ‘Reizen’ appears in the title (that is dutch for travel).

If it really concerns ‘Reizen’ then we will log in to my Tesla account and create an access token. With this token we have access to execute further commands to the car.

If the login is successful, I will save the access token. We then collect from Tesla which car(s) are connected to this account. Multiple cars can be linked to 1 account. In my Flow, however, I assume that it is only 1. You can also see that I use the access token in the header for authorization.

I then request the current status of the car. I do this because I want to check if someone is currently in the car and the car is locked. Of course I don’t want Flow to change the climate control if someone is driving. That’s why I check if nobody is present and the car is locked.

We are dealing with a battery-powered car. And I would like to get into a car with a nice temperature, but not if this means that I can then no longer drive because the battery is empty. Hence I first check whether the battery is more than 30% full.

Then I get the current climate status. With that data (current inside temperature and set climate control temperature) I can check whether the climate control should actually be on. If this deviates more than 2 degrees, I will continue with the Flow.

If all these conditions are met, I activate the climate control of the Tesla. This makes me nice and warm in the winter and I don’t have to scratch ice. And in the summer it is nice and cool.

I still have a 15 minute delay built in after the activation of the climate control. Of course I don’t want ‘Reizen’ to be in my agenda but for some reason I didn’t go. And then my climate control has been on indefinitely. That is why Flow checks after fifteen minutes if someone is in the car. If not, he switches the climate control off again.

One flow triggers another

I was watching episode 2 of the Flow Pro Show and they asked some MVP’s what there favorite flow feature is. And of course, I immediately asked myself the same thing. And I choose the HTTP action and HTTP trigger. With those 2, a world of possibilities opens up, including 2 flows that call on each other.

My favorite trigger

As soon as you select the When a HTTP request is received and you save the flow, flow creates a unique link. This flow starts every time this link is invoked. And so you can have other flows perform the HTTP action and thereby activate the other flow.

It is also possible to send information back and forth between flows. To demonstrate that, I made 2 flows.

  • Flow 1 calls to flow 2 with the text “Hello”
  • Flow 2 retrieves that info and adds ” World” to it
  • Flow 2 send this back to flow 1 as a response

See below the flow designs and it’s test results.


Flow 2 – Design


Flow 2 – Testrun

Create a new Team with Forms and Flow

With the introduction of MS Teams within your company, you as an admin are faced with the decision whether you want to keep creating new teams open for everyone or not. By default, it is possible for anyone with a license to create a new team within MS Teams. If you do not want this and want to control the creation of MS Teams a bit more, it’s an option to create a Form with a Flow that handles the creation of a team with Microsoft Graph.

Step 1 – Manage who can create Office 365 Groups

First of all, you configure who can create new Office 365 groups. This also removes the option in MS Teams to create a new team. Microsoft has created this step-by-step plan for this.

Step 2 – Create an App registration in AzureAD

We are going to create the team with the create team function in the Microsoft Graph REST API. To be able to address this from Flow with application rights, we create an app registration with Group.ReadWrite.All rights.

Create a new app registration

In the Azure portal, go to Azure Active Directory and select App registrations. Click on the New application registration button and enter the details. A valid website must be entered in the Sign-on URL, but since we are going to address the app from Flow, this is not relevant. After creating, note the Application ID that has been created.

To grant the required rights to this app registration, click on the Settings button. Then click on Required permissions and then on Add. At item 1 Select an API you select Microsoft Graph. Under section 2 Select permissions, select Read and write all groups under the Application permissions heading. Then an admin must approve the rights by clicking on Grant permissions and confirming.

Next we will create a key by going to the menu option Keys. Under Passwords, enter a self-designed description in the Description field, select Never expires and click the Save button. Copy the key that is now displayed and save it properly. This is the only time this code is displayed.

Key for access to the app registration

Finally, we still need the tenant ID. You can find this by going into the Azure portal to Azure Active Directory. There you click on Properties and then you copy the Directory ID code. This is your tenant ID.

Now you have:

  1. a tenant ID
  2. an application ID
  3. a password (a.k.a. Secret)

Step 3 – Create Form

Request new team form

Go to http://forms.office.com and create a new form. As an example I have created a form with 3 questions:

  • Name? – Text
  • Description? – Text
  • Kind of team? – Choice

Depending on the last answer, I let the team name start with Dep- or Proj-. I do this to show that you can set up something of a naming convention for your teams. For example, you could also set the department name at the start of every teamname.

Step 4 – Create the Flow

Go to http://flow.microsoft.com and create a new blank flow. Use the When a new response is submitted from Microsoft Forms as a trigger and select the form that you just created in step 3. Then initialize 4 new string variables and enter the data from step 2 in the first 3 variables. The last variable iniStrTeamStart must remain empty.

Initialize 4 string variables

Then create a new Get response details action and select the form that was created in step 3 again. InResponse Id, select the List of response notifications Response Id of the trigger. An Apply to each will now be created automatically.

Load data from Forms

Then create a Switch that looks at the value Kind of team?. Add the Department and Project options. Within those options we create a Set variable that changes the value StrTeamStart to Dep– or Proj-.

Switch on kind of team

We then have to retrieve 1 more variable and that is the ID of the applicant. When creating the team, we must specify who should become the owner. I want to use the applicant for this, so we first request the user profile with the Get user profile (V2) action. Because I only need the ID of the applicant, not his name or anything, I fill the Select fields with ID.

Get user profile (V2) action to retrieve ID of the requester

And then we have arrived at the actual creation of the team. We use the HTTP action for this and will use it to perform a POST request to Microsoft Graph. The various properties of the new team are set in the body. In order to easily copy these properties, I also have them as text below the image. Note that if you have renamed the variables and/or actions, you will also have to adjust them when copying the body-text.

HTTP request to Microsoft Graph to create the new team
{
  "template@odata.bind": "https://graph.microsoft.com/beta/teamsTemplates/standard",
  "displayName": "@{variables('StrTeamStart')}@{body('Get_response_details')?['r4a6d0d326bfd43e3b47e9959bac1dd26']}",
  "description": "@{body('Get_response_details')?['r9d583ab44ac54742a785ba6738f1a3ac']}",
  "Visibility": "Private",
  "owners@odata.bind": [
    "https://graph.microsoft.com/v1.0/users/@{body('GetRequestersProfile')?['id']}"
  ],
  "memberSettings": {
    "allowCreateUpdateChannels": true,
    "allowDeleteChannels": true,
    "allowAddRemoveApps": true,
    "allowCreateUpdateRemoveTabs": true,
    "allowCreateUpdateRemoveConnectors": true
  },
  "guestSettings": {
    "allowCreateUpdateChannels": false,
    "allowDeleteChannels": false
  },
  "funSettings": {
    "allowGiphy": true,
    "giphyContentRating": "Moderate",
    "allowStickersAndMemes": true,
    "allowCustomMemes": true
  },
  "messagingSettings": {
    "allowUserEditMessages": true,
    "allowUserDeleteMessages": true,
    "allowOwnerDeleteMessages": true,
    "allowTeamMentions": true,
    "allowChannelMentions": true
  }
}

To make the flow more beautiful, there are a lot of extra options that I have added eventually. But for the overview I leave it at this. But for example consider:

  • An approval process
  • Keep a log of what is being requested and the status of approval
  • Offer different team templates in your form and take them into account when creating the team
  • Send a confirmation to the applicant
  • Post a welcome message to the new team or a video about how to use MS Teams
  • A check to build in if the team does not already exist
  • Put all the input into variables like I descriped in this blog.

An overview of the complete flow:

Overview of the flow for creating a new team

Change default browser language

When you create Flows and PowerApps you often seek the help of Google. Sometimes it’s just easier to search for the solution on forums, YouTube or sites like this one. And when you do find a solution you will see that almost all of the examples are in English. At that time you don’t want to waste time and energy with searching for the translation of that particular action or formula. So if you haven’t done this already, change the language of your browser into English.

I use Google Chrome (love the profiles) for working with Flow and PowerApps. To change the language press the three dots in the top right and click on Settings (in you’re own language of course). A new page opens, click on the bottom on Advanced. Scroll down till you see the language settings section. Change it into English and restart the browser.

Rename new actions

I have taught myself to change the name immediately with every new action that I add. I do this because I encounter a large flow that I created and lost the overview of what was happening where. Take, for example, the initialization of variables. If you have many variables and you do not rename the actions, it will look like this in no time:

Unclear actions

Now try changing that specific variable from a string to an integer…

Start by saving the input into variables

I don’t even make flows that long, but I already have a list of tricks. These are the things that make working with Flow easier. Especially if you want to adjust them later on. Start with saving the input in variables is one of those tricks.

Save the input into variables

Immediately at the start of your flow you start by initializing variables and saving the input of the flow in there. Later in the flow you then only use these variables. The big advantage of this is that it is much easier to adjust the trigger later. You can then change the trigger and only refill the variables at the beginning with the input of the new trigger. You do not have to make any further adjustments in the rest of your flow.

Confirm that the trigger AND the associated dynamic content will be deleted