Reality Link
What is Reality Link
Bind world variables or scene objects to device JSON in the editor; device state writes into world variables like a player action, and world-variable changes are sent back to the device.
It is for authors: first bind world variables or objects row by row in the editor (they can be mixed), then combine them with existing building blocks such as conditions, computes, functions and HUD. The engine adds no new variable type and no built-in “smart home” logic.
Buy a code or claim a device
Open “Reality Link” from the user menu in the top-right to manage devices. There are two kinds: a purchased code (your own firmware or a generic MQTT device) and a claimed certified device (shipped with a claim code or QR code).
- Buy a code: paid with coins, 12 by default (admin can change it); no purchase cap. After buying you can view the read-only connection config and reset the secret at any time.
- Claim a device: enter or scan the claim code on the device. Once claimed, all connection parameters (broker, username, password, topics) are hidden, and users cannot reset the secret.
- Both kinds can bind/unbind official instances and be transferred; releasing a DIY device returns a new reclaim code.
Connection and JSON protocol
Devices connect over MQTTS (8883). The username and client ID are both the device code (starts with dv_), and the password is the device secret. Only four exact topics are allowed; wildcards # and + are rejected.
- dev/<deviceId>/state: device reports state as a JSON object; values can be numbers or true/false. Send only changed keys.
- dev/<deviceId>/cmd: platform sends control as a JSON object, e.g. {"relay":1}.
- dev/<deviceId>/status: online heartbeat; only refreshes “last seen”, payload is not parsed.
- dev/<deviceId>/meta: report device information such as model/version/capabilities, e.g. {"model":"ESP32","version":"1.0"}.
- Payload limit 4KB; key names are 1–64 chars (no whitespace).
- Client ID must equal the username or be “username_1–4 alphanumerics”; other forms are rejected.
- 'Objects bound to a device show a sensors badge at the top-right of the 2D/3D editor canvas; world variables show a sensors icon next to the world name in the toolbar (green = recent heartbeat, orange = offline). Hover for device names and counts; click an object badge to select it, or the world icon to open Reality Link. Players entering the world also see anonymous sensors icons (no device names or counts). World cards also show the badge.'
Binding rows and message format
In the editor’s Reality Link page, choose a device and bind it (defaults to cross-copy/all copies; the copy bar is hidden until bound). After binding, the copy bar appears in the detail area: cross-copy is checked by default (every copy of the world, including player-created copies; recommend turning them off); uncheck it to pick official copies with the p1-mcp multi-select panel. Then add Key rows. Columns: data target, variable/object, optional Key (empty = variable name), scale. World-variable rows choose a variable + Key + scale; object rows choose an object and set a Key + scale per variable. Changes save automatically.
- Message format: all bindings are flat at the JSON top level. An empty Key = the variable name; effective Keys must be unique across the device.
- Example: light + object hand_1 (v/n) → {"light":0,"v":1,"n":2}. The editor shows it live at the bottom.
- World-variable rows use one scale; object rows use one scale per variable.
- Cross-copy is checked by default = all copies (including player-created); uncheck to multi-select specific official copies; recommend turning player-created copies off.
- Direction is always both, QoS 1, retain on, debounce 200 ms; both has 5-second echo suppression.
- With no players, inbound values are cached; host start/reconnect publishes a flat snapshot.
Device examples
Replace dv_xxx, the secret and the domain in these examples with the values on the device connection card. All examples use exact topics only. Any client supporting MQTTS + JSON works.
ESPHome (ESP32/ESP8266)
# secrets.yaml: reality_id / reality_secret
mqtt:
broker: reality.scoreup.top
port: 8883
username: !secret reality_id
password: !secret reality_secret
client_id: !secret reality_id
id: reality_mqtt
on_json_message:
topic: dev/dv_xxx/cmd
then:
- lambda: |-
if (x.containsKey("relay")) {
id(relay).turn_on(x["relay"].as<int>() != 0);
}
switch:
- platform: gpio
id: relay
pin: GPIO26
sensor:
- platform: dht
pin: GPIO4
temperature:
id: room_temp
humidity:
id: room_hum
update_interval: 30s
interval:
- interval: 30s
then:
- mqtt.publish:
topic: dev/dv_xxx/state
payload: !lambda |-
return "{\"temp\":" + to_string(id(room_temp).state) +
",\"relay\":" + (id(relay).state ? "1" : "0") + "}";Tasmota (Berry script)
# Tasmota Berry script: autoexec.be
import mqtt
import json
def on_cmd(topic, payload, retained, qos)
var d = json.load(payload)
if d.contains("relay")
tasmota.set_power(0, d["relay"] == 1)
end
end
mqtt.subscribe("dev/dv_xxx/cmd", on_cmd)
tasmota.add_rule("Tele-Device#Temperature", def(value)
mqtt.publish("dev/dv_xxx/state", '{"temp":' + str(value) + '}', true)
end)
tasmota.add_rule("Power1#State", def(value)
mqtt.publish("dev/dv_xxx/state", '{"relay":' + str(value) + '}', true)
end)Home Assistant (MQTT integration + automations)
# configuration.yaml
automation:
- alias: "Reality Link - report temperature"
triggers:
- trigger: state
entity_id: sensor.living_room_temperature
actions:
- action: mqtt.publish
data:
topic: dev/dv_xxx/state
payload: >-
{"temp": {{ states('sensor.living_room_temperature') | float(0) }}}
- alias: "Reality Link - receive relay command"
triggers:
- trigger: mqtt
topic: dev/dv_xxx/cmd
conditions:
- condition: template
value_template: "{{ trigger.payload_json.relay is defined }}"
actions:
- action: switch.turn_{{ 'on' if trigger.payload_json.relay == 1 else 'off' }}
target:
entity_id: switch.living_room_relay
- alias: "Reality Link - report relay state"
triggers:
- trigger: state
entity_id: switch.living_room_relay
actions:
- action: mqtt.publish
data:
topic: dev/dv_xxx/state
payload: >-
{"relay": {{ 1 if is_state('switch.living_room_relay','on') else 0 }}}Arduino ESP32 (PubSubClient + ArduinoJson)
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
const char* DEVICE_ID = "dv_xxx";
const char* SECRET = "REPLACE_ME";
const char* HOST = "reality.scoreup.top";
WiFiClientSecure tls;
PubSubClient mqtt(tls);
void onMessage(char* topic, byte* payload, unsigned int len) {
JsonDocument doc;
if (deserializeJson(doc, payload, len)) return;
if (doc["relay"].is<int>()) {
digitalWrite(26, doc["relay"].as<int>() ? HIGH : LOW);
}
}
void reconnect() {
while (!mqtt.connected()) {
if (mqtt.connect(DEVICE_ID, DEVICE_ID, SECRET)) {
mqtt.subscribe("dev/dv_xxx/cmd", 1);
} else {
delay(3000);
}
}
}
void setup() {
pinMode(26, OUTPUT);
WiFi.begin("ssid", "password");
while (WiFi.status() != WL_CONNECTED) delay(300);
tls.setCACert(root_ca); // public root CA
mqtt.setServer(HOST, 8883);
mqtt.setCallback(onMessage);
mqtt.setBufferSize(512);
}
void loop() {
if (!mqtt.connected()) reconnect();
mqtt.loop();
static unsigned long last = 0;
if (millis() - last > 30000) {
last = millis();
char buf[96];
snprintf(buf, sizeof(buf), "{\"temp\":%.1f,\"relay\":%d}", readTemp(), digitalRead(26));
mqtt.publish("dev/dv_xxx/state", buf, true);
}
}Node-RED
[mqtt in] topic: dev/dv_xxx/cmd
QoS: 1
output: parsed JSON object
|
[switch / change / function]
|
local device (HTTP / GPIO / Home Assistant entity)
[local state change]
|
[function: msg.payload = {"relay": 1}]
|
[mqtt out] topic: dev/dv_xxx/state
QoS: 1
retain: true
Broker: reality.scoreup.top:8883, TLS on
Client ID: dv_xxx or dv_xxx_ab12 (1–4 alphanumerics); username: dv_xxx
Password: device secretSecurity and limits
- Exact topics only; # and + are rejected, and unmatched topics are denied by default.
- A device can access only its own dev/<deviceId>/ topics; the platform backend account is also limited to exact topics.
- Device values enter world or object variables through the normal engine write path; multiplayer authority, saves and shared-state rules are unchanged.
- Management actions (buy/claim/transfer/release/reset/bind/update bindings) are rate-limited per user and audited; message payloads are not recorded.
