Manage your smart-me.com plugs via PowerShell

This post is about using the smart-me REST API in PowerShell.

For more than a year I’m using smartmeters from smart-me. Unfortunately they are not compatible with Apple HomeKit or Google Home. But they provide a nice REST API. So let’s check out what we can do using their API.

Here’s the vendor’s documentation: https://smart-me.com/swagger

First of all, we need an authentication token. smart-me offers just “Basic Authentication”. So, let’s create our HTTP header.

This was easy. We will call it like this later in our script:

$Auth = New-SMHeader -Email "john.doe@gmail.com" -Pass "secret"

Since we do want to use friendly names to control our meters, we need to find out the device id because most of the REST API functions require the id and not the name of the device.

We will call it like this later in our script:

Get-SMDeviceIdByName -Name "Kitchen" -Headers $Auth

Before we toggle any switches on a device, we want to check if it’s already ON or OFF. The return value is either $true or $false.

Here’s how we call that later in our script:

Get-SMPowerStatus -Name "Kitchen" -Headers $Auth

Now comes the fun part. The power switch can be executed by using an “ObisCode”. This is some kind of an international standard for energy metering. You could find out this code by querying the available actions of your device.

https://smart-me.com:443/api/Actions/{DeviceId}
smart-me REST API powershell

The action itself we need to post in JSON format. The action value is 1 for power ON and 0 for power OFF.

Now, we are able to toggle the power using this nice and neat oneliner:

That’s one way to use the smart-me REST API with PowerShell.

Leave a Comment