How to control the charge limit imposed by the Smart Charging Service?

This document teaches:

  • What messages the Smart Service Service uses to control charge rate of a basic charging session.

  • What messages the Smart Service Service uses to control charge rate of an ISO 15118 session.

  • How to manipulate the charge rate.

For this guide, you need:

  • Smart Charging Service that reached the “ready” state. For more information read How to boot the Smart Charging Service?.

  • An MQTT broker.

  • The tools mosquitto_sub and mosquitto_pub.

  • The scripts at the bottom of this document.

Context

Basic Signaling

The Smart Charging Service controls the charge rate of basic charging sessions and ISO 15118 sessions. The charge rate of a basic charging session is controlled using the CpPwmRequest. This request includes a field current. The charger OEM must handle this message and adjust PWM of the control pilot accordingly.

The Smart Charging Service generate CpPwmRequests when both conditions are met:

  • A basic charging session is ongoing. That’s indicated by a SlacStatusUpdate with the field status set to ‘basic_charging”. The SlacStatusUpdate message is generated by Josev’s service rslac.

  • The control pilot is in state B2, C1, C2, D1 or D2. The charger OEM informs the Smart Charging Service through the CpStatusUpdate.

High Level Communication

The charge rate of an ISO 15118-2 or any other High Level Communication (HLC) session is controlled indirectly. The Smart Charging Service sends a Iso15118ChargeLimitUpdate to the iso15118 service. In turn, the iso15118 service interacts with the EV over HLC. Also, the iso15118 service sends a PowerElectronicsSetpointRequest. The charger OEM must adjust the settings to the power electronics accordingly.

Simulate basic charging session

The remainder of this document teaches how to simulate the start of a basic charging session, observe the limit imposed by the Smart Charging Service and how to control that limit using a ChargingProfileRequest.

⚠ The remainder of this document operates on an EVSE with id *GB*SEV*E123456789*. When you booted the Smart Charging Service using a different EVSE id, update the scripts at the bottom accordingly.

In terminal #1, start the Smart Charging Service and make sure it reaches the “ready” state.

terminal 1$ ./smart-charging-service
2023-12-13T15:58:19.979904Z  INFO smart_charging_service: VERSION="0.1.5"
... log lines skipped for brevity
2023-12-13T15:58:20.070398Z  INFO smart_charging_service: Outbound MQTT message. topic=josev/cs request=MqttMessage { id: 5f68db5a-1e3e-45cd-8437-b7a0d1c2d960, body: ServiceStatus(Update(ServiceStatusUpdate { service: SmartCharging, software_version: "0.1.5", api_version: "1.5.14", status: Ready })) }

In terminal #2, subscribe to the topic “josev/cs”:

terminal 2$ mosquitto_sub -t "josev/cs"

In a 3d terminal, simulate that an EV starts a basic charging session. At the bottom of this document you can find a script that simulates the start of a basic charging session. Execute that script:

terminal 3$ ./start-basic-charging.sh
Connecting to localhost:1883
Sent cp_status update.
Sent slac_status update.

By now, the Smart Charging Service realizes a basic charging session has started. Terminal #2 should show something like this:

terminal 2$ mosquitto_sub -t "josev/cs"
{"id":"b8426b2d-593f-4e6c-8cf0-4c3fe136c278","name":"cp_pwm","type":"request","data":{"evse_id":"GB*SEV*E123456789","hlc":false,"current":16.0,"error_state":false,"fault_state":false}}

This messages requests the charger OEM to set the PWM equivalent to a charge current of 16A.

16A is the the maximum rated current of the AC connector of EVSE *GB*SEV*E123456789*. The Smart Charging Service obtained this limit during boot, as part of the CsStatusAndLimitsResponse.

Control charge limit

One can control the limit using SetChargingProfileRequests. In a production scenario, Josev’s ocpp service receives OCPP SetChargingProfile requests from the CSMS and forward these requests to the Smart Charging Service over MQTT using the aforementioned SetChargingProfileRequest.

The Smart Charging Service handles the profiles according to OCPP 2.0.1, Part 2 Specification, chapter K Smart Charging.

At the bottom of this document you can find a script that sends a SetChargingProfileRequest using MQTT. It limits the charge rate to 10A. Execute that script:

terminal 3$ ./set-charging-profile.sh
Connecting to localhost:1883
Sent set_charging_profile request.

The Smart Charging Service should react and generate a CpPwmRequest that limits the maximum charge current to 10A.

In terminal #2 you should see something like:

terminal 2$ mosquitto_sub -t "josev/cs"
{"id":"b8426b2d-593f-4e6c-8cf0-4c3fe136c278","name":"cp_pwm","type":"request","data":{"evse_id":"GB*SEV*E123456789","hlc":false,"current":16.0,"error_state":false,"fault_state":false}}
{"id":"3e4cc68a-45a2-4f2b-9299-1a4e5a300928","name":"cp_pwm","type":"request","data":{"evse_id":"GB*SEV*E123456789","hlc":false,"current":10.0,"error_state":false,"fault_state":false}}

You know now how the Smart Charging Service imposes charge limits on session and how SetChargingProfileRequests controls the height of the charge limit. Play around with different profiles and see they how they effect the height of the limit.


Scripts

1. Simulate start of basic charging session

This script simulates the start of a basic charging session on connector 1 of EVSE *GB*SEV*E123456789*. It sends a CpStatusUpdate and a SlacStatusUpdate.

#!/bin/bash
type mosquitto_sub > /dev/null && type mosquitto_pub > /dev/null
if [ $? -ne 0 ]; then
	echo "This script requires 'mosquitto_sub' and 'mosquitto_pub'."
	echo "These tools are not found. To install those on Ubuntu"
	echo "or alike, run:"
	echo ""
	echo "	sudo apt install mosquitto-clients"

	exit 1
fi

set -e

mqtt_host=${MQTT_HOST:-"localhost"}
mqtt_port=${MQTT_PORT:-1883}

topic_cs_josev="cs/josev"

cp_status_update=$(cat <<EOF
{
    "id": "b5946726-5080-4bb6-8279-a7d5f06d698f",
    "name": "cp_status",
    "type": "update",
    "data": {
        "evse_id": "GB*SEV*E123456789",
        "connector_id": 1,
        "state": "C1",
        "max_voltage": null,
        "min_voltage": null,
        "duty_cycle": null
    }
}
EOF
)

slac_status_update=$(cat <<EOF
{
    "id": "ad626c8c-f364-4c20-a6e5-ab78722c1e91",
    "name": "slac_status",
    "type": "update",
    "data": {
        "evse_id": "GB*SEV*E123456789",
        "run_id": "0xAAD2BB1357FF0001",
        "status": "basic_charging"
    }
}
EOF
)

echo "Connecting to $mqtt_host:$mqtt_port"
mosquitto_pub -h $mqtt_host -p $mqtt_port -t $topic_cs_josev -m "$cp_status_update"
echo "Sent cp_status update."
mosquitto_pub -h $mqtt_host -p $mqtt_port -t $topic_cs_josev -m "$slac_status_update"
echo "Sent slac_status update."

2. Control charge limit with profile

This script sends a SetChargingProfileRequest for EVSE *GB*SEV*E123456789*. It limits the charge current to 10A.

#!/bin/bash
type mosquitto_sub > /dev/null && type mosquitto_pub > /dev/null
if [ $? -ne 0 ]; then
	echo "This script requires 'mosquitto_sub' and 'mosquitto_pub'."
	echo "These tools are not found. To install those on Ubuntu"
	echo "or alike, run:"
	echo ""
	echo "	sudo apt install mosquitto-clients"

	exit 1
fi

set -e

mqtt_host=${MQTT_HOST:-"localhost"}
mqtt_port=${MQTT_PORT:-1883}

topic_cs_josev="cs/josev"

set_charging_profile_request=$(cat <<EOF
{
    "id": "327b4566-27c5-4a3f-834b-40464942d0b3",
    "name": "set_charging_profile",
    "type": "request",
    "data": {
        "charging_profile": {
            "id": 1,
            "stack_level": 1,
            "charging_profile_purpose": "TxProfile",
            "charging_profile_kind": "Relative",
            "charging_schedule": [
                {
                    "id": 1,
                    "charging_rate_unit": "A",
                    "charging_schedule_period": [
                        {
                            "start_period": 0,
                            "limit": 10.0
                        }
		    ]
                }
            ],
            "transaction_id": "78c63bef-683f-4e72-b2c7-cdbc3660a1b4"
        },
        "evse_id": "GB*SEV*E123456789"
    }
}
EOF
)

echo "Connecting to $mqtt_host:$mqtt_port"
mosquitto_pub -h $mqtt_host -p $mqtt_port -t $topic_cs_josev -m "$set_charging_profile_request"
echo "Sent set_charging_profile request."