companion-variable-set-value

Set and read Bitfocus Companion variable values at runtime using setVariableValues and getVariableValue.

Updated May 19, 2026
One-click install
npx skills add https://github.com/digitaldrummerj/bitfocus-companion-skills --skill companion-variable-set-value-digitaldrummerj
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: companion-variable-set-value
Source: https://github.com/digitaldrummerj/bitfocus-companion-skills/tree/main/plugins/companion-variable-set-value
Command: npx skills add https://github.com/digitaldrummerj/bitfocus-companion-skills --skill companion-variable-set-value-digitaldrummerj

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @companion-module/base.

What problem does it solve? Bitfocus Companion module developers often set variable values before declaring them, pass unsupported object types, or read undefined values, causing buttons to display $(internal:variable_not_found) or stale data. This Skill provides the correct patterns for updating and reading variable state at runtime. ## Core Features & Use Cases - Setting Values: Call setVariableValues() with one or many keys during init() or in device state-change handlers, with support for partial updates. - Reading Values: Use getVariableValue() with undefined guards to safely compute a variable's next value. - Type Rules & Sequencing: Enforces allowed value types (string, number, boolean, undefined) and the rule that setVariableDefinitions() must run before setVariableValues(). - Use Case: When a device sends a status update over the network, use this Skill to update only the changed variables (e.g., volume_db, mute_state) so buttons always show current device state. ## Quick Start Ask the agent to update a Companion module so it sets initial variable values in init() and updates them whenever device state changes.

Frequently Asked Questions about companion-variable-set-value

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set variable values in a Bitfocus Companion module?▼

Call self.setVariableValues() with an object whose keys are variable IDs and values are strings, numbers, or booleans. Always call setVariableDefinitions() first so Companion can resolve the variables, then set initial values in init() or update them in state-change handlers.

How do I read a Companion variable's current value?▼

Use self.getVariableValue(variableId), which returns string, number, boolean, or undefined. Always guard the result with a default such as the nullish coalescing operator, since arithmetic on undefined produces NaN.

Why do my Companion buttons show variable_not_found?▼

This happens when setVariableValues() is called before the variables are declared with setVariableDefinitions(). Companion cannot resolve undeclared variable IDs, so always register definitions first, then set values.

Can I set an object or array as a Companion variable value?▼

No, only string, number, boolean, and undefined values are allowed. Convert objects or arrays with JSON.stringify() before passing them to setVariableValues(), otherwise you get runtime errors or [object Object] displayed on buttons.

Do I need to update all Companion variables at once?▼

No, setVariableValues() supports partial updates. Pass only the keys that changed and Companion merges them into its internal state, leaving all other variables at their current values.