Skip to main content

⚙️ Configuration

This documentation provides a comprehensive overview of all configuration options available in the Hass library. Configuration variables can be set through environment variables, CLI switches, or configuration files in ini, yaml, and json formats.

🔧 Configuration Table

VariableTypeDefault ValueDescription
AUTO_CONNECT_SOCKETbooleantrueWebsocket must be manually initialized if set to false
AUTO_SCAN_CALL_PROXYbooleantrueShould the call proxy request a service listing at bootstrap?
BASE_URLstringhttp://homeassistant.local:8123URL to reach Home Assistant at
EXPECT_RESPONSE_AFTERnumber5If sendMessage was set to expect a response, a warning will be emitted after this delay if one is not received
MANAGE_REGISTRYbooleantrueLive track registry data
MOCK_SOCKETbooleanfalseOperate with an artificial socket connection. For unit testing
RETRY_INTERVALnumber5How often to retry connecting on connection failure (seconds)
SOCKET_AVG_DURATIONnumber5How many seconds worth of requests to use in average for math in REQ_PER_SEC calculations
SOCKET_CRASH_REQUESTS_PER_SECnumber500Socket service will commit sudoku if more than this many outgoing messages are sent to Home Assistant in a second. Usually indicates runaway code.
SOCKET_WARN_REQUESTS_PER_SECnumber300Emit warnings if the home controller attempts to send more than X messages to Home Assistant inside of a second.
TOKENstring(none)Long-lived access token to Home Assistant. Required.
TRACK_ENTITIESbooleantrueSet to false to not fetch entity info at boot, and maintain states
VALIDATE_CONFIGURATIONbooleanfalseValidate the credentials, then quit
WEBSOCKET_URLstring(none)Override calculated value if it's breaking or you want something custom. Make sure to use "ws[s]://" scheme.

💡 Example Usage

🌍 Environment

Set up as an environment variable for your shell, then run the script

export AUTO_CONNECT_SOCKET=false
tsx src/main.ts

Set up as an environment variable for just the single run

BASE_URL="http://custom.homeassistant.local:8123" tsx src/main.ts

Use a .env file to set multiple variables

# .env file
AUTO_CONNECT_SOCKET=false
AUTO_SCAN_CALL_PROXY=true
BASE_URL="http://custom.homeassistant.local:8123"
EXPECT_RESPONSE_AFTER=10
MANAGE_REGISTRY=false
MOCK_SOCKET=true
RETRY_INTERVAL=10
SOCKET_AVG_DURATION=10
SOCKET_CRASH_REQUESTS_PER_SEC=1000
SOCKET_WARN_REQUESTS_PER_SEC=600
TOKEN="your_long_lived_access_token"
TRACK_ENTITIES=false
VALIDATE_CONFIGURATION=true
WEBSOCKET_URL="wss://custom.websocket.url"
# Use the --env-file switch to provide the .env file
tsx src/main.ts --env-file .env

🎛️ CLI Switch

Provide your config as a switch

tsx src/main.ts --retry_interval 15

📁 File

If your file does not have an extension, Configuration will do auto

📘 ini

.my_app_name, ~/.config/my_app_name

[hass]
AUTO_CONNECT_SOCKET=false
AUTO_SCAN_CALL_PROXY=true
BASE_URL=http://custom.homeassistant.local:8123
EXPECT_RESPONSE_AFTER=10
MANAGE_REGISTRY=false
MOCK_SOCKET=true
RETRY_INTERVAL=10
SOCKET_AVG_DURATION=10
SOCKET_CRASH_REQUESTS_PER_SEC=1000
SOCKET_WARN_REQUESTS_PER_SEC=600
TOKEN=your_long_lived_access_token
TRACK_ENTITIES=false
VALIDATE_CONFIGURATION=true
WEBSOCKET_URL=wss://custom.websocket.url

📄 yaml

.my_app_name.yaml

hass:
AUTO_CONNECT_SOCKET: false
AUTO_SCAN_CALL_PROXY: true
BASE_URL: "http://custom.homeassistant.local:8123"
EXPECT_RESPONSE_AFTER: 10
MANAGE_REGISTRY: false
MOCK_SOCKET: true
RETRY_INTERVAL: 10
SOCKET_AVG_DURATION: 10
SOCKET_CRASH_REQUESTS_PER_SEC: 1000
SOCKET_WARN_REQUESTS_PER_SEC: 600
TOKEN: "your_long_lived_access_token"
TRACK_ENTITIES: false
VALIDATE_CONFIGURATION: true
WEBSOCKET_URL: "wss://custom.websocket.url"

🗃️ json

.my_app_name.json

{
"hass": {
"AUTO_CONNECT_SOCKET": false,
"AUTO_SCAN_CALL_PROXY": true,
"BASE_URL": "http://custom.homeassistant.local:8123",
"EXPECT_RESPONSE_AFTER": 10,
"MANAGE_REGISTRY": false,
"MOCK_SOCKET": true,
"RETRY_INTERVAL": 10,
"SOCKET_AVG_DURATION": 10,
"SOCKET_CRASH_REQUESTS_PER_SEC": 1000,
"SOCKET_WARN_REQUESTS_PER_SEC": 600,
"TOKEN": "your_long_lived_access_token",
"TRACK_ENTITIES": false,
"VALIDATE_CONFIGURATION": true,
"WEBSOCKET_URL": "wss://custom.websocket.url"
}
}