Skip to main content
The EntityRegistry caches entity metadata populated by ListEntities and the latest state from incoming state responses. It is thread-safe for concurrent access and is available via client.Entities().

Entity interface

Every entity type implements the Entity interface:
type Entity interface {
    GetKey()      uint32
    GetName()     string
    GetObjectID() string
    GetDomain()   EntityDomain
}
GetDomain() returns an EntityDomain constant. Calling .String() on it returns the canonical ESPHome domain name (e.g. "sensor", "binary_sensor", "switch").

EntityDomain constants

const (
    DomainSensor      EntityDomain = iota
    DomainBinarySensor
    DomainCover
    DomainFan
    DomainLight
    DomainSwitch
    DomainTextSensor
    DomainCamera
    DomainClimate
    DomainNumber
    DomainSelect
    DomainSiren
    DomainLock
    DomainButton
    DomainMediaPlayer
    DomainWaterHeater
)
ConstantDomain string
DomainSensorsensor
DomainBinarySensorbinary_sensor
DomainCovercover
DomainFanfan
DomainLightlight
DomainSwitchswitch
DomainTextSensortext_sensor
DomainCameracamera
DomainClimateclimate
DomainNumbernumber
DomainSelectselect
DomainSirensiren
DomainLocklock
DomainButtonbutton
DomainMediaPlayermedia_player
DomainWaterHeaterwater_heater

EntityRegistry methods

ByKey

Returns any entity by its numeric key. Returns nil if no entity with that key has been registered.
func (r *EntityRegistry) ByKey(key uint32) Entity
entity := client.Entities().ByKey(0x12345678)
if entity != nil {
    fmt.Printf("%s (%s)\n", entity.GetName(), entity.GetDomain())
}

Len

Returns the total number of entities registered across all domains.
func (r *EntityRegistry) Len() int

Clear

Removes all entities from every domain map. Called automatically by the reconnect loop before re-discovering entities after a reconnection.
func (r *EntityRegistry) Clear()

Typed accessors

Each domain has a dedicated accessor that returns a slice of the concrete entity type. The slice is a copy — modifying it does not affect the registry.
func (r *EntityRegistry) Sensors() []*SensorEntity
func (r *EntityRegistry) BinarySensors() []*BinarySensorEntity
func (r *EntityRegistry) Switches() []*SwitchEntity
func (r *EntityRegistry) Lights() []*LightEntity
func (r *EntityRegistry) Covers() []*CoverEntity
func (r *EntityRegistry) Fans() []*FanEntity
func (r *EntityRegistry) Climates() []*ClimateEntity
func (r *EntityRegistry) Numbers() []*NumberEntity
func (r *EntityRegistry) Selects() []*SelectEntity
func (r *EntityRegistry) Sirens() []*SirenEntity
func (r *EntityRegistry) Locks() []*LockEntity
func (r *EntityRegistry) Buttons() []*ButtonEntity
func (r *EntityRegistry) MediaPlayers() []*MediaPlayerEntity
func (r *EntityRegistry) WaterHeaters() []*WaterHeaterEntity
func (r *EntityRegistry) TextSensors() []*TextSensorEntity
func (r *EntityRegistry) Cameras() []*CameraEntity

Entity types

Numeric sensor with a float state and optional unit of measurement.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
ObjectIDstringEntity object ID
IconstringOptional icon string
UnitOfMeasurementstringe.g. °C, %, hPa
DeviceClassstringe.g. temperature, humidity
StateClasspb.SensorStateClassMeasurement, total, or total increasing
AccuracyDecimalsint32Display precision hint
ForceUpdateboolWhether state is always published
DisabledByDefaultboolWhether entity is disabled by default
EntityCategorypb.EntityCategoryEntity category
DeviceIDuint32Associated device ID
Statefloat32Latest received value
MissingStatebooltrue until the first state update is received
for _, s := range client.Entities().Sensors() {
    if s.MissingState {
        fmt.Printf("%s = <missing>\n", s.Name)
    } else {
        fmt.Printf("%s = %.4g %s\n", s.Name, s.State, s.UnitOfMeasurement)
    }
}
Boolean sensor (on/off, true/false).
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
ObjectIDstringEntity object ID
IconstringOptional icon string
DeviceClassstringe.g. motion, door, occupancy
IsStatusBinarySensorboolWhether this is the device’s status sensor
DisabledByDefaultboolWhether entity is disabled by default
EntityCategorypb.EntityCategoryEntity category
DeviceIDuint32Associated device ID
StateboolLatest received state
MissingStatebooltrue until the first state update is received
Binary output (on/off) that can be controlled.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
ObjectIDstringEntity object ID
IconstringOptional icon string
AssumedStateboolWhether state is assumed rather than reported
DeviceClassstringe.g. outlet, switch
DisabledByDefaultboolWhether entity is disabled by default
EntityCategorypb.EntityCategoryEntity category
DeviceIDuint32Associated device ID
StateboolLatest received state (true = on)
Use SetSwitch to control a switch.
Light output with optional colour, brightness, and effect support.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
ObjectIDstringEntity object ID
SupportedColorModes[]pb.ColorModeSupported colour modes
MinMiredsfloat32Minimum colour temperature (mireds)
MaxMiredsfloat32Maximum colour temperature (mireds)
Effects[]stringAvailable effect names
StateboolOn/off state
Brightnessfloat32Brightness (0.0–1.0)
ColorModepb.ColorModeActive colour mode
ColorBrightnessfloat32Colour brightness (0.0–1.0)
Redfloat32Red channel (0.0–1.0)
Greenfloat32Green channel (0.0–1.0)
Bluefloat32Blue channel (0.0–1.0)
Whitefloat32White channel (0.0–1.0)
ColorTemperaturefloat32Colour temperature (mireds)
ColdWhitefloat32Cold white channel (0.0–1.0)
WarmWhitefloat32Warm white channel (0.0–1.0)
EffectstringActive effect name
Use SetLight to control a light.
Motorised cover (blind, shutter, garage door).
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
ObjectIDstringEntity object ID
AssumedStateboolWhether state is assumed
SupportsPositionboolWhether position control is supported
SupportsTiltboolWhether tilt control is supported
SupportsStopboolWhether stop command is supported
DeviceClassstringe.g. blind, garage, shutter
Positionfloat32Current position (0.0 = closed, 1.0 = open)
Tiltfloat32Current tilt (0.0–1.0)
CurrentOperationpb.CoverOperationActive operation (opening, closing, idle)
Use SetCover or SetCoverPosition to control a cover.
Fan with optional speed, oscillation, and direction.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
SupportsOscillationboolWhether oscillation is supported
SupportsSpeedboolWhether speed control is supported
SupportsDirectionboolWhether direction control is supported
SupportedSpeedCountint32Number of discrete speed levels
SupportedPresetModes[]stringAvailable preset mode names
StateboolOn/off state
OscillatingboolWhether oscillating
Directionpb.FanDirectionRotation direction
SpeedLevelint32Current speed level
PresetModestringActive preset mode
Use SetFan to control a fan.
Climate / HVAC unit with temperature, humidity, fan modes, and swing modes.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
SupportedModes[]pb.ClimateModeAvailable modes
VisualMinTemperaturefloat32Minimum displayable temperature
VisualMaxTemperaturefloat32Maximum displayable temperature
SupportedFanModes[]pb.ClimateFanModeAvailable fan modes
SupportedSwingModes[]pb.ClimateSwingModeAvailable swing modes
SupportedPresets[]pb.ClimatePresetAvailable presets
Modepb.ClimateModeActive climate mode
CurrentTemperaturefloat32Current measured temperature
TargetTemperaturefloat32Target temperature setpoint
Actionpb.ClimateActionCurrent action (heating, cooling, idle, …)
FanModepb.ClimateFanModeActive fan mode
SwingModepb.ClimateSwingModeActive swing mode
CurrentHumidityfloat32Current measured humidity
TargetHumidityfloat32Target humidity setpoint
Use SetClimate to control a climate entity.
Numeric input within a defined range.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
MinValuefloat32Minimum accepted value
MaxValuefloat32Maximum accepted value
Stepfloat32Increment step
UnitOfMeasurementstringUnit label
Modepb.NumberModeDisplay mode (auto, box, slider)
DeviceClassstringDevice class hint
Statefloat32Current value
MissingStatebooltrue until first state is received
Use SetNumber to set the value.
Dropdown option selector.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
Options[]stringAvailable option strings
StatestringCurrently selected option
MissingStatebooltrue until first state is received
Use SetSelect to set the value.
Audible alarm / siren with optional tone, duration, and volume.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
Tones[]stringAvailable tone names
SupportsDurationboolWhether duration is configurable
SupportsVolumeboolWhether volume is configurable
StateboolOn/off state
Use SetSiren to control a siren.
Lock with optional code support.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
AssumedStateboolWhether state is assumed
SupportsOpenboolWhether an open command is supported
RequiresCodeboolWhether a code is required to operate
CodeFormatstringRegex pattern for acceptable codes
Statepb.LockStateCurrent state (locked, unlocked, jammed, …)
Use SetLock to control a lock.
Stateless momentary button. Has no state fields — pressing a button triggers an action on the device.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
DeviceClassstringe.g. restart, update
Use PressButton to trigger a button.
Media player with playback control and volume.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
SupportsPauseboolWhether pause is supported
Statepb.MediaPlayerStateCurrent state (idle, playing, paused, …)
Volumefloat32Current volume (0.0–1.0)
MutedboolWhether muted
Use SetMediaPlayer to control a media player.
Water heater with temperature setpoints and mode selection.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
MinTemperaturefloat32Minimum setpoint
MaxTemperaturefloat32Maximum setpoint
TargetTemperatureStepfloat32Increment step
SupportedModes[]pb.WaterHeaterModeAvailable modes
CurrentTemperaturefloat32Current measured temperature
TargetTemperaturefloat32Target setpoint
Modepb.WaterHeaterModeActive mode
Sensor that reports a string value.
FieldTypeDescription
Keyuint32Stable entity identifier
NamestringHuman-readable name
DeviceClassstringDevice class hint
StatestringLatest received value
MissingStatebooltrue until first state is received