ocpp icon indicating copy to clipboard operation
ocpp copied to clipboard

How to start CP charging from a schedule stored in server side?

Open bitechone opened this issue 1 year ago • 4 comments

Hi, I managed to have a ocpp server started and connected with the client simulator

I want to check which function I need to implement for the schedule charging. i.e. to instruct the connect CP to start charging on a predefined time (e.g. Monday 11:30pm - 5am next day) stored in server and start charge remotely from the server side's charging schedule?

Thanks

bitechone avatar Jul 01 '24 14:07 bitechone

There are two main methods you can consider:

  1. Send RemoteStartTransaction & RemoteStopTransaction from the CS to the CP at the scheduled time.
  2. Send the scheduling information from the CS as a SetChargingProfile.

Here is an example of the SetChargingProfile:(create for GPT)

import datetime
from ocpp.v16 import call
from ocpp.v16.enums import ChargingProfileKindType, ChargingProfilePurposeType, ChargingRateUnitType

# Create the charging profile with the specified parameters
charging_profile = {
    "chargingProfileId": 1,
    "stackLevel": 0,
    "chargingProfilePurpose": ChargingProfilePurposeType.TxDefaultProfile,
    "chargingProfileKind": ChargingProfileKindType.Absolute,
    "chargingSchedule": {
        "startSchedule": "2024-07-01T10:00:00.000Z",
        "chargingRateUnit": ChargingRateUnitType.A,
        "chargingSchedulePeriod": [
            {"startPeriod": 0, "limit": 16, "numberPhases": 3},
            {"startPeriod": 3600, "limit": 0, "numberPhases": 3}  # 1 hour
        ]
    }
}

# Create the SetChargingProfile message
set_charging_profile = call.SetChargingProfile(
    connector_id=1,  # Adjust according to your CP configuration
    cs_charging_profiles=charging_profile
)

# Send the message to the CP
await charge_point.send(set_charging_profile)

Yoshida-Taisei avatar Jul 03 '24 07:07 Yoshida-Taisei

Thanks Yoshida. It is very helpful. Just one more question as for the SetChargingProfile method, I understand the start time need to be a full Date + Time. Say if I need that schedule happening every Monday. Whether I need to pre-set all the (or multiple) Monday dates in the profile and send to CP or it need to be set one by one (e.g. after the 1st Monday section finished, then use my server to send the 2nd Monday date and time to the CP?)

bitechone avatar Jul 03 '24 07:07 bitechone

There's no need to do that.

SetChargingProfile also has a recurring option (recurrencyKind). You should make use of that.

You should also be able to adjust the start time by using ChargingProfileKindType.

import datetime
from ocpp.v16 import call
from ocpp.v16.enums import ChargingProfileKindType, ChargingProfilePurposeType, RecurrencyKindType, ChargingRateUnitType

# Define the start time for every Monday at 9:00 AM
# Note: This time is in UTC
start_time = datetime.datetime(2024, 7, 1, 9, 0)  # Monday 9:00 AM UTC

# Create the charging profile
charging_profile = {
    "chargingProfileId": 1,
    "stackLevel": 0,
    "chargingProfilePurpose": ChargingProfilePurposeType.TxDefaultProfile,
    "chargingProfileKind": ChargingProfileKindType.Absolute,
    "recurrencyKind": RecurrencyKindType.Weekly,
    "validFrom": start_time.isoformat(),
    "chargingSchedule": {
        "startSchedule": start_time.isoformat(),
        "chargingRateUnit": ChargingRateUnitType.W,  # or ChargingRateUnitType.A depending on your needs
        "chargingSchedulePeriod": [
            {"startPeriod": 0, "limit": 16000, "numberPhases": 3},  # Charging at 16kW
            {"startPeriod": 21600, "limit": 0, "numberPhases": 3}  # Stop charging after 6 hours (6*3600=21600 seconds)
        ]
    }
}

# Create the SetChargingProfile message
set_charging_profile = call.SetChargingProfile(
    connector_id=1,  # Adjust according to your CP configuration
    cs_charging_profiles=charging_profile
)

# Send the message to the CP
await charge_point.send(set_charging_profile)

image

Yoshida-Taisei avatar Jul 03 '24 07:07 Yoshida-Taisei

Thanks Yoshida. It's great, let me try.

bitechone avatar Jul 03 '24 08:07 bitechone