mirror of
https://github.com/KinDR007/VictronMPPT-ESPHOME.git
synced 2024-10-21 07:09:27 +00:00
parent
ebcf670793
commit
547b1fa355
@ -105,6 +105,8 @@ esphome run esp8266-example.yaml
|
||||
|
||||
The `uart_id` and `victron_id` is optional if you use a single UART / victron device. All sensors are optional.
|
||||
|
||||
The victron device pushs one status message per second. To reduce the update interval of the ESPHome entities please use the `throttle` parameter to discard some messages.
|
||||
|
||||
The available numeric sensors are:
|
||||
- `max_power_yesterday`
|
||||
- `max_power_today`
|
||||
|
@ -1,7 +1,7 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import uart
|
||||
from esphome.const import CONF_ID
|
||||
from esphome.const import CONF_ID, CONF_THROTTLE
|
||||
|
||||
AUTO_LOAD = ["binary_sensor", "sensor", "text_sensor"]
|
||||
|
||||
@ -19,6 +19,7 @@ CONF_VICTRON_ID = "victron_id"
|
||||
CONFIG_SCHEMA = uart.UART_DEVICE_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(VictronComponent),
|
||||
cv.Optional(CONF_THROTTLE, default="1s"): cv.positive_time_period_milliseconds,
|
||||
}
|
||||
)
|
||||
|
||||
@ -27,3 +28,5 @@ def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield uart.register_uart_device(var, config)
|
||||
|
||||
cg.add(var.set_throttle(config[CONF_THROTTLE]))
|
||||
|
@ -393,6 +393,12 @@ static const std::string device_type_text(int value) {
|
||||
void VictronComponent::handle_value_() {
|
||||
int value;
|
||||
|
||||
const uint32_t now = millis();
|
||||
if (now - this->last_publish_ < this->throttle_) {
|
||||
return;
|
||||
}
|
||||
this->last_publish_ = now;
|
||||
|
||||
if (label_ == "H23") {
|
||||
if (max_power_yesterday_sensor_ != nullptr)
|
||||
max_power_yesterday_sensor_->publish_state(atoi(value_.c_str())); // NOLINT(cert-err34-c)
|
||||
|
@ -11,6 +11,7 @@ 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;
|
||||
}
|
||||
@ -119,6 +120,8 @@ class VictronComponent : public uart::UARTDevice, public Component {
|
||||
std::string label_;
|
||||
std::string value_;
|
||||
uint32_t last_transmission_{0};
|
||||
uint32_t last_publish_{0};
|
||||
uint32_t throttle_{0};
|
||||
};
|
||||
|
||||
} // namespace victron
|
||||
|
@ -61,6 +61,7 @@ uart:
|
||||
victron:
|
||||
id: victron0
|
||||
uart_id: uart_bus
|
||||
throttle: 10s
|
||||
|
||||
sensor:
|
||||
- platform: victron
|
||||
|
@ -44,8 +44,10 @@ uart:
|
||||
victron:
|
||||
- id: victron0
|
||||
uart_id: uart0
|
||||
throttle: 10s
|
||||
- id: victron1
|
||||
uart_id: uart1
|
||||
throttle: 10s
|
||||
|
||||
sensor:
|
||||
- platform: victron
|
||||
|
@ -37,6 +37,7 @@ uart:
|
||||
victron:
|
||||
uart_id: uart0
|
||||
id: victron0
|
||||
throttle: 10s
|
||||
|
||||
sensor:
|
||||
- platform: victron
|
||||
|
Loading…
Reference in New Issue
Block a user