ESPHome 2026.6.0-dev
Loading...
Searching...
No Matches
modbus_sensor.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <vector>
8
10
11class ModbusSensor : public Component, public sensor::Sensor, public SensorItem {
12 public:
14 SensorValueType value_type, int register_count, uint16_t skip_updates, bool force_new_range) {
15 this->register_type = register_type;
16 this->start_address = start_address;
17 this->offset = offset;
18 this->bitmask = bitmask;
19 this->sensor_value_type = value_type;
20 this->register_count = register_count;
21 this->skip_updates = skip_updates;
22 this->force_new_range = force_new_range;
23 }
24
25 void parse_and_publish(const std::vector<uint8_t> &data) override;
26 void dump_config() override;
27 using transform_func_t = optional<float> (*)(ModbusSensor *, float, const std::vector<uint8_t> &);
28
30
31 protected:
32 optional<transform_func_t> transform_func_{nullopt};
33};
34
35} // namespace esphome::modbus_controller
ESPDEPRECATED("set_retry is deprecated and will be removed in 2026.8.0. Use set_timeout or set_interval instead.", "2026.2.0") void set_retry(const std uint32_t uint8_t std::function< RetryResult(uint8_t)> && f
Definition component.h:437
void set_template(transform_func_t f)
void parse_and_publish(const std::vector< uint8_t > &data) override
optional< transform_func_t > transform_func_
ModbusSensor(ModbusRegisterType register_type, uint16_t start_address, uint8_t offset, uint32_t bitmask, SensorValueType value_type, int register_count, uint16_t skip_updates, bool force_new_range)
optional< float >(*)(ModbusSensor *, float, const std::vector< uint8_t > &) transform_func_t
Base-class for all sensors.
Definition sensor.h:47
const std::vector< uint8_t > & data
static void uint32_t