Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Matter EVSE (button entities version) #133662

Closed
wants to merge 64 commits into from

Conversation

lboue
Copy link
Contributor

@lboue lboue commented Dec 20, 2024

Proposed change

Support for Matter EVSE - EnergyEvse cluster

Matter 1.3’s energy features enable new energy-centric devices, the first of which is Electric Vehicle Supply Equipment (EVSE).

  • This enables EV charging equipment manufacturers to present a consumer-friendly way to control how and when they charge their vehicles.
  • It features the ability to manually start or stop charging, adjust the charging rate, or specify how many miles of range to be added by a set departure time, leaving the charging station to automatically optimize the charging to happen at the cheapest and lowest carbon times.

As discussed with Marcel, the second step would be to create a specific entity for EVSE in Home Assistant for better integration.

Supported attributes:

  • EnergyEvse.Attributes.State
  • EnergyEvse.Attributes.SupplyState
  • EnergyEvse.Attributes.FaultState
  • EnergyEvse.Attributes.CircuitCapacity
  • EnergyEvse.Attributes.MinimumChargeCurrent
  • EnergyEvse.Attributes.MaximumChargeCurrent
  • EnergyEvse.Attributes.UserMaximumChargeCurrent

Changes
Add command_timeout attribute in MatterButtonEntityDescription class. This is mandatory for EnergyEvse commands.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Testing

Testing with Matter Linux Energy Management Example device from SDK.

Enable charging with chip-tool

./chip-tool generaldiagnostics test-event-trigger hex:000102030405060708090a0b0c0d0e0f 0x0099000000000000 <nodeID> 0
./chip-tool generaldiagnostics test-event-trigger hex:000102030405060708090a0b0c0d0e0f 0x0099000000000002 <nodeID> 0
./chip-tool generaldiagnostics test-event-trigger hex:000102030405060708090a0b0c0d0e0f 0x0099000000000004 <nodeID> 0
./chip-tool energyevse enable-charging null 2000 30000 <nodeID> 1 --timedInteractionTimeoutMs 3000

Enable charging with WebSocket

{
  "message_id": "example",
  "command": "device_command",
  "args": {
    "endpoint_id": 1,
    "node_id": 23,
    "payload": {
        "ChargingEnabledUntil" : null,
        "MinimumChargeCurrent": 2000,
        "MaximumChargeCurrent":30000
    },
    "cluster_id": 153,
    "command_name": "EnableCharging",
    "timed_request_timeout_ms": 3000
  }
}

image

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.

To help with the load of incoming pull requests:

@lboue lboue marked this pull request as ready for review December 24, 2024 16:45
Copy link
Member

@joostlek joostlek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add the evse_charging fixture to the list of fixtures in the conftest.py

@home-assistant home-assistant bot marked this pull request as draft January 16, 2025 12:41
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@joostlek
Copy link
Member

You probably have to execute pytest ./tests/components/matter --snapshot-update for it to work. Don't forget to generate translations before that

@lboue
Copy link
Contributor Author

lboue commented Jan 16, 2025

You probably have to execute pytest ./tests/components/matter --snapshot-update for it to work. Don't forget to generate translations before that

I will do that

@lboue lboue marked this pull request as ready for review January 16, 2025 15:40
@home-assistant home-assistant bot requested a review from joostlek January 16, 2025 15:40
Comment on lines 153 to 180
MatterDiscoverySchema(
platform=Platform.BUTTON,
entity_description=MatterButtonEntityDescription(
key="EnergyEvseEnableChargingButton",
translation_key="enable_charging",
command=clusters.EnergyEvse.Commands.EnableCharging(
chargingEnabledUntil=NullValue,
minimumChargeCurrent=0,
maximumChargeCurrent=0,
),
command_timeout=3000,
),
entity_class=MatterCommandButton,
required_attributes=(clusters.EnergyEvse.Attributes.AcceptedCommandList,),
allow_multi=True,
),
MatterDiscoverySchema(
platform=Platform.BUTTON,
entity_description=MatterButtonEntityDescription(
key="EnergyEvseDisableChargingButton",
translation_key="disable_charging",
command=clusters.EnergyEvse.Commands.Disable,
command_timeout=3000,
),
entity_class=MatterCommandButton,
required_attributes=(clusters.EnergyEvse.Attributes.AcceptedCommandList,),
allow_multi=True,
),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So one question arose here for me is: Do we have a state for this? Because if we do, wouldn't this be a switch?

Note: I am not up to date on any matter specs, so you might know more here, but please enlighten me :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is a State attribute in the specs: 24-27350-005_Matter-1.4-Application-Cluster-Specification.pdf page 661

9.3.8.1. State Attribute
This attribute SHALL indicate the current status of the EVSE. This higher-level status is partly derived from the signaling protocol as communicated between the EVSE and the vehicle through the pilot signal.
The State attribute SHALL change when the EVSE detects change of condition of the EV (plugged in or unplugged, whether the vehicle is asking for demand or not, and if it is charging or discharging).

It's implemented here:

EVSE_STATE_MAP = {
clusters.EnergyEvse.Enums.StateEnum.kNotPluggedIn: "not_plugged_in",
clusters.EnergyEvse.Enums.StateEnum.kPluggedInNoDemand: "plugged_in_no_demand",
clusters.EnergyEvse.Enums.StateEnum.kPluggedInDemand: "plugged_in_demand",
clusters.EnergyEvse.Enums.StateEnum.kPluggedInCharging: "plugged_in_charging",
clusters.EnergyEvse.Enums.StateEnum.kPluggedInDischarging: "plugged_in_discharging",
clusters.EnergyEvse.Enums.StateEnum.kSessionEnding: "session_ending",
clusters.EnergyEvse.Enums.StateEnum.kFault: "fault",
}

Copy link
Contributor Author

@lboue lboue Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure exposing this as a switch will be the best way of doing this.
clusters.EnergyEvse.Attributes.SupplyState is an enum attribute. So we would have to:

  • Create a new representation of a Matter switch
  • map switch state to enum values
  • handle two On/Off commands
    • EnableCharging
    • EnergyEvse.Commands.Disable,
  • handle arguments for EnableCharging command (chargingEnabledUntil, minimumChargeCurrent, maximumChargeCurrent) and get values from other entities

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Matter switch platform recently got a new variant to base the switch on enum/int values so we have some plumbing present to do this. Also the state is mandatory so there always be a state present. Worst case you can set it None which will be handled by HA (and just show both options).

I would also keep the enum string sensor with the more detailed state.

So yeah I agree with Joost here that the 2 buttons to enable/disable charging should be a single switch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we need to define a new EntityDescription capable of receiving Matter on and off commands and their arguments as arguments. Like this:

    MatterDiscoverySchema(
        platform=Platform.SWITCH,
        entity_description=SwitchEntityDescription(
            key="EnergyEvseEnableDisableCharging",
            name=None,
            on_command=lambda: clusters.EnergyEvse.Commands.EnableCharging(
                chargingEnabledUntil=NullValue,
                minimumChargeCurrent=0,
                maximumChargeCurrent=0,
            ),
            off_command=clusters.EnergyEvse.Commands.Disable,
            command_timeout=3000,
        ),
        entity_class=MatterGenericCommandSwitch,
        required_attributes=(clusters.EnergyEvse.Attributes.AcceptedCommandList,),
        value_contains=clusters.EnergyEvse.Commands.EnableCharging.command_id,
        allow_multi=True,
    ),

@marcelveldt marcelveldt marked this pull request as draft January 28, 2025 15:50
@marcelveldt
Copy link
Member

converted to draft because the enable_charging should be a switch.
Next to that I think we also need a new platform at one point for more fine grained control, so you can do things like "change until" but that needs architecture discussion.

@lboue lboue changed the title Support for Matter EVSE Support for Matter EVSE (button entities version) Feb 2, 2025
@lboue
Copy link
Contributor Author

lboue commented Feb 2, 2025

I'm replacing this request with this one, as this one requires too many changes to adapt and resolve all the conflicts:

@lboue lboue closed this Feb 2, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants