Skip to content

Commit

Permalink
feat(aquamqtt): parse and provide water production attribute (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
tspopp authored Aug 19, 2024
1 parent b90bac4 commit 314537c
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .idea/AquaMQTT.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions AquaMQTT/include/message/MainEnergyMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class MainEnergyMessage

uint16_t powerOverall();

uint16_t totalWaterProduction();

void compareWith(uint8_t* data);

bool totalHeatpumpHoursChanged() const;
Expand All @@ -44,6 +46,8 @@ class MainEnergyMessage

bool powerOverallChanged() const;

bool totalWaterProductionChanged() const;

private:
uint8_t* mData;

Expand All @@ -54,6 +58,7 @@ class MainEnergyMessage
bool mTotalHeatElementHoursChanged;
bool mTotalHoursChanged;
bool mTotalEnergyChanged;
bool mTotalWaterProductionChanged;
};

} // namespace message
Expand Down
1 change: 1 addition & 0 deletions AquaMQTT/include/mqtt/MQTTDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ constexpr char ENERGY_TOTAL_ENERGY_WH[] = { "totalEnergyWh" };
constexpr char ENERGY_POWER_TOTAL[] = { "powerTotal" };
constexpr char ENERGY_POWER_HEAT_ELEMENT[] = { "powerHeatingElem" };
constexpr char ENERGY_POWER_HEATPUMP[] = { "powerHeatpump" };
constexpr char ENERGY_TOTAL_WATER_PRODUCTION[] = { "totalWaterProduction" };

constexpr char ERROR_ERROR_NUMBER[] = { "errorNumber" };

Expand Down
16 changes: 16 additions & 0 deletions AquaMQTT/src/message/MainEnergyMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ uint16_t MainEnergyMessage::powerOverall()
{
return ((uint16_t) mData[8] << 8) | (uint16_t) mData[7];
}

uint16_t MainEnergyMessage::totalWaterProduction()
{
return ((uint16_t) mData[10] << 8) | (uint16_t) mData[9];
}

void MainEnergyMessage::compareWith(uint8_t* data)
{
if (data == nullptr)
Expand All @@ -51,6 +57,7 @@ void MainEnergyMessage::compareWith(uint8_t* data)
mTotalHeatElementHoursChanged = true;
mTotalHoursChanged = true;
mTotalEnergyChanged = true;
mTotalWaterProductionChanged = true;
return;
}

Expand All @@ -76,6 +83,10 @@ void MainEnergyMessage::compareWith(uint8_t* data)
case 8:
mPowerOverallChanged = true;
break;
case 9:
case 10:
mTotalWaterProductionChanged = true;
break;
case 11:
case 12:
case 13:
Expand Down Expand Up @@ -118,6 +129,7 @@ MainEnergyMessage::MainEnergyMessage(uint8_t* data)
, mTotalHeatElementHoursChanged(false)
, mTotalHoursChanged(false)
, mTotalEnergyChanged(false)
, mTotalWaterProductionChanged(false)
{
}
bool MainEnergyMessage::totalHeatpumpHoursChanged() const
Expand Down Expand Up @@ -148,6 +160,10 @@ bool MainEnergyMessage::powerOverallChanged() const
{
return mPowerOverallChanged;
}
bool MainEnergyMessage::totalWaterProductionChanged() const
{
return mTotalWaterProductionChanged;
}

} // namespace message
} // namespace aquamqtt
4 changes: 4 additions & 0 deletions AquaMQTT/src/task/MQTTTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,10 @@ void MQTTTask::updateEnergyStats(bool fullUpdate)
publishul(ENERGY_SUBTOPIC, ENERGY_POWER_TOTAL, message.powerOverall());
}

if(message.totalWaterProductionChanged()) {
publishul(ENERGY_SUBTOPIC, ENERGY_TOTAL_WATER_PRODUCTION, message.totalWaterProduction());
}

if (config::DEBUG_RAW_SERIAL_MESSAGES)
{
sprintf(reinterpret_cast<char*>(mTopicBuffer),
Expand Down
17 changes: 9 additions & 8 deletions MQTT.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,17 @@ Using the prefix, the `$root` topic is created, which is `$prefix/aquamqtt/` and

### Energy Message

| Value | MQTT Topic | Format | Unit | Other Information |
|-------------------------------|--------------------------------------|--------|------|------------------------------------------------------------------------------------------------------------|
| Total Heatpump Hours | `$root/energy/totalHeatpumpHours` | uint32 | h | retained |
| Total Heating Element Hours | `$root/energy/totalHeatingElemHours` | uint32 | h | retained |
| Total Hours | `$root/energy/totalHours` | uint32 | h | retained |
| Total Energy | `$root/energy/totalEnergyWh` | uint64 | Wh | |
| Value | MQTT Topic | Format | Unit | Other Information |
|-------------------------------|--------------------------------------|--------|------|----------------------------------------------------------------------------------------------------|
| Total Heatpump Hours | `$root/energy/totalHeatpumpHours` | uint32 | h | retained |
| Total Heating Element Hours | `$root/energy/totalHeatingElemHours` | uint32 | h | retained |
| Total Hours | `$root/energy/totalHours` | uint32 | h | retained |
| Total Energy | `$root/energy/totalEnergyWh` | uint64 | Wh | |
| Total Water Production | `$root/energy/totalWaterProduction` | uint16 | l | Note: Expected to wrap-around at UINT16_MAX |
| Current Power Heatpump | `$root/energy/powerHeatpump` | uint16 | W | Note: It is possible to define an additional custom mqtt topic for this attribute within `Configuration.h` |
| Current Power Heating Element | `$root/energy/powerHeatingElem` | uint16 | W | Note: It is possible to define an additional custom mqtt topic for this attribute within `Configuration.h` |
| Current Power Total | `$root/energy/powerTotal` | uint16 | W | |
| Raw Message (Debug Mode Only) | `$root/energy/debug` | string | | |
| Current Power Total | `$root/energy/powerTotal` | uint16 | W | |
| Raw Message (Debug Mode Only) | `$root/energy/debug` | string | | |

### Error Messages

Expand Down
3 changes: 1 addition & 2 deletions PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,7 @@ Findings...
| 5 | 0 | ? | - |
| 6 | 0 | ? | - |
| 7 - 8 | 221 1 | Power Consumption Total (Both) | - |
| 9 | 54 | ? | - |
| 10 | 215 | ? | - |
| 9 - 10 | 54 215 | Total Water Production (l) | [Ticket](https://github.com/tspopp/AquaMQTT/issues/30) |
| 11 - 14 | 231 9 0 0 | Total Operation Hours (Heatpump) | - |
| 15 - 18 | 24 0 0 0 | Total Operation Hours (Heating Element) | - |
| 19 - 22 | 231 9 0 0 | Total Operation Hours (Both) | - |
Expand Down
11 changes: 11 additions & 0 deletions aquamqtt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,17 @@ mqtt:
manufacturer: tspopp
name: AquaMQTT
model: V1
- name: "Total Water Production"
state_topic: "aquamqtt/energy/totalWaterProduction"
unit_of_measurement: "l"
state_class: total_increasing
unique_id: atlantic_state_total_water_production
icon: mdi:water-pump
device:
identifiers: AquaMQTT
manufacturer: tspopp
name: AquaMQTT
model: V1
- name: "Total Heating Element Hours"
state_topic: "aquamqtt/energy/totalHeatingElemHours"
unit_of_measurement: "h"
Expand Down

0 comments on commit 314537c

Please sign in to comment.