Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 34b09d6
Author: Boris Brock <[email protected]>
Date:   Tue Oct 8 08:02:14 2024 +0200

    Deleting obsolete doc, updating ReadMe, fixing MQTT bug

commit 36e55a6
Author: Boris Brock <[email protected]>
Date:   Tue Oct 8 07:49:46 2024 +0200

    Update MQTTManager.cpp

commit f1e5dce
Author: Boris Brock <[email protected]>
Date:   Mon Oct 7 21:59:43 2024 +0200

    Adding remaning messages

commit 9bf0e53
Author: Boris Brock <[email protected]>
Date:   Sun Oct 6 21:04:30 2024 +0200

    Adding first discovery topics
  • Loading branch information
BorisBrock committed Oct 8, 2024
1 parent b1a586a commit d2f0718
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 76 deletions.
14 changes: 5 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,11 @@ Start evcc with your new configuration and the HeidelBridge should be there.

# Setting up Home Assistant

HeidelBridge offers a simple MQTT API (see below). Via this API, HeidelBridge can easily be added to Home Assistant.
To do so, add the following to your `configuration.yaml`:

```
mqtt: !include mqtt.yaml
```

Also create a new file called `mqtt.yaml` and paste the example code from [here](doc/mqtt.yaml) into that file.
Now Home Assistant should have all the entities provided by the HeidelBridge MQTT API.
HeidelBridge offers a simple MQTT API (see below). It also supports Home Assistant's MQTT auto discovery feature.
This way HeidelBridge can easily be added to Home Assistant:
- Make sure the MQTT integration in Home Assistant is enabled.
- Power on your HeidelBridge.
- The HeidelBridge should immediately show up as an MQTT device.

GUI Example:

Expand Down
67 changes: 0 additions & 67 deletions doc/mqtt.yaml

This file was deleted.

15 changes: 15 additions & 0 deletions src/Components/MQTT/MQTTManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ namespace MQTTManager
}
}

void PublishHomeAssistantDiscovery()
{
// Publish Home Assistant MQTT discovery messages
gMqttClient.publish("homeassistant/binary_sensor/HeidelBridge/is_vehicle_connected/config", 1, false, R"({"name":"Vehicle connected","device_class":"plug","state_topic":"heidelbridge/is_vehicle_connected","payload_on":"1","payload_off":"0","unique_id":"is_vehicle_connected","device":{"identifiers":["BB42"],"name":"HeidelBridge"}})");
gMqttClient.publish("homeassistant/binary_sensor/HeidelBridge/is_vehicle_charging/config", 1, false, R"({"name":"Vehicle charging","device_class":"battery_charging","state_topic":"heidelbridge/is_vehicle_charging","payload_on":"1","payload_off":"0","unique_id":"is_vehicle_charging","device":{"identifiers":["BB42"],"name":"HeidelBridge"}})");
gMqttClient.publish("homeassistant/sensor/HeidelBridge/charging_power/config", 1, false, R"({"name":"Charging power","device_class":"power","state_topic":"heidelbridge/charging_power","unique_id":"charging_power","unit_of_measurement":"W","device":{"identifiers":["BB42"],"name":"HeidelBridge"}})");
gMqttClient.publish("homeassistant/sensor/HeidelBridge/charging_current/config", 1, false, R"({"name":"Charging current","device_class":"current","state_topic":"heidelbridge/charging_current/phase1","unique_id":"charging_current","unit_of_measurement":"A","device":{"identifiers":["BB42"],"name":"HeidelBridge"}})");
gMqttClient.publish("homeassistant/sensor/HeidelBridge/charging_current_limit/config", 1, false, R"({"name":"Charging current limit","device_class":"current","state_topic":"heidelbridge/charging_current_limit","unique_id":"charging_current_limit","unit_of_measurement":"A","device":{"identifiers":["BB42"],"name":"HeidelBridge"}})");
gMqttClient.publish("homeassistant/sensor/HeidelBridge/energy_meter/config", 1, false, R"({"name":"Energy meter","device_class":"energy","state_topic":"heidelbridge/energy_meter","unique_id":"energy_meter","unit_of_measurement":"kWh","device":{"identifiers":["BB42"],"name":"HeidelBridge"}})");
gMqttClient.publish("homeassistant/sensor/HeidelBridge/temperature/config", 1, false, R"({"name":"Temperature","device_class":"temperature","state_topic":"heidelbridge/temperature","unique_id":"temperature","unit_of_measurement":"°C","device":{"identifiers":["BB42"],"name":"HeidelBridge"}})");
}

void OnMqttConnect(bool sessionPresent)
{
Logger::Info("Connected to MQTT");
Expand All @@ -130,6 +142,9 @@ namespace MQTTManager
gMqttClient.publish("heidelbridge/version", 0, true, versionString.c_str());
gMqttClient.publish("heidelbridge/build_date", 0, true, __DATE__);
gMqttClient.publish("heidelbridge/ip_address", 0, true, WiFi.localIP().toString().c_str());

// Publish discovery data
PublishHomeAssistantDiscovery();
}

void OnMqttDisconnect(AsyncMqttClientDisconnectReason reason)
Expand Down

0 comments on commit d2f0718

Please sign in to comment.