ESPHome 2026.8.2
Loading...
Searching...
No Matches
esphome::modbus_controller::SensorItem Class Referenceabstract

#include <modbus_controller.h>

Inheritance diagram for esphome::modbus_controller::SensorItem:
esphome::modbus_controller::ModbusBinaryOutput esphome::modbus_controller::ModbusBinarySensor esphome::modbus_controller::ModbusFloatOutput esphome::modbus_controller::ModbusNumber esphome::modbus_controller::ModbusSelect esphome::modbus_controller::ModbusSensor esphome::modbus_controller::ModbusSwitch esphome::modbus_controller::ModbusTextSensor

Public Member Functions

virtual void parse_and_publish (std::span< const uint8_t > data)=0
 Parse this sensor's slice out of its range's response and publish it.
 
bool addresses_bits () const
 Coils and discrete inputs address individual bits; every other type addresses 16-bit registers.
 
uint16_t write_address () const
 Address a write entity (switch/number/select) targets, derived from its resolved position within the range so that a write lands on the register the sensor reads from.
 
void set_offset_from_start_address (uint8_t offset)
 Records the offset as configured, and seeds the resolved position with it.
 
void set_address (uint16_t address)
 Sets the configured address, and points the range base at it.
 
void set_custom_data (const std::vector< uint8_t > &data)
 
virtual size_t get_register_size () const
 
void set_register_size (uint8_t register_size)
 

Data Fields

modbus::EntityType register_type {modbus::EntityType::CUSTOM}
 
SensorValueType sensor_value_type {SensorValueType::RAW}
 
uint16_t start_address {0}
 
uint32_t bitmask {0}
 
uint8_t offset {0}
 Position of this sensor's data within its range's response - a byte offset for registers, a bit index for coils and discrete inputs.
 
uint8_t register_count {0}
 
uint8_t response_bytes {0}
 
uint8_t offset_from_start_address {0}
 The offset exactly as configured: measured from this sensor's own start_address, where offset is measured from the first register of the range it ends up polled in.
 
uint16_t range_start_address {0}
 First register of the range this sensor is polled in; equals start_address for an unpolled item.
 
uint16_t skip_updates {0}
 
std::vector< uint8_t > custom_data {}
 
bool force_new_range {false}
 

Detailed Description

Definition at line 128 of file modbus_controller.h.

Member Function Documentation

◆ addresses_bits()

bool esphome::modbus_controller::SensorItem::addresses_bits ( ) const
inline

Coils and discrete inputs address individual bits; every other type addresses 16-bit registers.

Definition at line 136 of file modbus_controller.h.

◆ get_register_size()

virtual size_t esphome::modbus_controller::SensorItem::get_register_size ( ) const
inlinevirtual

Definition at line 161 of file modbus_controller.h.

◆ parse_and_publish()

virtual void esphome::modbus_controller::SensorItem::parse_and_publish ( std::span< const uint8_t > data)
pure virtual

Parse this sensor's slice out of its range's response and publish it.

The span points into the response buffer and is only valid for the duration of the call. Read the sensor's data from offset within it.

Implemented in esphome::modbus_controller::ModbusBinaryOutput, esphome::modbus_controller::ModbusBinarySensor, esphome::modbus_controller::ModbusFloatOutput, esphome::modbus_controller::ModbusNumber, esphome::modbus_controller::ModbusSelect, esphome::modbus_controller::ModbusSensor, esphome::modbus_controller::ModbusSwitch, and esphome::modbus_controller::ModbusTextSensor.

◆ set_address()

void esphome::modbus_controller::SensorItem::set_address ( uint16_t address)
inline

Sets the configured address, and points the range base at it.

Building the ranges moves the base to the range's first register; an item that is never polled (an output, or a switch with assumed_state) keeps its own address, so write_address() stays correct for it.

Definition at line 155 of file modbus_controller.h.

◆ set_custom_data()

void esphome::modbus_controller::SensorItem::set_custom_data ( const std::vector< uint8_t > & data)
inline

Definition at line 160 of file modbus_controller.h.

◆ set_offset_from_start_address()

void esphome::modbus_controller::SensorItem::set_offset_from_start_address ( uint8_t offset)
inline

Records the offset as configured, and seeds the resolved position with it.

Building the ranges overwrites offset with the position within the range; an item that is never polled keeps this value, which is what its own address arithmetic expects.

Definition at line 147 of file modbus_controller.h.

◆ set_register_size()

void esphome::modbus_controller::SensorItem::set_register_size ( uint8_t register_size)
inline

Definition at line 169 of file modbus_controller.h.

◆ write_address()

uint16_t esphome::modbus_controller::SensorItem::write_address ( ) const
inline

Address a write entity (switch/number/select) targets, derived from its resolved position within the range so that a write lands on the register the sensor reads from.

Definition at line 140 of file modbus_controller.h.

Field Documentation

◆ bitmask

uint32_t esphome::modbus_controller::SensorItem::bitmask {0}

Definition at line 173 of file modbus_controller.h.

◆ custom_data

std::vector<uint8_t> esphome::modbus_controller::SensorItem::custom_data {}

Definition at line 190 of file modbus_controller.h.

◆ force_new_range

bool esphome::modbus_controller::SensorItem::force_new_range {false}

Definition at line 191 of file modbus_controller.h.

◆ offset

uint8_t esphome::modbus_controller::SensorItem::offset {0}

Position of this sensor's data within its range's response - a byte offset for registers, a bit index for coils and discrete inputs.

Resolved while the ranges are built, so it already accounts for the registers ahead of it (including wide response_size ones) and for any offset inherited from an earlier sensor sharing the same register.

Definition at line 178 of file modbus_controller.h.

◆ offset_from_start_address

uint8_t esphome::modbus_controller::SensorItem::offset_from_start_address {0}

The offset exactly as configured: measured from this sensor's own start_address, where offset is measured from the first register of the range it ends up polled in.

Same units as offset - bytes for registers, bits for coils and discrete inputs. Kept so the resolution can be recomputed, and so the sort order of the sensor set never depends on the resolved value. Declared before range_start_address so it lands in the padding after response_bytes.

Definition at line 186 of file modbus_controller.h.

◆ range_start_address

uint16_t esphome::modbus_controller::SensorItem::range_start_address {0}

First register of the range this sensor is polled in; equals start_address for an unpolled item.

Definition at line 188 of file modbus_controller.h.

◆ register_count

uint8_t esphome::modbus_controller::SensorItem::register_count {0}

Definition at line 179 of file modbus_controller.h.

◆ register_type

modbus::EntityType esphome::modbus_controller::SensorItem::register_type {modbus::EntityType::CUSTOM}

Definition at line 170 of file modbus_controller.h.

◆ response_bytes

uint8_t esphome::modbus_controller::SensorItem::response_bytes {0}

Definition at line 180 of file modbus_controller.h.

◆ sensor_value_type

SensorValueType esphome::modbus_controller::SensorItem::sensor_value_type {SensorValueType::RAW}

Definition at line 171 of file modbus_controller.h.

◆ skip_updates

uint16_t esphome::modbus_controller::SensorItem::skip_updates {0}

Definition at line 189 of file modbus_controller.h.

◆ start_address

uint16_t esphome::modbus_controller::SensorItem::start_address {0}

Definition at line 172 of file modbus_controller.h.


The documentation for this class was generated from the following file: