Skip to content

Commit

Permalink
Update Amiplus for G1x tariffs - init
Browse files Browse the repository at this point in the history
  • Loading branch information
augustynski-lukasz authored Jun 19, 2024
1 parent 1ad30e4 commit 93733aa
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions driver_amiplus.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ struct Amiplus: Driver
std::map<std::string, double> ret_val{};

add_to_map(ret_val, "total_energy_consumption_kwh", this->get_total_energy_consumption_kwh(telegram));
add_to_map(ret_val, "total_energy_consumption_t1_kwh", this->get_total_energy_consumption_t1_kwh(telegram));
add_to_map(ret_val, "total_energy_consumption_t2_kwh", this->get_total_energy_consumption_t2_kwh(telegram));
add_to_map(ret_val, "total_energy_consumption_t3_kwh", this->get_total_energy_consumption_t3_kwh(telegram));
add_to_map(ret_val, "current_power_consumption_kw", this->get_current_power_consumption_kw(telegram));
add_to_map(ret_val, "total_energy_production_kwh", this->get_total_energy_production_kwh(telegram));
add_to_map(ret_val, "current_power_production_kw", this->get_current_power_production_kw(telegram));
Expand Down Expand Up @@ -74,6 +77,63 @@ struct Amiplus: Driver
return ret_val;
};

esphome::optional<double> get_total_energy_consumption_t1_kwh(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint32_t usage = 0;
size_t i = 11;
uint32_t total_register = 0x0E03;
while (i < telegram.size()) {
uint32_t c = (((uint32_t)telegram[i+0] << 8) | ((uint32_t)telegram[i+1]));
if (c == total_register) {
i += 2;
usage = bcd_2_int(telegram, i, 6);
ret_val = usage / 1000.0;
ESP_LOGVV(TAG, "Found register '0E03' with '%d'->'%f'", usage, ret_val.value());
break;
}
i++;
}
return ret_val;
};

esphome::optional<double> get_total_energy_consumption_t2_kwh(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint32_t usage = 0;
size_t i = 11;
uint32_t total_register = 0x0E03;
while (i < telegram.size()) {
uint32_t c = (((uint32_t)telegram[i+0] << 8) | ((uint32_t)telegram[i+1]));
if (c == total_register) {
i += 2;
usage = bcd_2_int(telegram, i, 6);
ret_val = usage / 1000.0;
ESP_LOGVV(TAG, "Found register '0E03' with '%d'->'%f'", usage, ret_val.value());
break;
}
i++;
}
return ret_val;
};

esphome::optional<double> get_total_energy_consumption_t3_kwh(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint32_t usage = 0;
size_t i = 11;
uint32_t total_register = 0x0E03;
while (i < telegram.size()) {
uint32_t c = (((uint32_t)telegram[i+0] << 8) | ((uint32_t)telegram[i+1]));
if (c == total_register) {
i += 2;
usage = bcd_2_int(telegram, i, 6);
ret_val = usage / 1000.0;
ESP_LOGVV(TAG, "Found register '0E03' with '%d'->'%f'", usage, ret_val.value());
break;
}
i++;
}
return ret_val;
};

esphome::optional<double> get_current_power_consumption_kw(std::vector<unsigned char> &telegram) {
esphome::optional<double> ret_val{};
uint32_t usage = 0;
Expand Down

0 comments on commit 93733aa

Please sign in to comment.