The entity model provides JavaScript classes for representing Home Assistant entities in the plasmoid. It includes runtime entity data (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/korapp/plasma-homeassistant/llms.txt
Use this file to discover all available pages before exploring further.
Entity) and configuration entity data (ConfigEntity).
Overview
The model is implemented as an ES6 JavaScript module that exports entity classes and utility functions. Location:package/contents/code/model.mjs
Type: JavaScript ES Module
Exports:
Entity- Runtime entity with live state dataConfigEntity- Configuration entity with action definitions
Entity Class
Represents a Home Assistant entity with its current state and computed properties.Constructor
Home Assistant entity ID (e.g.,
"light.bedroom", "sensor.temperature")Custom display nameFalls back to
attributes.friendly_name if not providedCustom icon nameFalls back to
attributes.icon if not provided. Supports Material Design Icons (mdi:) and Plasma iconsInitial/default state valueOverridden by
data.s if providedAttribute name to display instead of stateWhen set, displays the value of
attributes[attribute] instead of the state valueInitial attributes objectMerged with
data.a to create final attributes. Common attributes:friendly_name: Display nameicon: Icon identifierunit_of_measurement: Unit string- Domain-specific attributes (brightness, temperature, etc.)
Custom unit stringFalls back to
attributes.unit_of_measurement if not providedService call configuration for click actionStructure:
Service call configuration for scroll action (number fields)Same structure as
default_actionLive state update from Home AssistantProperties:
s: New state valuea: Updated attributes object
Properties
All Entity instances have the following properties:The entity’s unique identifier
Current state value (merged from initial state and
data.s)Merged attributes from configuration and live data
Display name, resolved from custom name or
attributes.friendly_nameIcon identifier, resolved from custom icon or
attributes.iconUnit string, resolved from custom unit or
attributes.unit_of_measurementAttribute name to display (if any)
Click action configuration
Scroll action configuration
Whether the entity is in an “active” stateTrue if state is
"on", "open", or "idle"Entity domain extracted from entity_idExamples:
"light", "sensor", "switch", "climate"Computed display value using
getDisplayValue()Shows attribute value or formatted state with unitImplementation
Frommodel.mjs:9-22:
Usage Example
Frommain.qml:96-102:
main.qml:82-94):
ConfigEntity Class
Represents an entity in the configuration UI with reactive action properties.Constructor
Entity ID to configure
Custom display name
Custom icon identifier
Attribute name to display
Click action configuration
Scroll action configuration
Whether to show notifications when entity value changes
Properties
ConfigEntity uses property descriptors for reactive behavior:Reactive entity ID propertyWhen set, automatically:
- Updates internal
domainproperty - Updates action targets to match new entity_id
- Validates actions against new domain
Entity domain extracted from entity_id
Reactive default action propertyWhen set, automatically:
- Validates service exists
- Sets domain from entity domain if not provided
- Sets target to current entity_id if not provided
- Returns
nullif service is empty
Reactive scroll action property (same behavior as default_action)
Implementation
Frommodel.mjs:24-52:
Action Property Logic
Frommodel.mjs:54-73:
Usage Example
FromConfigItems.qml:34 and ConfigItem.qml:
getDisplayValue Function
Utility function that formats entity display values.Signature
Entity state value
Attribute name to display (if any)
Entity attributes object
Unit string
Formatted display string
Logic
Frommodel.mjs:3-7:
Behavior
- Attribute mode: If
attributeis set and exists inattributes, return that value - State mode: If state exists and is not
"unknown", return formatted state:- Percentage: Append
%directly (e.g.,"75%") - Other units: Add space before unit (e.g.,
"22 °C")
- Percentage: Append
- Fallback: Return empty string if no valid value
Examples
Active States
The model defines which states are considered “active”:active === true, which can be used for:
- Visual highlighting
- Icon selection
- Color themes
- Filtering
Data Flow
Configuration to Runtime
- User configures entity in ConfigItems using
ConfigEntity - Configuration saved to
plasmoid.configuration.itemsas JSON - Main plasmoid reads configuration and parses JSON to array
- Array items used as templates to create
Entityinstances - Live state data merged into Entity instances
- Entity instances stored in
itemModelfor UI display
State Updates
- Home Assistant sends state change event via WebSocket
- Event contains entity_id and change data:
{entity_id: {"+": {s: "new_state", a: {...}}}} - Find corresponding item in model by entity_id
- Create new
Entitymerging existing config with new state - Replace old Entity in model with new one
- QML UI automatically updates via model binding
Best Practices
- Immutable updates: Always create new Entity instances for updates (don’t modify existing)
- Merge carefully: Use
Object.assign({}, old, new)to merge attributes safely - Check attribute existence: Always check
if (attribute && attributes[attribute])before accessing - Validate entity_id: Ensure entity_id contains a dot before extracting domain
- Handle undefined: Use default parameters and fallback chains for safety
- Use ConfigEntity reactivity: Let property setters handle domain/action updates automatically
Type Reference
Entity Type
ConfigEntity Type
Action Type
Related Components
- Client Component - Fetches entity state data
- Main Plasmoid - Uses Entity for itemModel
- Configuration Components - Uses ConfigEntity
