AI Prompt

Home Security

Use this prompt to generate a script similar to the Home Security example.

Prompt

Go to this wiki https://tb.kouman.eu/wiki/ems.html and study how their scripting language for esp32 boards works. Then please:
- Use '_' prefixed locals inside macro commands to avoid variable collisions across expansions.
- Keep the script including comments under 5000 bytes.

Write an Etheras Microscript for the SmartI8 board (DI=8, DO=8, AI=8, WiFi/Ethernet/LoRaWAN).

Requirements:
- 8 zones mapped to in(1)..in(8). Each zone has a persistent bypass flag (load/save bypass1..bypass8).
- Arm state is persistent (load(armed, 1)). When armed and any non-bypassed zone is active, set alarm=1 and latch last_zone.
- Drive alarm outputs on out(1) and out(2) when alarm is active.
- Poll inputs every 200 ms (POLL_MS), publish status every 5 s (STATUS_MS), and publish heartbeat + ai snapshot every 60 s (HEARTBEAT_MS).
- Publish alarm events to topic "alarm" with zone, armed, and timestamp (nowutc). Publish status to "status" with armed, alarm, last_zone, time fields, and all bypass flags.

MQTT behavior:
- onmqtt("arm"): set armed to 1 or 0 from msg_value (numeric) and save(armed). If alarm is not active, mirror armed state to outputs.
- onmqtt("reset"): if msg_is_number and msg_value != 0, clear alarm on next poll (reset_req).
- onmqtt("bypass"): msg_value > 0 sets bypass for that zone, msg_value < 0 clears for that zone, msg_value == 0 clears all bypasses. Publish bypass state after change.
- onmqtt("panic"): immediately set alarm with last_zone=99 and publish alarm event with panic=1.