Use PowerShell to query your Bosch Home Connect Devices

Recently our Washdryer lost the function to dry, so we keep him to wash our clothes and needed to buy a new Dryer. The most important thing here (for me) was the possibility to have an API and to integrate with our Home Automation.

So after some research, “we” decided to buy a new dryer from Bosch with “Home Connect”. To be honest, my Girlfriend had no idea about this decision, she just wanted a new dryer 🙂

So, the Dryer was delivered and quickly connected to my Home Automation with Openhab.

But, can I use PowerShell to query the Bosch Home Connect API?

So I quickly started to do some tests and made it possible to start a Dryer Program by PowerShell 🙂

So, let’s see how this works

Preparation

The Documentation can be found here: Home Connect API Documentation (home-connect.com)

First, we need to create a Home Connect Account and then an API Program here: Register new Application | Home Connect Developer Program (home-connect.com)

Make sure that you use “Device Flow” as “OAuth Flow”

For the Redirect URI, you can use localhost

When the APP is created, note the Client ID and the Secret

$ClientID="00089089089089089E0C7F6863EB9250BFA2D4FED8089D4ADE8089089017B"
$Secret="ECC399E890890890890892F4699007D33A07E25A4408908908909089016C768"

Authentication

Now let’s see how to authenticate with the Home Connect API. Unfortunately, there is a manual step inside.

As you can read in the Docs, we have three steps.

  • Device Auth
  • User Approval – manual
  • Get Token

The following part will do the first step and return an URL, you need to open, log in and click Approve

$URL="https://api.home-connect.com"

$Body = @{
    "client_id"  = "$ClientID"
    "scope"   = "IdentifyAppliance Monitor Control "
}

$AuthURL="https://api.home-connect.com/security/oauth/device_authorization"
$VerificationRepsonse=Invoke-RestMethod -Method POST -Uri $AuthURL -ContentType "application/x-www-form-urlencoded" -Body $Body


$VerificationRepsonse.verification_uri_complete

When this step is finished, you can continue the PowerShell Code

$Body = @{
    "client_id"  = "$ClientID"
    "grant_type"   = "device_code"
    "client_secret" = "$Secret"
    "device_code" = "$($VerificationRepsonse.device_code)"
}

$AuthURL="https://api.home-connect.com/security/oauth/token"

$TokenRepsonse=Invoke-RestMethod -Method POST -Uri $AuthURL -ContentType "application/x-www-form-urlencoded" -Body $Body

$Header = @{
    "Authorization"  = "Bearer $($TokenRepsonse.access_token)"
}

Now we defined the $header Variable with our Request Token, so we are now authenticated and can go ahead.

Control Device

First, we need to Query the API for our Devices/Appliances.

$Appliances=Invoke-RestMethod -Uri "https://api.home-connect.com/api/homeappliances" -Method GET -Headers $Header

$Appliances.data.homeappliances

The Result shows a list of all Devices and their “haId” that the Unique ID what we need in the Next Steps.

So, now lets query the state of the Device with the following Code

$State=Invoke-RestMethod -Uri "https://api.home-connect.com/api/homeappliances/$($AppliANCES.data.homeappliances.haId)/status" -Method GET -Headers $Header

$State.data.status

What is important here, the that “RemoteControlStartAllowed” is “True” so that we can Start the Dryer by PowerShell.

This needs to be activated directly at the Dryer.

Start the Dryer

So, related to that Documentation we start a specific Program and need to build the JSON and Send a PUT Command.

https://api-docs.home-connect.com/programs-and-options#dryer

#Start a Program
#https://api-docs.home-connect.com/programs-and-options#dryer
$JsonBody = @"
{
    "data":{
        "key":"LaundryCare.Dryer.Program.Mix",
        "options":[
            {
                "key":"LaundryCare.Dryer.Option.DryingTarget",
                "value":"LaundryCare.Dryer.EnumType.DryingTarget.CupboardDry"
            }
        ]
    }
}
"@


Invoke-RestMethod -Uri "https://api.home-connect.com/api/homeappliances/$($AppliANCES.data.homeappliances.haId)/programs/active" -Method PUT -Headers $Header -Body $JsonBody -ContentType "application/vnd.bsh.sdk.v1+json"

To check the Result, let’s run the GET command


$Program=Invoke-RestMethod -Uri "https://api.home-connect.com/api/homeappliances/$($AppliANCES.data.homeappliances.haId)/programs/active" -Method GET -Headers $Header
$Program.data.options

And now we see the Program is running and active

Also, my Home Connect App is telling me, that the Program is active.

Github

You can find the Script in my GitHub Report for Bosch Home Connect: Seidlm/BOSCH-Home-Connect-PowerShell: BOSCH Home Connect PowerShell (github.com)

au2mate, everything
Michael Seidl, aka Techguy

BOSCH and Home-Connect, HomeConnect is a trademark of Robert Bosch BmbH or Bosch Corporation. I just used it here to have some fun.

2 thoughts on “Use PowerShell to query your Bosch Home Connect Devices”

  1. What I’m missing here: How does your Girlfriend now start the dryer? With PowerShell 🙂

Leave a Comment

Your email address will not be published. Required fields are marked *

*