alarm_control_panel

Go types for Home Assistant's alarm_control_panel domain: control over HTTP and MQTT, serve over MQTT discovery.

Control: HTTP Control: MQTT Serve a device Discovery config
import "github.com/taumatix/homeassistant-go/domains/alarmcontrolpanel"

Overview

Package alarmcontrolpanel is Home Assistant's alarm_control_panel domain: its types and its MQTT discovery config.

Entity controls one alarm_control_panel entity over HTTP or MQTT. Device serves one over MQTT.

Home Assistant documents the domain here:

Integration: https://www.home-assistant.io/integrations/alarm_control_panel/

MQTT discovery: https://www.home-assistant.io/integrations/alarm_control_panel.mqtt/

Entity model (developers): https://contributors.home-assistant.io/core/entities/alarm-control-panel/

Control

// client is an *api.Client or a connected *mqtt.Client
target := alarmcontrolpanel.Get(client, "my_alarm_control_panel")
state, err := target.State(ctx)
err = target.AlarmArmAway(ctx)

Serve

// mqttClient is a connected *mqtt.Client
device, err := alarmcontrolpanel.NewDevice(ctx, mqttClient, "my-alarm-control-panel",
	alarmcontrolpanel.WithName("My alarm control panel"),
)

Commands

What each Entity method does on each transport. MQTT publishes to the topic the entity's discovery config names in that option.

MethodOver HTTP, callsOver MQTT, publishes to
AlarmArmAway alarm_control_panel.alarm_arm_away command_topic
AlarmArmCustomBypass alarm_control_panel.alarm_arm_custom_bypass command_topic
AlarmArmHome alarm_control_panel.alarm_arm_home command_topic
AlarmArmNight alarm_control_panel.alarm_arm_night command_topic
AlarmArmVacation alarm_control_panel.alarm_arm_vacation command_topic
AlarmDisarm alarm_control_panel.alarm_disarm command_topic
AlarmTrigger alarm_control_panel.alarm_trigger command_topic

Control

type Entity struct

Entity controls one alarm_control_panel entity over HTTP (api.Client) or MQTT (mqtt.Client). State and Subscribe come from the embedded Handle.

Embeds entity.Handle[Attributes], whose methods it has too.

func Get(transport entity.Transport, id string) *Entity

Get returns the alarm_control_panel entity with the given id: an entity id over HTTP (the "alarm_control_panel." prefix may be omitted), a discovery object path or unique id over MQTT. It does no I/O.

func List(ctx context.Context, transport entity.Transport) ([]*Entity, error)

List returns every alarm_control_panel entity the transport can see: all of Home Assistant's over HTTP, the discovered ones over MQTT.

func (e *Entity) AlarmArmAway(ctx context.Context, options ...entity.ServiceOption) error

AlarmArmAway calls alarm_control_panel.alarm_arm_away, or publishes payload_arm_away to command_topic. Core describes the service: Arms an alarm in the away mode.

func (e *Entity) AlarmArmCustomBypass(ctx context.Context, options ...entity.ServiceOption) error

AlarmArmCustomBypass calls alarm_control_panel.alarm_arm_custom_bypass, or publishes payload_arm_custom_bypass to command_topic. Core describes the service: Arms an alarm while allowing to bypass a custom area.

func (e *Entity) AlarmArmHome(ctx context.Context, options ...entity.ServiceOption) error

AlarmArmHome calls alarm_control_panel.alarm_arm_home, or publishes payload_arm_home to command_topic. Core describes the service: Arms an alarm in the home mode.

func (e *Entity) AlarmArmNight(ctx context.Context, options ...entity.ServiceOption) error

AlarmArmNight calls alarm_control_panel.alarm_arm_night, or publishes payload_arm_night to command_topic. Core describes the service: Arms an alarm in the night mode.

func (e *Entity) AlarmArmVacation(ctx context.Context, options ...entity.ServiceOption) error

AlarmArmVacation calls alarm_control_panel.alarm_arm_vacation, or publishes payload_arm_vacation to command_topic. Core describes the service: Arms an alarm in the vacation mode.

func (e *Entity) AlarmDisarm(ctx context.Context, options ...entity.ServiceOption) error

AlarmDisarm calls alarm_control_panel.alarm_disarm, or publishes payload_disarm to command_topic. Core describes the service: Disarms an alarm.

func (e *Entity) AlarmTrigger(ctx context.Context, options ...entity.ServiceOption) error

AlarmTrigger calls alarm_control_panel.alarm_trigger, or publishes payload_trigger to command_topic. Core describes the service: Triggers an alarm manually.

type State = entity.State[Attributes]

State is a snapshot of one alarm_control_panel entity.

func Code(value string) entity.ServiceOption

Code sets the "code" service data field.

Serve over MQTT

type Device struct

Device is one alarm_control_panel entity served by this process over MQTT. Close, Delete and ReportAvailability come from the embedded mqtt.Device.

Commands from Home Assistant arrive through the On*Command callbacks. A callback's ctx is cancelled when the client closes; an error it returns goes to the client's error path (mqtt.WithLogger, mqtt.WithOnError).

Embeds *mqtt.Device, whose methods it has too.

func NewDevice(ctx context.Context, client *mqtt.Client, objectID string, options ...DeviceOption) (*Device, error)

NewDevice announces a alarm_control_panel entity through MQTT discovery and returns the device serving it. objectID may carry one "node_id/" prefix. Command, state and availability topics default to <topic root>/alarm_control_panel/<objectID>/... and the options can override them. The client must be connected.

func (d *Device) Config() Config

Config returns the discovery config announced to Home Assistant.

func (d *Device) OnAlarmArmAwayCommand(fn func(ctx context.Context) error)

OnAlarmArmAwayCommand registers the callback for Home Assistant requesting alarm_arm_away.

func (d *Device) OnAlarmArmCustomBypassCommand(fn func(ctx context.Context) error)

OnAlarmArmCustomBypassCommand registers the callback for Home Assistant requesting alarm_arm_custom_bypass.

func (d *Device) OnAlarmArmHomeCommand(fn func(ctx context.Context) error)

OnAlarmArmHomeCommand registers the callback for Home Assistant requesting alarm_arm_home.

func (d *Device) OnAlarmArmNightCommand(fn func(ctx context.Context) error)

OnAlarmArmNightCommand registers the callback for Home Assistant requesting alarm_arm_night.

func (d *Device) OnAlarmArmVacationCommand(fn func(ctx context.Context) error)

OnAlarmArmVacationCommand registers the callback for Home Assistant requesting alarm_arm_vacation.

func (d *Device) OnAlarmDisarmCommand(fn func(ctx context.Context) error)

OnAlarmDisarmCommand registers the callback for Home Assistant requesting alarm_disarm.

func (d *Device) OnAlarmTriggerCommand(fn func(ctx context.Context) error)

OnAlarmTriggerCommand registers the callback for Home Assistant requesting alarm_trigger.

func (d *Device) ReportState(ctx context.Context, state string, opts ...mqtt.StateOption) error

ReportState reports the state on state_topic. opts override the client's state QoS and retain defaults for this publish.

type DeviceOption func(config *Config)

DeviceOption customizes the discovery config of a device before it is announced. Options run before the default topics are derived, so a topic they set is kept.

func WithConfig(fn func(config *Config)) DeviceOption

WithConfig applies fn to the discovery config for adjustments not covered by the other options.

func WithDeviceDetails(details ha.MQTTDeviceDetails) DeviceOption

WithDeviceDetails ties the entity to a device in the Home Assistant device registry.

func WithName(name string) DeviceOption

WithName sets the friendly name announced to Home Assistant.

State and values

type Attributes struct

Attributes are the state attributes of a alarm_control_panel entity, under the names Home Assistant publishes them with.

See: https://www.home-assistant.io/integrations/alarm_control_panel/

FieldTypeWire keyDescription
ChangedBy*stringchanged_by

Changed by.

CodeArmRequiredboolcode_arm_required

Code for arming. Over MQTT it comes from the code_arm_required option.

CodeFormat*CodeFormatcode_format

Code format.

SupportedFeaturesFeaturesupported_features

A set of Feature flags.

CodeFormat

type CodeFormat string

CodeFormat is core's CodeFormat.

ConstantValue
CodeFormatUnknown"Unknown"
CodeFormatText"text"
CodeFormatNumber"number"
func CodeFormatFromString(s string) CodeFormat

CodeFormatFromString returns the CodeFormat spelled s, by its value or by the name of core's member, and CodeFormatUnknown for anything else.

func (v *CodeFormat) UnmarshalJSON(data []byte) error

UnmarshalJSON reads any spelling CodeFormatFromString accepts.

Feature

type Feature uint64

Feature is a set of alarm_control_panel supported features, with the values of core's AlarmControlPanelEntityFeature: the supported_features attribute decodes into it.

ConstantValue
FeatureUnknown0
FeatureArmHome1 << 0
FeatureArmAway1 << 1
FeatureArmNight1 << 2
FeatureTrigger1 << 3
FeatureArmCustomBypass1 << 4
FeatureArmVacation1 << 5
func FeatureFromString(s string) Feature

FeatureFromString returns the Feature spelled s, by its value or by the name of core's member, and FeatureUnknown for anything else.

StateValue

type StateValue string

StateValue is core's AlarmControlPanelState.

ConstantValue
StateValueUnknown"Unknown"
StateValueDisarmed"disarmed"
StateValueArmedHome"armed_home"
StateValueArmedAway"armed_away"
StateValueArmedNight"armed_night"
StateValueArmedVacation"armed_vacation"
StateValueArmedCustomBypass"armed_custom_bypass"
StateValuePending"pending"
StateValueArming"arming"
StateValueDisarming"disarming"
StateValueTriggered"triggered"
func StateValueFromString(s string) StateValue

StateValueFromString returns the StateValue spelled s, by its value or by the name of core's member, and StateValueUnknown for anything else.

func (v *StateValue) UnmarshalJSON(data []byte) error

UnmarshalJSON reads any spelling StateValueFromString accepts.

MQTT discovery config

type Config struct

Config is the MQTT discovery config of alarm_control_panel.

See: https://www.home-assistant.io/integrations/alarm_control_panel.mqtt/

FieldTypeWire keyDescription
Availability[]ha.MQTTAvailabilityavailability
AvailabilityMode*stringavailability_mode

Allowed: "all", "any", "latest".

Default: "latest"

AvailabilityTemplate*ha.Templateavailability_template
AvailabilityTopic*stringavailability_topic

Topic to receive the availability payload on. NewDevice defaults it to <base>/availability.

Code*stringcode
CodeArmRequired*boolcode_arm_required

If set, the code is required to arm the alarm. If not set, the code is not validated. Over MQTT, Entity reports it as the "code_arm_required" attribute.

Default: true

CodeDisarmRequired*boolcode_disarm_required

If set, the code is required to disarm the alarm. If not set, the code is not validated.

Default: true

CodeTriggerRequired*boolcode_trigger_required

If set, the code is required to manually trigger the alarm. If not set, the code is not validated.

Default: true

CommandTemplate*ha.Templatecommand_template

Only Home Assistant renders templates: with it set, Entity refuses to publish to command_topic.

Default: "{{action}}"

CommandTopicstringcommand_topic

Required. Entity.AlarmArmAway publishes to it. Entity.AlarmArmCustomBypass publishes to it. Entity.AlarmArmHome publishes to it. Entity.AlarmArmNight publishes to it. Entity.AlarmArmVacation publishes to it. Entity.AlarmDisarm publishes to it. Entity.AlarmTrigger publishes to it. Device.OnAlarmArmAwayCommand receives what is published to it. Device.OnAlarmArmCustomBypassCommand receives what is published to it. Device.OnAlarmArmHomeCommand receives what is published to it. Device.OnAlarmArmNightCommand receives what is published to it. Device.OnAlarmArmVacationCommand receives what is published to it. Device.OnAlarmDisarmCommand receives what is published to it. Device.OnAlarmTriggerCommand receives what is published to it. NewDevice defaults it to <base>/alarm_arm_away/set.

DefaultEntityId*stringdefault_entity_id
Device*ha.MQTTDeviceDetailsdevice
EnabledByDefault*boolenabled_by_default

Default: true

Encoding*stringencoding

Default: "utf-8"

EntityCategory*stringentity_category

Allowed: "config", "diagnostic".

EntityPicture*stringentity_picture

An URL to a picture to be assigned.

Group[]stringgroup
Icon*ha.Iconicon
JsonAttributesTemplate*ha.Templatejson_attributes_template
JsonAttributesTopic*stringjson_attributes_topic

The library does not use it: extra attributes in a JSON document, which is not offered yet.

MessageExpiryInterval*map[string]anymessage_expiry_interval

Retention time interval for published message.

Name*stringname
Origin*ha.DeviceOriginorigin
PayloadArmAway*stringpayload_arm_away

The payload sent when an "arm away" command is issued. Entity.AlarmArmAway publishes it. Device.OnAlarmArmAwayCommand matches the received payload against it.

Default: "ARM_AWAY"

PayloadArmCustomBypass*stringpayload_arm_custom_bypass

The payload sent when an "arm custom bypass" command is issued. Entity.AlarmArmCustomBypass publishes it. Device.OnAlarmArmCustomBypassCommand matches the received payload against it.

Default: "ARM_CUSTOM_BYPASS"

PayloadArmHome*stringpayload_arm_home

The payload sent when an "arm home" command is issued. Entity.AlarmArmHome publishes it. Device.OnAlarmArmHomeCommand matches the received payload against it.

Default: "ARM_HOME"

PayloadArmNight*stringpayload_arm_night

The payload sent when an "arm night" command is issued. Entity.AlarmArmNight publishes it. Device.OnAlarmArmNightCommand matches the received payload against it.

Default: "ARM_NIGHT"

PayloadArmVacation*stringpayload_arm_vacation

The payload sent when an "arm vacation" command is issued. Entity.AlarmArmVacation publishes it. Device.OnAlarmArmVacationCommand matches the received payload against it.

Default: "ARM_VACATION"

PayloadAvailable*stringpayload_available

The payload that indicates the device is available (defaults to 'online').

Default: "online"

PayloadDisarm*stringpayload_disarm

Entity.AlarmDisarm publishes it. Device.OnAlarmDisarmCommand matches the received payload against it.

Default: "DISARM"

PayloadNotAvailable*stringpayload_not_available

The payload that indicates the device is not available (defaults to 'offline').

Default: "offline"

PayloadTrigger*stringpayload_trigger

The payload sent when a "trigger alarm" command is issued. Entity.AlarmTrigger publishes it. Device.OnAlarmTriggerCommand matches the received payload against it.

Default: "TRIGGER"

Qos*intqos

Default: 0

Retain*boolretain

Default: false

StateTopicstringstate_topic

Required. Over MQTT, Entity reads the entity state from it. Device.ReportState publishes to it. NewDevice defaults it to <base>/state.

SupportedFeatures[]stringsupported_features

The features that the entity supports. Allowed: "arm_home", "arm_away", "arm_night", "arm_vacation", "arm_custom_bypass", "trigger".

Default: [ "arm_home", "arm_away", "arm_night", "arm_vacation", "arm_custom_bypass", "trigger" ]

UniqueId*stringunique_id
ValueTemplate*ha.Templatevalue_template

Only Home Assistant renders templates: with it set, Entity skips state_topic when reading state. It applies to every state topic without a template of its own; Entity skips those topics when reading state.

VisibleByDefault*boolvisible_by_default

Default: true

func (*Config) IsMQTTDiscoverySchema()

IsMQTTDiscoverySchema marks Config as a discovery payload (ha.MQTTDiscoverySchema).