mirror of
https://github.com/esphome/esphome.git
synced 2026-05-26 19:26:25 +08:00
Implementation for Atlas Scientific Peristaltic Pump (#3528)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
41b5cb06d3
commit
f30e54d177
@@ -79,6 +79,7 @@ esphome/components/esp8266/* @esphome/core
|
||||
esphome/components/ethernet_info/* @gtjadsonsantos
|
||||
esphome/components/exposure_notifications/* @OttoWinter
|
||||
esphome/components/ezo/* @ssieb
|
||||
esphome/components/ezo_pmp/* @carlos-sarmiento
|
||||
esphome/components/factory_reset/* @anatoly-savchenkov
|
||||
esphome/components/fastled_base/* @OttoWinter
|
||||
esphome/components/feedback/* @ianchi
|
||||
|
||||
@@ -0,0 +1,291 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c
|
||||
from esphome.const import CONF_ADDRESS, CONF_COMMAND, CONF_ID, CONF_DURATION
|
||||
from esphome import automation
|
||||
from esphome.automation import maybe_simple_id
|
||||
|
||||
CODEOWNERS = ["@carlos-sarmiento"]
|
||||
DEPENDENCIES = ["i2c"]
|
||||
MULTI_CONF = True
|
||||
|
||||
CONF_VOLUME = "volume"
|
||||
CONF_VOLUME_PER_MINUTE = "volume_per_minute"
|
||||
|
||||
ezo_pmp_ns = cg.esphome_ns.namespace("ezo_pmp")
|
||||
EzoPMP = ezo_pmp_ns.class_("EzoPMP", cg.PollingComponent, i2c.I2CDevice)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(EzoPMP),
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
.extend(cv.polling_component_schema("60s"))
|
||||
.extend(i2c.i2c_device_schema(103))
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
|
||||
EZO_PMP_NO_ARGS_ACTION_SCHEMA = maybe_simple_id(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(EzoPMP),
|
||||
}
|
||||
)
|
||||
|
||||
# Actions that do not require more arguments
|
||||
|
||||
EzoPMPFindAction = ezo_pmp_ns.class_("EzoPMPFindAction", automation.Action)
|
||||
EzoPMPClearTotalVolumeDispensedAction = ezo_pmp_ns.class_(
|
||||
"EzoPMPClearTotalVolumeDispensedAction", automation.Action
|
||||
)
|
||||
EzoPMPClearCalibrationAction = ezo_pmp_ns.class_(
|
||||
"EzoPMPClearCalibrationAction", automation.Action
|
||||
)
|
||||
EzoPMPPauseDosingAction = ezo_pmp_ns.class_(
|
||||
"EzoPMPPauseDosingAction", automation.Action
|
||||
)
|
||||
EzoPMPStopDosingAction = ezo_pmp_ns.class_("EzoPMPStopDosingAction", automation.Action)
|
||||
EzoPMPDoseContinuouslyAction = ezo_pmp_ns.class_(
|
||||
"EzoPMPDoseContinuouslyAction", automation.Action
|
||||
)
|
||||
|
||||
# Actions that require more arguments
|
||||
EzoPMPDoseVolumeAction = ezo_pmp_ns.class_("EzoPMPDoseVolumeAction", automation.Action)
|
||||
EzoPMPDoseVolumeOverTimeAction = ezo_pmp_ns.class_(
|
||||
"EzoPMPDoseVolumeOverTimeAction", automation.Action
|
||||
)
|
||||
EzoPMPDoseWithConstantFlowRateAction = ezo_pmp_ns.class_(
|
||||
"EzoPMPDoseWithConstantFlowRateAction", automation.Action
|
||||
)
|
||||
EzoPMPSetCalibrationVolumeAction = ezo_pmp_ns.class_(
|
||||
"EzoPMPSetCalibrationVolumeAction", automation.Action
|
||||
)
|
||||
EzoPMPChangeI2CAddressAction = ezo_pmp_ns.class_(
|
||||
"EzoPMPChangeI2CAddressAction", automation.Action
|
||||
)
|
||||
EzoPMPArbitraryCommandAction = ezo_pmp_ns.class_(
|
||||
"EzoPMPArbitraryCommandAction", automation.Action
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.find", EzoPMPFindAction, EZO_PMP_NO_ARGS_ACTION_SCHEMA
|
||||
)
|
||||
async def ezo_pmp_find_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.dose_continuously",
|
||||
EzoPMPDoseContinuouslyAction,
|
||||
EZO_PMP_NO_ARGS_ACTION_SCHEMA,
|
||||
)
|
||||
async def ezo_pmp_dose_continuously_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.clear_total_volume_dosed",
|
||||
EzoPMPClearTotalVolumeDispensedAction,
|
||||
EZO_PMP_NO_ARGS_ACTION_SCHEMA,
|
||||
)
|
||||
async def ezo_pmp_clear_total_volume_dosed_to_code(
|
||||
config, action_id, template_arg, args
|
||||
):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.clear_calibration",
|
||||
EzoPMPClearCalibrationAction,
|
||||
EZO_PMP_NO_ARGS_ACTION_SCHEMA,
|
||||
)
|
||||
async def ezo_pmp_clear_calibration_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.pause_dosing", EzoPMPPauseDosingAction, EZO_PMP_NO_ARGS_ACTION_SCHEMA
|
||||
)
|
||||
async def ezo_pmp_pause_dosing_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.stop_dosing", EzoPMPStopDosingAction, EZO_PMP_NO_ARGS_ACTION_SCHEMA
|
||||
)
|
||||
async def ezo_pmp_stop_dosing_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
return cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
|
||||
# Actions that require Multiple Args
|
||||
|
||||
EZO_PMP_DOSE_VOLUME_ACTION_SCHEMA = cv.All(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(EzoPMP),
|
||||
cv.Required(CONF_VOLUME): cv.templatable(
|
||||
cv.float_range()
|
||||
), # Any way to represent as proper volume (vs. raw int)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.dose_volume", EzoPMPDoseVolumeAction, EZO_PMP_DOSE_VOLUME_ACTION_SCHEMA
|
||||
)
|
||||
async def ezo_pmp_dose_volume_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_VOLUME], args, cg.double)
|
||||
cg.add(var.set_volume(template_))
|
||||
|
||||
return var
|
||||
|
||||
|
||||
EZO_PMP_DOSE_VOLUME_OVER_TIME_ACTION_SCHEMA = cv.All(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(EzoPMP),
|
||||
cv.Required(CONF_VOLUME): cv.templatable(
|
||||
cv.float_range()
|
||||
), # Any way to represent as proper volume (vs. raw int)
|
||||
cv.Required(CONF_DURATION): cv.templatable(
|
||||
cv.int_range(1)
|
||||
), # Any way to represent it as minutes (vs. raw int)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.dose_volume_over_time",
|
||||
EzoPMPDoseVolumeOverTimeAction,
|
||||
EZO_PMP_DOSE_VOLUME_OVER_TIME_ACTION_SCHEMA,
|
||||
)
|
||||
async def ezo_pmp_dose_volume_over_time_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_VOLUME], args, cg.double)
|
||||
cg.add(var.set_volume(template_))
|
||||
|
||||
template_ = await cg.templatable(config[CONF_DURATION], args, int)
|
||||
cg.add(var.set_duration(template_))
|
||||
|
||||
return var
|
||||
|
||||
|
||||
EZO_PMP_DOSE_WITH_CONSTANT_FLOW_RATE_ACTION_SCHEMA = cv.All(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(EzoPMP),
|
||||
cv.Required(CONF_VOLUME_PER_MINUTE): cv.templatable(
|
||||
cv.float_range()
|
||||
), # Any way to represent as proper volume (vs. raw int)
|
||||
cv.Required(CONF_DURATION): cv.templatable(
|
||||
cv.int_range(1)
|
||||
), # Any way to represent it as minutes (vs. raw int)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.dose_with_constant_flow_rate",
|
||||
EzoPMPDoseWithConstantFlowRateAction,
|
||||
EZO_PMP_DOSE_WITH_CONSTANT_FLOW_RATE_ACTION_SCHEMA,
|
||||
)
|
||||
async def ezo_pmp_dose_with_constant_flow_rate_to_code(
|
||||
config, action_id, template_arg, args
|
||||
):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_VOLUME_PER_MINUTE], args, cg.double)
|
||||
cg.add(var.set_volume(template_))
|
||||
|
||||
template_ = await cg.templatable(config[CONF_DURATION], args, int)
|
||||
cg.add(var.set_duration(template_))
|
||||
|
||||
return var
|
||||
|
||||
|
||||
EZO_PMP_SET_CALIBRATION_VOLUME_ACTION_SCHEMA = cv.All(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(EzoPMP),
|
||||
cv.Required(CONF_VOLUME): cv.templatable(
|
||||
cv.float_range()
|
||||
), # Any way to represent as proper volume (vs. raw int)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.set_calibration_volume",
|
||||
EzoPMPSetCalibrationVolumeAction,
|
||||
EZO_PMP_SET_CALIBRATION_VOLUME_ACTION_SCHEMA,
|
||||
)
|
||||
async def ezo_pmp_set_calibration_volume_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_VOLUME], args, cg.double)
|
||||
cg.add(var.set_volume(template_))
|
||||
|
||||
return var
|
||||
|
||||
|
||||
EZO_PMP_CHANGE_I2C_ADDRESS_ACTION_SCHEMA = cv.All(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(EzoPMP),
|
||||
cv.Required(CONF_ADDRESS): cv.templatable(cv.int_range(min=1, max=127)),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.change_i2c_address",
|
||||
EzoPMPChangeI2CAddressAction,
|
||||
EZO_PMP_CHANGE_I2C_ADDRESS_ACTION_SCHEMA,
|
||||
)
|
||||
async def ezo_pmp_change_i2c_address_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_ADDRESS], args, cg.double)
|
||||
cg.add(var.set_address(template_))
|
||||
|
||||
return var
|
||||
|
||||
|
||||
EZO_PMP_ARBITRARY_COMMAND_ACTION_SCHEMA = cv.All(
|
||||
{
|
||||
cv.Required(CONF_ID): cv.use_id(EzoPMP),
|
||||
cv.Required(CONF_COMMAND): cv.templatable(cv.string_strict),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@automation.register_action(
|
||||
"ezo_pmp.arbitrary_command",
|
||||
EzoPMPArbitraryCommandAction,
|
||||
EZO_PMP_ARBITRARY_COMMAND_ACTION_SCHEMA,
|
||||
)
|
||||
async def ezo_pmp_arbitrary_command_to_code(config, action_id, template_arg, args):
|
||||
paren = await cg.get_variable(config[CONF_ID])
|
||||
var = cg.new_Pvariable(action_id, template_arg, paren)
|
||||
|
||||
template_ = await cg.templatable(config[CONF_COMMAND], args, cg.std_string)
|
||||
cg.add(var.set_command(template_))
|
||||
|
||||
return var
|
||||
@@ -0,0 +1,42 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import binary_sensor
|
||||
from esphome.const import (
|
||||
ENTITY_CATEGORY_NONE,
|
||||
DEVICE_CLASS_RUNNING,
|
||||
DEVICE_CLASS_EMPTY,
|
||||
CONF_ID,
|
||||
)
|
||||
|
||||
from . import EzoPMP
|
||||
|
||||
DEPENDENCIES = ["ezo_pmp"]
|
||||
|
||||
CONF_PUMP_STATE = "pump_state"
|
||||
CONF_IS_PAUSED = "is_paused"
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(EzoPMP),
|
||||
cv.Optional(CONF_PUMP_STATE): binary_sensor.binary_sensor_schema(
|
||||
device_class=DEVICE_CLASS_RUNNING,
|
||||
entity_category=ENTITY_CATEGORY_NONE,
|
||||
),
|
||||
cv.Optional(CONF_IS_PAUSED): binary_sensor.binary_sensor_schema(
|
||||
device_class=DEVICE_CLASS_EMPTY,
|
||||
entity_category=ENTITY_CATEGORY_NONE,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
parent = await cg.get_variable(config[CONF_ID])
|
||||
|
||||
if CONF_PUMP_STATE in config:
|
||||
sens = await binary_sensor.new_binary_sensor(config[CONF_PUMP_STATE])
|
||||
cg.add(parent.set_is_dosing(sens))
|
||||
|
||||
if CONF_IS_PAUSED in config:
|
||||
sens = await binary_sensor.new_binary_sensor(config[CONF_IS_PAUSED])
|
||||
cg.add(parent.set_is_paused(sens))
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,252 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
#include "esphome/components/binary_sensor/binary_sensor.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_SENSOR
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#endif
|
||||
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
#include "esphome/components/text_sensor/text_sensor.h"
|
||||
#endif
|
||||
|
||||
namespace esphome {
|
||||
namespace ezo_pmp {
|
||||
|
||||
class EzoPMP : public PollingComponent, public i2c::I2CDevice {
|
||||
public:
|
||||
void dump_config() override;
|
||||
float get_setup_priority() const override { return setup_priority::DATA; };
|
||||
|
||||
void loop() override;
|
||||
void update() override;
|
||||
|
||||
#ifdef USE_SENSOR
|
||||
void set_current_volume_dosed(sensor::Sensor *current_volume_dosed) { current_volume_dosed_ = current_volume_dosed; }
|
||||
void set_total_volume_dosed(sensor::Sensor *total_volume_dosed) { total_volume_dosed_ = total_volume_dosed; }
|
||||
void set_absolute_total_volume_dosed(sensor::Sensor *absolute_total_volume_dosed) {
|
||||
absolute_total_volume_dosed_ = absolute_total_volume_dosed;
|
||||
}
|
||||
void set_pump_voltage(sensor::Sensor *pump_voltage) { pump_voltage_ = pump_voltage; }
|
||||
void set_last_volume_requested(sensor::Sensor *last_volume_requested) {
|
||||
last_volume_requested_ = last_volume_requested;
|
||||
}
|
||||
void set_max_flow_rate(sensor::Sensor *max_flow_rate) { max_flow_rate_ = max_flow_rate; }
|
||||
#endif
|
||||
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
void set_is_dosing(binary_sensor::BinarySensor *is_dosing) { is_dosing_ = is_dosing; }
|
||||
void set_is_paused(binary_sensor::BinarySensor *is_paused) { is_paused_ = is_paused; }
|
||||
#endif
|
||||
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
void set_dosing_mode(text_sensor::TextSensor *dosing_mode) { dosing_mode_ = dosing_mode; }
|
||||
void set_calibration_status(text_sensor::TextSensor *calibration_status) { calibration_status_ = calibration_status; }
|
||||
#endif
|
||||
|
||||
// Actions for EZO-PMP
|
||||
void find();
|
||||
void dose_continuously();
|
||||
void dose_volume(double volume);
|
||||
void dose_volume_over_time(double volume, int duration);
|
||||
void dose_with_constant_flow_rate(double volume, int duration);
|
||||
void set_calibration_volume(double volume);
|
||||
void clear_total_volume_dosed();
|
||||
void clear_calibration();
|
||||
void pause_dosing();
|
||||
void stop_dosing();
|
||||
void change_i2c_address(int address);
|
||||
void exec_arbitrary_command(const std::basic_string<char> &command);
|
||||
|
||||
protected:
|
||||
uint32_t start_time_ = 0;
|
||||
uint32_t wait_time_ = 0;
|
||||
bool is_waiting_ = false;
|
||||
bool is_first_read_ = true;
|
||||
|
||||
uint16_t next_command_ = 0;
|
||||
double next_command_volume_ = 0; // might be negative
|
||||
int next_command_duration_ = 0;
|
||||
|
||||
uint16_t next_command_queue_[10];
|
||||
double next_command_volume_queue_[10];
|
||||
int next_command_duration_queue_[10];
|
||||
int next_command_queue_head_ = 0;
|
||||
int next_command_queue_last_ = 0;
|
||||
int next_command_queue_length_ = 0;
|
||||
|
||||
uint16_t current_command_ = 0;
|
||||
bool is_paused_flag_ = false;
|
||||
bool is_dosing_flag_ = false;
|
||||
|
||||
const char *arbitrary_command_{nullptr};
|
||||
|
||||
void send_next_command_();
|
||||
void read_command_result_();
|
||||
void clear_current_command_();
|
||||
void queue_command_(uint16_t command, double volume, int duration, bool should_schedule);
|
||||
void pop_next_command_();
|
||||
uint16_t peek_next_command_();
|
||||
|
||||
#ifdef USE_SENSOR
|
||||
sensor::Sensor *current_volume_dosed_{nullptr};
|
||||
sensor::Sensor *total_volume_dosed_{nullptr};
|
||||
sensor::Sensor *absolute_total_volume_dosed_{nullptr};
|
||||
sensor::Sensor *pump_voltage_{nullptr};
|
||||
sensor::Sensor *max_flow_rate_{nullptr};
|
||||
sensor::Sensor *last_volume_requested_{nullptr};
|
||||
#endif
|
||||
|
||||
#ifdef USE_BINARY_SENSOR
|
||||
binary_sensor::BinarySensor *is_dosing_{nullptr};
|
||||
binary_sensor::BinarySensor *is_paused_{nullptr};
|
||||
#endif
|
||||
|
||||
#ifdef USE_TEXT_SENSOR
|
||||
text_sensor::TextSensor *dosing_mode_{nullptr};
|
||||
text_sensor::TextSensor *calibration_status_{nullptr};
|
||||
#endif
|
||||
};
|
||||
|
||||
// Action Templates
|
||||
template<typename... Ts> class EzoPMPFindAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPFindAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override { this->ezopmp_->find(); }
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPDoseContinuouslyAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPDoseContinuouslyAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override { this->ezopmp_->dose_continuously(); }
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPDoseVolumeAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPDoseVolumeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override { this->ezopmp_->dose_volume(this->volume_.value(x...)); }
|
||||
TEMPLATABLE_VALUE(double, volume)
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPDoseVolumeOverTimeAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPDoseVolumeOverTimeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override {
|
||||
this->ezopmp_->dose_volume_over_time(this->volume_.value(x...), this->duration_.value(x...));
|
||||
}
|
||||
TEMPLATABLE_VALUE(double, volume)
|
||||
TEMPLATABLE_VALUE(int, duration)
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPDoseWithConstantFlowRateAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPDoseWithConstantFlowRateAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override {
|
||||
this->ezopmp_->dose_with_constant_flow_rate(this->volume_.value(x...), this->duration_.value(x...));
|
||||
}
|
||||
TEMPLATABLE_VALUE(double, volume)
|
||||
TEMPLATABLE_VALUE(int, duration)
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPSetCalibrationVolumeAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPSetCalibrationVolumeAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override { this->ezopmp_->set_calibration_volume(this->volume_.value(x...)); }
|
||||
TEMPLATABLE_VALUE(double, volume)
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPClearTotalVolumeDispensedAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPClearTotalVolumeDispensedAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override { this->ezopmp_->clear_total_volume_dosed(); }
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPClearCalibrationAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPClearCalibrationAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override { this->ezopmp_->clear_calibration(); }
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPPauseDosingAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPPauseDosingAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override { this->ezopmp_->pause_dosing(); }
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPStopDosingAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPStopDosingAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override { this->ezopmp_->stop_dosing(); }
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPChangeI2CAddressAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPChangeI2CAddressAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override { this->ezopmp_->change_i2c_address(this->address_.value(x...)); }
|
||||
TEMPLATABLE_VALUE(int, address)
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class EzoPMPArbitraryCommandAction : public Action<Ts...> {
|
||||
public:
|
||||
EzoPMPArbitraryCommandAction(EzoPMP *ezopmp) : ezopmp_(ezopmp) {}
|
||||
|
||||
void play(Ts... x) override { this->ezopmp_->exec_arbitrary_command(this->command_.value(x...)); }
|
||||
TEMPLATABLE_VALUE(std::string, command)
|
||||
|
||||
protected:
|
||||
EzoPMP *ezopmp_;
|
||||
};
|
||||
|
||||
} // namespace ezo_pmp
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,104 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import sensor
|
||||
from esphome.const import (
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
ENTITY_CATEGORY_NONE,
|
||||
DEVICE_CLASS_EMPTY,
|
||||
DEVICE_CLASS_VOLTAGE,
|
||||
STATE_CLASS_MEASUREMENT,
|
||||
STATE_CLASS_NONE,
|
||||
CONF_ID,
|
||||
UNIT_VOLT,
|
||||
)
|
||||
|
||||
from . import EzoPMP
|
||||
|
||||
|
||||
DEPENDENCIES = ["ezo_pmp"]
|
||||
|
||||
CONF_CURRENT_VOLUME_DOSED = "current_volume_dosed"
|
||||
CONF_TOTAL_VOLUME_DOSED = "total_volume_dosed"
|
||||
CONF_ABSOLUTE_TOTAL_VOLUME_DOSED = "absolute_total_volume_dosed"
|
||||
CONF_PUMP_VOLTAGE = "pump_voltage"
|
||||
CONF_LAST_VOLUME_REQUESTED = "last_volume_requested"
|
||||
CONF_MAX_FLOW_RATE = "max_flow_rate"
|
||||
|
||||
UNIT_MILILITER = "ml"
|
||||
UNIT_MILILITERS_PER_MINUTE = "ml/min"
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(EzoPMP),
|
||||
cv.Optional(CONF_CURRENT_VOLUME_DOSED): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_MILILITER,
|
||||
accuracy_decimals=2,
|
||||
device_class=DEVICE_CLASS_EMPTY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_NONE,
|
||||
),
|
||||
cv.Optional(CONF_LAST_VOLUME_REQUESTED): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_MILILITER,
|
||||
accuracy_decimals=2,
|
||||
device_class=DEVICE_CLASS_EMPTY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_NONE,
|
||||
),
|
||||
cv.Optional(CONF_MAX_FLOW_RATE): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_MILILITERS_PER_MINUTE,
|
||||
accuracy_decimals=2,
|
||||
device_class=DEVICE_CLASS_EMPTY,
|
||||
state_class=STATE_CLASS_NONE,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
cv.Optional(CONF_TOTAL_VOLUME_DOSED): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_MILILITER,
|
||||
accuracy_decimals=2,
|
||||
device_class=DEVICE_CLASS_EMPTY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
cv.Optional(CONF_ABSOLUTE_TOTAL_VOLUME_DOSED): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_MILILITER,
|
||||
accuracy_decimals=2,
|
||||
device_class=DEVICE_CLASS_EMPTY,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
cv.Optional(CONF_PUMP_VOLTAGE): sensor.sensor_schema(
|
||||
unit_of_measurement=UNIT_VOLT,
|
||||
accuracy_decimals=2,
|
||||
device_class=DEVICE_CLASS_VOLTAGE,
|
||||
state_class=STATE_CLASS_MEASUREMENT,
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
parent = await cg.get_variable(config[CONF_ID])
|
||||
|
||||
if CONF_CURRENT_VOLUME_DOSED in config:
|
||||
sens = await sensor.new_sensor(config[CONF_CURRENT_VOLUME_DOSED])
|
||||
cg.add(parent.set_current_volume_dosed(sens))
|
||||
|
||||
if CONF_LAST_VOLUME_REQUESTED in config:
|
||||
sens = await sensor.new_sensor(config[CONF_LAST_VOLUME_REQUESTED])
|
||||
cg.add(parent.set_last_volume_requested(sens))
|
||||
|
||||
if CONF_TOTAL_VOLUME_DOSED in config:
|
||||
sens = await sensor.new_sensor(config[CONF_TOTAL_VOLUME_DOSED])
|
||||
cg.add(parent.set_total_volume_dosed(sens))
|
||||
|
||||
if CONF_ABSOLUTE_TOTAL_VOLUME_DOSED in config:
|
||||
sens = await sensor.new_sensor(config[CONF_ABSOLUTE_TOTAL_VOLUME_DOSED])
|
||||
cg.add(parent.set_absolute_total_volume_dosed(sens))
|
||||
|
||||
if CONF_PUMP_VOLTAGE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_PUMP_VOLTAGE])
|
||||
cg.add(parent.set_pump_voltage(sens))
|
||||
|
||||
if CONF_MAX_FLOW_RATE in config:
|
||||
sens = await sensor.new_sensor(config[CONF_MAX_FLOW_RATE])
|
||||
cg.add(parent.set_max_flow_rate(sens))
|
||||
@@ -0,0 +1,39 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import text_sensor
|
||||
from esphome.const import (
|
||||
ENTITY_CATEGORY_NONE,
|
||||
ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
CONF_ID,
|
||||
)
|
||||
|
||||
from . import EzoPMP
|
||||
|
||||
DEPENDENCIES = ["ezo_pmp"]
|
||||
|
||||
CONF_DOSING_MODE = "dosing_mode"
|
||||
CONF_CALIBRATION_STATUS = "calibration_status"
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.use_id(EzoPMP),
|
||||
cv.Optional(CONF_DOSING_MODE): text_sensor.text_sensor_schema(
|
||||
entity_category=ENTITY_CATEGORY_NONE,
|
||||
),
|
||||
cv.Optional(CONF_CALIBRATION_STATUS): text_sensor.text_sensor_schema(
|
||||
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
parent = await cg.get_variable(config[CONF_ID])
|
||||
|
||||
if CONF_DOSING_MODE in config:
|
||||
sens = await text_sensor.new_text_sensor(config[CONF_DOSING_MODE])
|
||||
cg.add(parent.set_dosing_mode(sens))
|
||||
|
||||
if CONF_CALIBRATION_STATUS in config:
|
||||
sens = await text_sensor.new_text_sensor(config[CONF_CALIBRATION_STATUS])
|
||||
cg.add(parent.set_calibration_status(sens))
|
||||
@@ -165,6 +165,12 @@ binary_sensor:
|
||||
|
||||
|
||||
|
||||
- platform: ezo_pmp
|
||||
pump_state:
|
||||
name: "Pump State"
|
||||
is_paused:
|
||||
name: "Is Paused"
|
||||
|
||||
tlc5947:
|
||||
data_pin: GPIO12
|
||||
clock_pin: GPIO14
|
||||
@@ -220,6 +226,10 @@ esp32_improv:
|
||||
authorized_duration: 1min
|
||||
status_indicator: built_in_led
|
||||
|
||||
ezo_pmp:
|
||||
id: hcl_pump
|
||||
update_interval: 1s
|
||||
|
||||
number:
|
||||
- platform: template
|
||||
name: My template number
|
||||
@@ -440,6 +450,20 @@ sensor:
|
||||
cold_junction:
|
||||
name: Ambient Temperature
|
||||
|
||||
- platform: ezo_pmp
|
||||
current_volume_dosed:
|
||||
name: Current Volume Dosed
|
||||
total_volume_dosed:
|
||||
name: Total Volume Dosed
|
||||
absolute_total_volume_dosed:
|
||||
name: Absolute Total Volume Dosed
|
||||
pump_voltage:
|
||||
name: Pump Voltage
|
||||
last_volume_requested:
|
||||
name: Last Volume Requested
|
||||
max_flow_rate:
|
||||
name: Max Flow Rate
|
||||
|
||||
script:
|
||||
- id: automation_test
|
||||
then:
|
||||
@@ -487,3 +511,33 @@ display:
|
||||
lambda: |-
|
||||
it.print("81818181");
|
||||
|
||||
text_sensor:
|
||||
- platform: ezo_pmp
|
||||
dosing_mode:
|
||||
name: Dosing Mode
|
||||
calibration_status:
|
||||
name: Calibration Status
|
||||
on_value:
|
||||
- ezo_pmp.dose_volume:
|
||||
id: hcl_pump
|
||||
volume: 10
|
||||
- ezo_pmp.dose_volume_over_time:
|
||||
id: hcl_pump
|
||||
volume: 10
|
||||
duration: 2
|
||||
- ezo_pmp.dose_with_constant_flow_rate:
|
||||
id: hcl_pump
|
||||
volume_per_minute: 10
|
||||
duration: 2
|
||||
- ezo_pmp.set_calibration_volume:
|
||||
id: hcl_pump
|
||||
volume: 10
|
||||
- ezo_pmp.find: hcl_pump
|
||||
- ezo_pmp.dose_continuously: hcl_pump
|
||||
- ezo_pmp.clear_total_volume_dosed: hcl_pump
|
||||
- ezo_pmp.clear_calibration: hcl_pump
|
||||
- ezo_pmp.pause_dosing: hcl_pump
|
||||
- ezo_pmp.stop_dosing: hcl_pump
|
||||
- ezo_pmp.arbitrary_command:
|
||||
id: hcl_pump
|
||||
command: D,?
|
||||
|
||||
Reference in New Issue
Block a user