# \[TUTORIAL\] How to get notified about which charging station are free while driving

**URL:** <https://community.homey.app/t/tutorial-how-to-get-notified-about-which-charging-station-are-free-while-driving/118161>\
**Category:** Tutorials\
**Tags:** homey-pro\
**Created:** [October 14, 2024, 9:11pm UTC](https://community.homey.app/t/tutorial-how-to-get-notified-about-which-charging-station-are-free-while-driving/118161 "2024-10-14T21:11:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel3](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@daniel3](https://community.homey.app/u/daniel3)\
**Post date:** [October 14, 2024, 9:11pm UTC](https://community.homey.app/t/tutorial-how-to-get-notified-about-which-charging-station-are-free-while-driving/118161/1 "2024-10-14T21:11:58Z")

</div>

Since I own an electric car with a relatively small battery, I need to charge it regularly. Unfortunately, I can’t do this at home, so I’m dependent on the availability of public charging stations in the area. This is generally fine, but one thing that bothers me is that you only find out whether a charging station is occupied when you actually get there. If it is occupied, you either have to hope the next station is available, or pull out your phone to check which charging stations are free. Both options feel like a missed opportunity. Ideally, you’d want to be informed in advance. This is what I tried to solve with the tutorial described here.

With the help of ChatGPT, I created a HomeyScript that informs me about which charging stations are available. This notification is then sent to my phone, allowing me to play it out loud through Android Auto while I’m driving. This way, I know exactly which charging stations are free and where to drive to charge my car.

 ![Example of the notification within Android Auto.](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/c/1c6eaa2702dee4439a5674323b07c7d182eb61ec.jpeg)

# What do we need?

- [TomTom EV Service](https://homey.app/nl-nl/app/com.tomtom/TomTom-EV-Service/)
- [HomeyScript](https://homey.app/nl-nl/app/com.athom.homeyscript/HomeyScript/)
- Android phone with Android Auto
- [Tasker](https://play.google.com/store/apps/details?id=net.dinglisch.android.taskerm&hl=en)
- [AA Notification Forwarder](https://github.com/ztNFny/AANotificationForwarder)
- [_Optional: AutoLocation_](https://play.google.com/store/apps/details?id=com.joaomgcd.autolocation&hl=en)
- [_Optional: OpenWeather or another weather app_](https://homey.app/nl-nl/app/nu.baretta.openweathermap/OpenWeather/)

# Step 1: Setting up the charging stations

With the TomTom app installed, we can add the charging stations that interest us because they are nearby or, for example, because they are cheaper. If you’re unsure how to set up the TomTom app, MartijnPoppen has an [excellent guide](https://community.homey.app/t/app-pro-tomtom-ev-service/58383/4) on how to request the API key and add new charging stations.

 ![Charging Stations within Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/0/0/00de01de056bcf1f9846ca39140e8fca0280360b.png)

Keep in mind that, at the time of writing, TomTom allows 2500 free API requests per day. So, we adjust the update interval based on the number of charging stations we’ve added. This can be found in the settings of the added charging station. The ten charging stations I have added are set to either 300 seconds or 600 seconds to stay within the limit of 2.500 requests per day.

# Step 2: Weather conditions (optional)

I don’t mind walking a bit further to charge my care somewhat cheaper. But if it’s pouring rain, I’ll pass on that option. The notification takes weather conditions into account when it’s sent. If it’s raining, the cheaper but farther charging station is not included in the list of available stations. I use OpenWeather for this, where I’ve set my home address as the location when I added the _1. weather, current (location)_ as a new device within Homey. For more information on how to set this up, RonnyW has written an [excellent guide](https://community.homey.app/t/app-pro-openweather/61482) as well. If you don’t mind braving the elements, you can skip this step 😉 .

# Step 3: The HomeyScript

Now comes the fun part. With the charging stations and weather conditions set, we can query which stations are available. We only want to see charging stations where at least one charging point is available. It’s also not useful to hear about ten different stations being available, so we set a limit of three available stations in the notification. As mentioned in step 2, weather conditions are also taken into account.

```auto
// Common variables
let devices = await Homey.devices.getDevices();
let availableChargingPoints = [];
const capabilitiesToCheck = [ 
// 'measure_amount_available.5.Outlet', 
  'measure_amount_available.17.Outlet', 
  'measure_amount_available.11.Outlet'
];  
let firstLineChargingPoints = "De volgende laadpunten zijn beschikbaar: \n";
let devicesMap = new Map();

// Define all laadpalen with their desired order
const laadpalenOrder = {
  "A": 1,
  "B": 2,
  "C": 3,
  "D": 4,
  "E": 5,
  "F": 6,
  "G": 7,
  "H": 100,
  "I": 101,
  "J": 102,
  // Add more laadpalen as needed
};

// Get the weather device by ID
const weatherDevice = devices['c2c1ca48-1098-418e-a557-77134aec18d9'];
let rainAboveThreshold = false;

// Check if the weather device exists and has the measure_rain capability
if (weatherDevice && weatherDevice.capabilitiesObj.measure_rain) {
  const measureRain = weatherDevice.capabilitiesObj.measure_rain.value;
  if (measureRain > 2) {
    rainAboveThreshold = true; // If the rain measure is above the threshold, set the flag
  }
}

for (const device of Object.values(devices)) {
  // Ensure capabilitiesObj exists for the device and the device has the specific driver ID
  if (!device.capabilitiesObj || device.driverId !== 'homey:app:com.tomtom:charging_availability') continue;

  for (const capabilityToCheck of capabilitiesToCheck) {
    const capability = device.capabilitiesObj[capabilityToCheck];
    if (capability && capability.value > 0) {
      
      // Remove "laadpaal" from device name and trim
      const deviceNameWithoutPrefix = device.name.replace("Laadpaal", "").trim();

      // Aggregate capability values for each device
      if (devicesMap.has(deviceNameWithoutPrefix)) {
        devicesMap.set(deviceNameWithoutPrefix, devicesMap.get(deviceNameWithoutPrefix) + capability.value);
      } else {
        devicesMap.set(deviceNameWithoutPrefix, capability.value);
      }
    }
  }
}

// Process devicesMap to create entries, including order information
for (const [deviceName, totalValue] of devicesMap.entries()) {
  // If rain is above threshold, skip adding Laadpaal A to the available charging points
  if (rainAboveThreshold && deviceName === "A") {
    continue;
  }

  // Get the order from the predefined list, or default to a high number for unordered laadpalen
  const order = laadpalenOrder[deviceName] || 999;
  const entry = { order, text: `- ${deviceName}: ${totalValue};` };
  availableChargingPoints.push(entry);
}

// Sort entries by their order
availableChargingPoints.sort((a, b) => a.order - b.order);

// Extract the sorted text entries for the output and take only the first three
const sortedEntries = availableChargingPoints.slice(0, 3).map(entry => entry.text);

function generateOutputMessage(sortedEntries) {
  return sortedEntries.length > 0
    ? firstLineChargingPoints + sortedEntries.join("\n")
    : "Er zijn geen laadpunten beschikbaar.";
}

const outputMessage = generateOutputMessage(sortedEntries);
await tag("Available Charging Points", outputMessage);
console.log(outputMessage);

```

## Explanation of the HomeScript

In the capabilitiesToCheck variable, I’ve included the different outlet types to check for. By entering the names of the charging stations in the [Devices section under Developer Tools](https://tools.developer.homey.app/tools/devices), we can see how the capabilities are named. We look up the names of the charging stations and check under capabilities for the ID, which usually starts with _measure\_amount\_available.[number].Outlet_.

```auto
const capabilitiesToCheck = [
'measure_amount_available.17.Outlet',
'measure_amount_available.11.Outlet'
];

```

 ![Capabilities ID found in Devices in Developer Tools](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/2/c2aa539be43c33133ef76ea11619327bfcab2b7d.png)

laadpalenOrder determines the order in which the notification lists the charging stations. The charging station with number 1 will be displayed first if it is free.

```auto
// Define all laadpalen with their desired order
const laadpalenOrder = {
  "A": 1,
  "B": 2,
  "C": 3,
  "D": 4,
  "E": 5,
  "F": 6,
  "G": 7,
  "H": 100,
  "I": 101,
  "J": 102,
  // Add more laadpalen as needed
};

```

The variable weatherDevice is the ID of the added OpenWeather location. This can also be found under [Devices in Developer Tools](https://tools.developer.homey.app/tools/devices).

```auto
const weatherDevice = devices['ID'];

```

 ![ID found in Devices in Developer Tools.](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/4/74afd61e23b850f237bc2e76c07605175cde7090.png)

Down here, we remove the word “Laadpaal” (charging station) from the deviceNameWithoutPrefix variable. In Homey, I’ve named all charging stations with the same naming convention: Laadpaal [street name]. That works fine in Homey but isn’t very helpful when we want a quick overview of available charging stations. So, I strip out the word “Laadpaal.”

```auto
// Remove "laadpaal" from device name and trim
const deviceNameWithoutPrefix = device.name.replace("Laadpaal", "").trim();

```

The last part worth explaining. This ensures that Laadpaal A is not shown if it’s raining.

```auto
// Process devicesMap to create entries, including order information
for (const [deviceName, totalValue] of devicesMap.entries()) {
// If rain is above threshold, skip adding Laadpaal A to the available charging points
if (rainAboveThreshold && deviceName === "A") {
continue;
}

```

# Step 4: Setting up AA Notification Forwarder

Now that the script is ready, we want to make sure it’s visible in the car. Unfortunately, the Homey app doesn’t natively support Android Auto. So, to make this work, we need to use an app that makes notifications from other apps visible in Android Auto. For this, we can use AA Notification Forwarder, which is not available in the Play Store. This is because the app doesn’t comply with Google’s policies regarding Android Auto. Google prefers not to forward notifications from non-chat services. Fortunately, it’s not very difficult to sideload apps on Android. After downloading and installing the app, it’s important to follow the steps as outlined on the [Github page](https://github.com/ztNFny/AANotificationForwarder). If not, we won’t receive the notifications.

Once the settings are configured, we start the app. Under _Apps to Forward_, we search for Homey and enable it. We also enable the checkbox for _Ignore Group Summary notifications_.

 ![AA Notification Forwarder](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/5/c5302f05286c1dcf83bbed8bc9a1d95679dd86c1.png)

# Step 5: Setting up Tasker and AutoLocation

Now it’s time to let Homey know that we’re within a certain range of home, so it can send the notification to the phone. We use Tasker, and optionally AutoLocation, for this. Both apps require a one-time purchase. It is possible to do this with Tasker alone, but experience shows that AutoLocation is more accurate in location tracking.

## Connected to the car

First, we create a task in Tasker that uses a variable to check if the phone is connected to the car via Bluetooth. We don’t want to receive the free charging stations notification if we’re not in the car. In Tasker, we go to the VARS tab and create the variable %ConnectCar. The initial uppercase letter is important here; otherwise, it becomes a local variable that we can’t use elsewhere. We set the variable value to 0. Next, we go to the TASKS tab. There, we create a new task by clicking the plus button in the bottom right. Click _Create_ and name the task, like _Car start_. In the task, click the plus button again and search for _Variable Set_. In _Name_, click the label icon in the top right. Find variable %ConnectCar and set the _To_ value to 1.

 ![Car Start Task](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/6/86c150d78622d1f095773226bcfe0734dad894f8.png)

Next, go back with the arrow in the top left, and you’ll see the task is created. Click the back arrow again to create a second task. I named this _Car Stop_, and it is identical to _Car Start_, except that the value of %ConnectCar is set to 0. Afterward, we go to the PROFILES tab and create a profile using the plus button in the bottom right. Choose _Create_ and click _State_. Then search for _BT Connected_. Under _Name_, use the magnifying glass to find the previously saved Bluetooth connections. Select the one for the car (you must have connected to the car at least once for this to work). Use the back arrow to select the task to activate when connected to the car’s Bluetooth. Choose _Car Start_. Long press _Car Start_ until the option to _Add Exit Task_ appears. Select _Car Stop_, and the variable will now change depending on whether we are connected to the car’s Bluetooth.

 ![Screenshot_20241014-2233132](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/5/85df7a29b0270e311e4d193b5c1d1bd4cf8bce99.png)

## Setting up AutoLocation

If we want to use the AutoLocation app, we need to set up the Geofence before proceeding. Open the app and click _Start Monitor_ under Geofences. Then, go to _Manage Geofences_ and click the plus sign at the top. On the map screen, click the up arrow in the bottom right corner. Here, you can set the radius of the geofence. In my case, it’s 10.000 meters, but this can be any distance. Then, find your home location on the map and click it. A circle will appear around the location based on the set distance. Then click _Accept Geofence_ and give the Geofence a name.

## Informing Homey

Now that Tasker knows if we’re in the car and AutoLocation is set up, it’s time to inform Homey that we are nearby. To do this, we create another task. The task begins with an _If_ statement that checks if the phone is connected to the car via Bluetooth. If %ConnectCar equals 1, the flow should proceed. Click the plus button and search for _if_ in the action category. Then, using the label icon, find %ConnectCar and select it. Change the ~ to _equals_, and the value should be 1. Go back to select _If, End If_.

Between the _If_ and _End If_, place a new action called _HTTP request_. The method is _GET_, and the URL is [https://webhook.homey.app/[HomeyID]/ChargingPoints?tag=[name]](https://webhook.homey.app/%5BHomeyID%5D/ChargingPoints?tag=%5Bname%5D), where HomeyID is the ID of Homey (found under Settings, General), and name is a custom name.

 ![Available Charging Points Task](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/f/d/fde998d138695680601658112996a6069680d02d.png)

With the task ready, create a profile. Click the plus button in the profile tab, then _Create_. If using AutoLocation, click _State_ and search for _AutoLocation Geofences_. Select the name of the Geofence you created earlier. Set the _Status_ to _Inside_. Then, click back several times until you can select the task. Find the name of the task you created to notify Homey.

If you’re not using AutoLocation, select _Location_ instead of _State_ when creating the profile. Create a new location by long-pressing your home location on the map. Adjust the radius to, for example, 10 kilometers. Click _Back_ and give the location a name. Then, select the task you created to notify Homey.

# Step 6: Flow in Homey

With everything set up, it’s just a matter of creating the Flow in Homey. I used the following flow:

 ![Flow 2.0](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/4/6/46c1a775e4644ac43724dc5b0bb3f08adcfe7629.png)

In the flow, the name of the webhook event matches the one from the HTTP request. The TomTom EV Services app then updates all its data with the _update charging station availability_ card, ensuring that the most recent data is used. HomeyScript is, of course, the script from this tutorial, and _tag_ is the custom name that we created with the GET request.

Hopefully, this explanation helps others easily find an available charging station or provides inspiration for triggering flows when you are near home.

---

<div class="post-metadata">

**Author:** ![daniel3](https://avatars.discourse-cdn.com/v4/letter/d/a4c791/32.png) [@daniel3](https://community.homey.app/u/daniel3)\
**Post date:** [April 11, 2025, 3:08pm UTC](https://community.homey.app/t/tutorial-how-to-get-notified-about-which-charging-station-are-free-while-driving/118161/2 "2025-04-11T15:08:42Z")

</div>

Since the release of the 1.5.0 version of the TomTom EV Services app you can now update all charging points using a single then card. I updated step 6 of this tutorial with the new card.
