ESPHome 2026.8.2
Loading...
Searching...
No Matches
modbus_sensor.h
Go to the documentation of this file.
1#pragma once
2
6
7#include <span>
8
10
11class ModbusSensor final : 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->set_address(start_address);
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(std::span<const uint8_t> data) override;
26 void dump_config() override;
27 using transform_func_t = optional<float> (*)(ModbusSensor *, float, std::span<const uint8_t>);
28
30
31 protected:
32 optional<transform_func_t> transform_func_{nullopt};
33};
34
35} // namespace esphome::modbus_controller
void set_template(transform_func_t f)
optional< float >(*)(ModbusSensor *, float, std::span< const uint8_t >) transform_func_t
ModbusSensor(modbus::EntityType 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)
void parse_and_publish(std::span< const uint8_t > data) override
optional< transform_func_t > transform_func_
void set_address(uint16_t address)
Sets the configured address, and points the range base at it.
void set_offset_from_start_address(uint8_t offset)
Records the offset as configured, and seeds the resolved position with it.
uint8_t offset
Position of this sensor's data within its range's response - a byte offset for registers,...
Base-class for all sensors.
Definition sensor.h:47
const std::vector< uint8_t > & data
static void uint32_t