VictronMPPT-ESPHOME/components/victron/victron.h

130 lines
5.8 KiB
C
Raw Normal View History

2021-05-30 10:28:38 +00:00
#pragma once
#include "esphome/core/component.h"
#include "esphome/components/binary_sensor/binary_sensor.h"
2021-05-30 10:28:38 +00:00
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/text_sensor/text_sensor.h"
#include "esphome/components/uart/uart.h"
namespace esphome {
namespace victron {
class VictronComponent : public uart::UARTDevice, public Component {
public:
void set_throttle(uint32_t throttle) { this->throttle_ = throttle; }
void set_load_state_binary_sensor(binary_sensor::BinarySensor *load_state_binary_sensor) {
load_state_binary_sensor_ = load_state_binary_sensor;
}
void set_relay_state_binary_sensor(binary_sensor::BinarySensor *relay_state_binary_sensor) {
relay_state_binary_sensor_ = relay_state_binary_sensor;
}
2021-08-29 07:01:00 +00:00
void set_max_power_yesterday_sensor(sensor::Sensor *max_power_yesterday_sensor) {
max_power_yesterday_sensor_ = max_power_yesterday_sensor;
}
void set_max_power_today_sensor(sensor::Sensor *max_power_today_sensor) {
max_power_today_sensor_ = max_power_today_sensor;
}
2021-05-30 10:28:38 +00:00
void set_yield_total_sensor(sensor::Sensor *yield_total_sensor) { yield_total_sensor_ = yield_total_sensor; }
2021-08-29 07:01:00 +00:00
void set_yield_yesterday_sensor(sensor::Sensor *yield_yesterday_sensor) {
yield_yesterday_sensor_ = yield_yesterday_sensor;
}
2021-05-30 10:28:38 +00:00
void set_yield_today_sensor(sensor::Sensor *yield_today_sensor) { yield_today_sensor_ = yield_today_sensor; }
void set_panel_voltage_sensor(sensor::Sensor *panel_voltage_sensor) { panel_voltage_sensor_ = panel_voltage_sensor; }
void set_panel_power_sensor(sensor::Sensor *panel_power_sensor) { panel_power_sensor_ = panel_power_sensor; }
2021-08-29 07:01:00 +00:00
void set_battery_voltage_sensor(sensor::Sensor *battery_voltage_sensor) {
battery_voltage_sensor_ = battery_voltage_sensor;
}
void set_battery_current_sensor(sensor::Sensor *battery_current_sensor) {
battery_current_sensor_ = battery_current_sensor;
}
2021-09-21 20:42:27 +00:00
void set_ac_out_voltage_sensor(sensor::Sensor *ac_out_voltage_sensor) {
ac_out_voltage_sensor_ = ac_out_voltage_sensor;
}
void set_ac_out_current_sensor(sensor::Sensor *ac_out_current_sensor) {
ac_out_current_sensor_ = ac_out_current_sensor;
}
2021-05-30 15:32:46 +00:00
void set_load_current_sensor(sensor::Sensor *load_current_sensor) { load_current_sensor_ = load_current_sensor; }
2021-05-30 10:28:38 +00:00
void set_day_number_sensor(sensor::Sensor *day_number_sensor) { day_number_sensor_ = day_number_sensor; }
2021-09-01 09:56:00 +00:00
void set_charging_mode_id_sensor(sensor::Sensor *charging_mode_id_sensor) {
charging_mode_id_sensor_ = charging_mode_id_sensor;
2021-08-29 07:01:00 +00:00
}
2021-05-30 10:28:38 +00:00
void set_error_code_sensor(sensor::Sensor *error_code_sensor) { error_code_sensor_ = error_code_sensor; }
2021-09-21 20:42:27 +00:00
void set_warning_code_sensor(sensor::Sensor *warning_code_sensor) { warning_code_sensor_ = warning_code_sensor; }
2021-09-01 09:56:00 +00:00
void set_tracking_mode_id_sensor(sensor::Sensor *tracking_mode_id_sensor) {
tracking_mode_id_sensor_ = tracking_mode_id_sensor;
2021-08-29 07:01:00 +00:00
}
2021-09-21 20:42:27 +00:00
void set_device_mode_id_sensor(sensor::Sensor *device_mode_id_sensor) {
device_mode_id_sensor_ = device_mode_id_sensor;
}
2021-09-01 09:56:00 +00:00
void set_charging_mode_text_sensor(text_sensor::TextSensor *charging_mode_text_sensor) {
charging_mode_text_sensor_ = charging_mode_text_sensor;
2021-08-29 07:01:00 +00:00
}
2021-05-30 10:28:38 +00:00
void set_error_text_sensor(text_sensor::TextSensor *error_text_sensor) { error_text_sensor_ = error_text_sensor; }
2021-10-04 17:31:50 +00:00
void set_warning_text_sensor(text_sensor::TextSensor *warning_text_sensor) {
warning_text_sensor_ = warning_text_sensor;
}
2021-09-01 09:56:00 +00:00
void set_tracking_mode_text_sensor(text_sensor::TextSensor *tracking_mode_text_sensor) {
tracking_mode_text_sensor_ = tracking_mode_text_sensor;
}
2021-09-21 20:42:27 +00:00
void set_device_mode_text_sensor(text_sensor::TextSensor *device_mode_text_sensor) {
device_mode_text_sensor_ = device_mode_text_sensor;
}
2021-09-01 09:56:00 +00:00
void set_firmware_version_text_sensor(text_sensor::TextSensor *firmware_version_text_sensor) {
firmware_version_text_sensor_ = firmware_version_text_sensor;
}
void set_device_type_text_sensor(text_sensor::TextSensor *device_type_text_sensor) {
device_type_text_sensor_ = device_type_text_sensor;
2021-08-29 07:01:00 +00:00
}
2021-05-30 10:28:38 +00:00
void dump_config() override;
void loop() override;
2021-10-22 13:32:46 +00:00
float get_setup_priority() const override { return setup_priority::DATA; }
2021-05-30 10:28:38 +00:00
protected:
void handle_value_();
binary_sensor::BinarySensor *load_state_binary_sensor_;
binary_sensor::BinarySensor *relay_state_binary_sensor_;
2021-05-30 10:28:38 +00:00
sensor::Sensor *max_power_yesterday_sensor_{nullptr};
sensor::Sensor *max_power_today_sensor_{nullptr};
sensor::Sensor *yield_total_sensor_{nullptr};
sensor::Sensor *yield_yesterday_sensor_{nullptr};
sensor::Sensor *yield_today_sensor_{nullptr};
sensor::Sensor *panel_voltage_sensor_{nullptr};
sensor::Sensor *panel_power_sensor_{nullptr};
sensor::Sensor *battery_voltage_sensor_{nullptr};
sensor::Sensor *battery_current_sensor_{nullptr};
2021-09-21 20:42:27 +00:00
sensor::Sensor *ac_out_voltage_sensor_{nullptr};
sensor::Sensor *ac_out_current_sensor_{nullptr};
2021-05-30 15:32:46 +00:00
sensor::Sensor *load_current_sensor_{nullptr};
2021-05-30 10:28:38 +00:00
sensor::Sensor *day_number_sensor_{nullptr};
2021-09-21 20:42:27 +00:00
sensor::Sensor *device_mode_sensor_{nullptr};
2021-09-01 09:56:00 +00:00
sensor::Sensor *charging_mode_id_sensor_{nullptr};
2021-05-30 10:28:38 +00:00
sensor::Sensor *error_code_sensor_{nullptr};
2021-09-21 20:42:27 +00:00
sensor::Sensor *warning_code_sensor_{nullptr};
2021-09-01 09:56:00 +00:00
sensor::Sensor *tracking_mode_id_sensor_{nullptr};
2021-09-21 20:42:27 +00:00
sensor::Sensor *device_mode_id_sensor_{nullptr};
2021-05-30 10:28:38 +00:00
2021-09-01 09:56:00 +00:00
text_sensor::TextSensor *charging_mode_text_sensor_{nullptr};
2021-05-30 10:28:38 +00:00
text_sensor::TextSensor *error_text_sensor_{nullptr};
2021-09-21 20:42:27 +00:00
text_sensor::TextSensor *warning_text_sensor_{nullptr};
2021-09-01 09:56:00 +00:00
text_sensor::TextSensor *tracking_mode_text_sensor_{nullptr};
2021-09-21 20:42:27 +00:00
text_sensor::TextSensor *device_mode_text_sensor_{nullptr};
2021-09-01 09:56:00 +00:00
text_sensor::TextSensor *firmware_version_text_sensor_{nullptr};
text_sensor::TextSensor *device_type_text_sensor_{nullptr};
2021-05-30 10:28:38 +00:00
2022-05-29 13:00:38 +00:00
bool publishing_{true};
2021-05-30 10:28:38 +00:00
int state_{0};
std::string label_;
std::string value_;
uint32_t last_transmission_{0};
uint32_t last_publish_{0};
uint32_t throttle_{0};
2021-05-30 10:28:38 +00:00
};
} // namespace victron
} // namespace esphome