Package 'ha'

Title: Interact with 'Home Assistant'
Description: Provides tools to control smart home features via the API for 'Home Assistant' <https://developers.home-assistant.io/>. Allows for controlling states, services, and events. Supports configuring both local access and remote access.
Authors: Christopher T. Kenny [aut, cre] (ORCID: <https://orcid.org/0000-0002-9386-6860>)
Maintainer: Christopher T. Kenny <[email protected]>
License: MIT + file LICENSE
Version: 0.0.0.9000
Built: 2026-05-31 06:19:13 UTC
Source: https://github.com/christopherkenny/ha

Help Index


Check if the API is running

Description

Check if the API is running

Usage

ha_api(ip = NULL)

Arguments

ip

IP address. Default is NULL, which uses the local host.

Value

A list containing the API information.

Examples

ha_api()

Get Home Assistant configuration validity

Description

Get Home Assistant configuration validity

Usage

ha_check_config(ip = NULL)

Arguments

ip

IP address. Default is NULL, which uses the local host.

Value

A list containing the Home Assistant configuration check result.

Examples

ha_check_config()

Remove Home Assistant State

Description

Remove Home Assistant State

Usage

ha_delete_states(entity_id, ip = NULL)

Arguments

entity_id

Entity ID. For example, sensor.temperature.

ip

IP address. Default is NULL, which uses the local host.

Value

A list containing a confirmation message.

Examples

ha_set_states('rpkg.test', 'on')
ha_delete_states('rpkg.test')

Retrieve Home Assistant calendars

Description

Retrieve Home Assistant calendars

Usage

ha_get_calendars(ip = NULL)

Arguments

ip

IP address. Default is NULL, which uses the local host.

Value

A list containing Home Assistant calendar information.

Examples

ha_get_calendars()

Retrieve Home Assistant Configuration

Description

Retrieve Home Assistant Configuration

Usage

ha_get_config(ip = NULL)

Arguments

ip

IP address. Default is NULL, which uses the local host.

Value

A list containing the Home Assistant configuration.

Examples

ha_get_config()

Retrieve Home Assistant Error Log

Description

Retrieve Home Assistant Error Log

Usage

ha_get_error_log(ip = NULL)

Arguments

ip

IP address. Default is NULL, which uses the local host.

Value

A character vector containing the Home Assistant error log.

Examples

ha_get_error_log()

Retrieve Home Assistant Events

Description

Retrieve Home Assistant Events

Usage

ha_get_events(ip = NULL)

Arguments

ip

IP address. Default is NULL, which uses the local host.

Value

A list containing Home Assistant event information.

Examples

ha_get_events()

Retrieve Home Assistant History

Description

Retrieve Home Assistant History

Usage

ha_get_history(entity_id, timestamp = NULL, ip = NULL)

Arguments

entity_id

Required. Entity ID. For example, sensor.temperature.

timestamp

Optional. Time in YYYY-MM-DDThh:mm:ssTZD format.

ip

IP address. Default is NULL, which uses the local host.

Value

A list containing Home Assistant history entries.

Examples

ha_get_history('update.home_assistant_core_update')

Retrieve Home Assistant Logbook Entries

Description

Retrieve Home Assistant Logbook Entries

Usage

ha_get_logbook(timestamp = NULL, ip = NULL)

Arguments

timestamp

Optional. Time in YYYY-MM-DDThh:mm:ssTZD format.

ip

IP address. Default is NULL, which uses the local host.

Value

A list containing Home Assistant logbook entries.

Examples

ha_get_logbook()

Retrieve Home Assistant Services

Description

Retrieve Home Assistant Services

Usage

ha_get_services(ip = NULL)

Arguments

ip

IP address. Default is NULL, which uses the local host.

Value

A list containing Home Assistant service information.

Examples

ha_get_services()

Retrieve Home Assistant States

Description

Retrieve Home Assistant States

Usage

ha_get_states(entity_id = NULL, ip = NULL)

Arguments

entity_id

Optional. Entity ID. For example, sensor.temperature.

ip

IP address. Default is NULL, which uses the local host.

Value

A list containing Home Assistant state information.

Examples

ha_get_states()

Render a Home Assistant Template

Description

Render a Home Assistant Template

Usage

ha_render_template(template, ip = NULL)

Arguments

template

a length one character vector containing the template to render.

ip

IP address. Default is NULL, which uses the local host.

Value

A length one character vector containing the rendered template

Examples

ha_render_template("My living room light is {{ states('light.h6076') }}.")

Set Home Assistant Events

Description

Set Home Assistant Events

Usage

ha_set_event(event_type, event_data = NULL, ip = NULL)

Arguments

event_type

The type of event to set, e.g. light.turn_on

event_data

Optional. A named list of data to send with the event.

ip

IP address. Default is NULL, which uses the local host.

Value

A vector of events fired with a confirmation or detailed information

Examples

ha_set_event('light.test')

Set Home Assistant Intents

Description

Note that this requires use of "intents" for Home Assistant, which are not enabled by default. Using these without enabling them will create an error.

Usage

ha_set_intent(intent, ip = NULL)

Arguments

intent

an intent to fire

ip

IP address. Default is NULL, which uses the local host.

Value

A list of intents

Examples

ha_set_intent(list(name = 'SetTimer', data = list(seconds = '30')))

Add Entry to Renviron

Description

Adds Home Assistant API key to .Renviron.

Usage

ha_set_key(key, overwrite = FALSE, install = FALSE, r_env = NULL)

Arguments

key

Character. API key to add to add.

overwrite

Defaults to FALSE. Boolean. Should existing FELT_KEY in Renviron be overwritten?

install

Defaults to FALSE. Boolean. Should this be added to an environment file, r_env?

r_env

Path to install to if install is TRUE.

Value

key, invisibly

Examples

example_env <- tempfile(fileext = '.Renviron')
ha_set_key('EXAMPLE-1234', r_env = example_env)
# r_env should likely be: file.path(Sys.getenv('HOME'), '.Renviron')

Set Home Assistant Services

Description

Set Home Assistant Services

Usage

ha_set_services(domain, service, entity_id, ip = NULL)

Arguments

domain

An entity domain. For example, light or switch.

service

A service name. For example, turn_on or turn_off.

entity_id

Entity ID. For example, sensor.temperature.

ip

IP address. Default is NULL, which uses the local host.

Value

A list of changes made by the service call

Examples

ha_set_services('light', 'turn_off', 'light.h6076')

Set Home Assistant State

Description

Set Home Assistant State

Usage

ha_set_states(entity_id, state, attributes = NULL, ip = NULL)

Arguments

entity_id

Entity ID. For example, sensor.temperature.

state

A state value. For example, on or off.

attributes

Optional. A named list of attributes to set for the entity.

ip

IP address. Default is NULL, which uses the local host.

Value

a list of information on the new or updated state

Examples

ha_set_states(entity_id = 'rpkg.test', state = 'on',
  attributes = list(version = '4.5.1'))

Check or Get Home Assistant API Key

Description

Check or Get Home Assistant API Key

Usage

ha_has_key()

ha_get_key()

Value

logical if has, key if get

Examples

ha_has_key()