Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**Show the readings Indigo leaves out when it does not fully know a Z-Wave sensor, as Indigo devices of their own.**

**Version:** 5.15 | **Author:** CliveS & Claude | **Needs:** Indigo 2022.1 or later, with a Z-Wave interface
**Version:** 5.16 | **Author:** CliveS & Claude | **Needs:** Indigo 2022.1 or later, with a Z-Wave interface

**[Read the full guide](https://highsteads.github.io/UniversalZWaveSensor/)** — setting up, what everything means, and what to do when something goes wrong.

Expand Down Expand Up @@ -53,6 +53,8 @@ The [full guide](https://highsteads.github.io/UniversalZWaveSensor/) goes throug

## What's new

**v5.16** — Some sensor readings were filed under the wrong name. A water sensor using the older binary report showed as **Tamper** rather than **Water Leak**, a tamper showed as **Motion**, and readings such as current, voltage and CO2 landed in the wrong state, so a plug's current in amps appeared as its power in watts. The plugin's lookup tables now follow the Z-Wave standard. A reading the plugin has no state for is now reported as unknown rather than stored somewhere wrong.

**v5.15** — A sensor's **Online** state now says online from the moment the plugin starts it, and whenever it reports, so **Show Status** no longer calls a working sensor offline. A lock's **Latch Closed** state no longer shows the opposite of the truth. One of the sample messages in **Simulate Z-Wave Report** was labelled the wrong way round, and the old manual inside the plugin has gone, as the guide replaces it.

**v5.14** — The settings window was wider than the screen allowed, so the help text beside each setting was cut off. The help now wraps to fit. No setting or behaviour changed.
Expand Down
2 changes: 1 addition & 1 deletion UniversalZWaveSensor.indigoPlugin/Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<key>IwsApiVersion</key>
<string>1.0.0</string>
<key>PluginVersion</key>
<string>5.15</string>
<string>5.16</string>
<key>ServerApiVersion</key>
<string>3.0</string>
</dict>
Expand Down
96 changes: 70 additions & 26 deletions UniversalZWaveSensor.indigoPlugin/Contents/Server Plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,26 @@
# (temperature, humidity, contact, etc.) that Indigo does not expose
# natively. Uses subscribeToIncoming() to receive ALL Z-Wave bytes.
# Author: CliveS & Claude Opus 4.8, Claude Opus 5.5
# Date: 27-09-2026
# Version: 5.15
# Date: 01-11-2026
# Version: 5.16
#
# v5.16 (01-11-2026): the two Z-Wave code tables now follow the Z-Wave standard
# (checked against the zwave-js project's definitions).
# * SENSOR_BINARY types: 0x06 is Water (was read as tamper), 0x08 is Tamper (was
# motion), 0x04 is CO2 (was a water leak), and 0x09 Aux / 0x0B Tilt are no
# longer read as motion. Types the plugin has no state for (CO2, heat, freeze,
# aux, tilt, glass break) set only the primary on/off state, as an unknown
# type always has.
# * SENSOR_MULTILEVEL types: right up to 0x09 before, but from 0x0B nearly every
# entry named the wrong reading, e.g. Current (0x10) was written to watts and
# CO2 (0x11) to UV index. Corrected, with velocity (0x06), loudness (0x1E),
# target temperature (0x22), PM2.5 (0x23) and VOC (0x27) at their real codes.
# Codes with no matching state (dew point, weight, tank capacity, angle,
# seismic intensity, resistivity) are now reported as unknown instead of
# being written to an unrelated state.
# * Each reading's unit follows the scale the sensor sends: millivolts and
# milliamps are converted to V and A so the voltage and current states stay
# in one unit, and a target temperature is converted like a temperature.
#
# v5.15 (27-09-2026): Online state set True when a device starts or reports,
# False only on the stale path; simulateReport example for "motion cleared"
Expand Down Expand Up @@ -174,41 +192,62 @@
# key -> (state_id, default_unit)
# ==============================================================================
SENSOR_TYPES = {
# Codes per the Z-Wave Sensor Multilevel command class (zwave-js
# Sensors.ts, checked 01-11-2026). Before v5.16 the entries from 0x0B up
# named the wrong reading. A code not listed here is logged as unknown.
0x01: ("temperature", "degC"),
0x03: ("luminance", "lux"),
0x04: ("watts", "W"), # general power (alt to type 0x10)
0x04: ("watts", "W"), # power
0x05: ("humidity", "%"),
0x08: ("pressure", "kPa"),
0x09: ("atmosphericPressure", "kPa"), # scale=1 -> inHg
0x0B: ("velocity", "m/s"),
0x0E: ("targetTemperature", "degC"), # thermostat-style target temp via multilevel
0x0F: ("co2Level", "ppm"),
0x10: ("watts", "W"), # power (reuses energy meter state)
0x11: ("uvIndex", ""),
0x12: ("voltage", "V"), # reuses meter voltage state
0x13: ("current", "A"), # reuses meter current state
0x15: ("airFlow", "m3/h"),
0x19: ("voc", "ppm"),
0x1B: ("noise", "dB"),
0x1C: ("soilMoisture", "%"),
0x1F: ("pm25", "ug/m3"),
0x06: ("velocity", "m/s"),
0x08: ("pressure", "kPa"), # atmospheric pressure
0x09: ("atmosphericPressure", "kPa"), # barometric pressure; scale=1 -> inHg
0x0F: ("voltage", "V"),
0x10: ("current", "A"),
0x11: ("co2Level", "ppm"),
0x12: ("airFlow", "m3/h"),
0x1B: ("uvIndex", ""),
0x1E: ("noise", "dB"), # loudness
0x1F: ("soilMoisture", "%"), # moisture
0x22: ("targetTemperature", "degC"),
0x23: ("pm25", "ug/m3"),
0x27: ("voc", "ppm"),
}

# Scales other than 0 for the codes above, as (unit, multiplier). The value is
# multiplied so a state keeps one unit whatever the sensor sends: millivolts and
# milliamps become V and A. A scale missing here keeps the default unit.
# (Temperature, target temperature and luminance are handled in the parser.)
SENSOR_SCALES = {
0x06: {1: ("mph", 1.0)},
0x0F: {1: ("V", 0.001)}, # millivolts
0x10: {1: ("A", 0.001)}, # milliamps
0x12: {1: ("cfm", 1.0)},
0x1E: {1: ("dBA", 1.0)},
0x1F: {1: ("m3/m3", 1.0), 2: ("kOhm", 1.0), 3: ("aw", 1.0)},
0x23: {0: ("mol/m3", 1.0), 1: ("ug/m3", 1.0)},
0x27: {0: ("mol/m3", 1.0), 1: ("ppm", 1.0)},
}
TEMPERATURE_TYPES = (0x01, 0x22) # converted to the user's degC / degF

# ==============================================================================
# SENSOR_BINARY (0x30) sensor type lookup
# key -> state_id
# ==============================================================================
# Codes per the Z-Wave Sensor Binary command class (zwave-js BinarySensorType,
# checked 01-11-2026): 0x01 general purpose, 0x02 smoke, 0x03 CO, 0x04 CO2,
# 0x05 heat, 0x06 water, 0x07 freeze, 0x08 tamper, 0x09 aux, 0x0A door/window,
# 0x0B tilt, 0x0C motion, 0x0D glass break. Before v5.16 several were wrong (a
# water report set "tamper", a tamper report set "motion"). Codes with no state
# of their own here fall back to onOffState in _handle_binary_sensor.
BINARY_SENSOR_TYPES = {
0x01: "onOffState", # general purpose
0x02: "smoke",
0x03: "coAlarm",
0x04: "waterLeak",
0x06: "tamper",
0x08: "motion",
0x09: "motion", # PIR alternative
0x03: "coAlarm", # CO (carbon monoxide)
0x06: "waterLeak", # water
0x08: "tamper",
0x0A: "contact", # door / window
0x0B: "motion", # movement alternative
0x0C: "motion", # motion sensor (Z-Wave SENSOR_BINARY v2 type 0x0C)
0x0C: "motion",
}

# ==============================================================================
Expand Down Expand Up @@ -966,7 +1005,7 @@ def _handle_multilevel(self, device, raw) -> bool:
state_key, default_unit = SENSOR_TYPES[sensor_type]

# Resolve unit; apply temperature unit preference with conversion if needed
if sensor_type == 0x01: # temperature
if sensor_type in TEMPERATURE_TYPES: # temperature, target temperature
reported_unit = "degC" if scale == 0 else "degF"
if reported_unit != self.temp_unit:
if self.temp_unit == "degF":
Expand All @@ -977,6 +1016,11 @@ def _handle_multilevel(self, device, raw) -> bool:
unit = self.temp_unit
elif sensor_type == 0x03: # luminance
unit = "%" if scale == 0 else "lux"
elif scale in SENSOR_SCALES.get(sensor_type, {}):
unit, factor = SENSOR_SCALES[sensor_type][scale]
if factor != 1.0:
value = value * factor
precision += 3 # mV -> V keeps its resolution
else:
unit = default_unit

Expand Down Expand Up @@ -2253,7 +2297,7 @@ def updateStateImageOnServer(self, sel):
("Meter power 1500W", "32 02 01 12 05 DC", "watts"),
("Barrier open", "66 03 FF", "contact"),
("Central scene 2x", "5B 03 02 03 02", "lastSceneAction"),
("Supervision+motion", "6C 01 2A 04 30 03 FF 08", "motion"),
("Supervision+motion", "6C 01 2A 04 30 03 FF 0C", "motion"),
]

w = 78
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,9 @@ def test_humidity_icon_from_raw_path(self):
self.assertNotIn("SensorOn", dev.image_writes)

def test_co2_850_ppm(self):
"""850 ppm CO2: sensor=0x0F, precision=0, scale=0, size=2"""
"""850 ppm CO2: sensor=0x11 (CO2 in the Z-Wave standard), precision=0, scale=0, size=2"""
pss = self._prec_scale_size(0, 0, 2)
raw = [0x31, 0x05, 0x0F, pss] + list(struct.pack(">H", 850))
raw = [0x31, 0x05, 0x11, pss] + list(struct.pack(">H", 850))
dev = self._dev("generic")
self.assertTrue(self.p._handle_multilevel(dev, raw))
self.assertAlmostEqual(dev.state_writes["co2Level"]["value"], 850.0)
Expand Down Expand Up @@ -842,16 +842,16 @@ def _dev(self, sensor_type="generic"):
plugin_props={"sensorType": sensor_type})

def test_motion_detected(self):
"""0xFF + type=0x08 (PIR) -> motion=True, displayStatus=detected."""
"""0xFF + type=0x0C (Motion) -> motion=True, displayStatus=detected."""
dev = self._dev("motion")
self.assertTrue(self.p._handle_binary_sensor(dev, [0x30, 0x03, 0xFF, 0x08]))
self.assertTrue(self.p._handle_binary_sensor(dev, [0x30, 0x03, 0xFF, 0x0C]))
self.assertTrue(dev.state_writes["motion"]["value"])
self.assertEqual(dev.state_writes["displayStatus"]["value"], "detected")

def test_motion_clear(self):
"""0x00 + type=0x08 -> motion=False, displayStatus=clear."""
"""0x00 + type=0x0C -> motion=False, displayStatus=clear."""
dev = self._dev("motion")
self.assertTrue(self.p._handle_binary_sensor(dev, [0x30, 0x03, 0x00, 0x08]))
self.assertTrue(self.p._handle_binary_sensor(dev, [0x30, 0x03, 0x00, 0x0C]))
self.assertFalse(dev.state_writes["motion"]["value"])
self.assertEqual(dev.state_writes["displayStatus"]["value"], "clear")

Expand All @@ -870,9 +870,9 @@ def test_contact_closed(self):
self.assertEqual(dev.state_writes["displayStatus"]["value"], "closed")

def test_water_leak(self):
"""0xFF + type=0x04 -> waterLeak=True, displayStatus=leak."""
"""0xFF + type=0x06 (Water) -> waterLeak=True, displayStatus=leak."""
dev = self._dev("generic")
self.assertTrue(self.p._handle_binary_sensor(dev, [0x30, 0x03, 0xFF, 0x04]))
self.assertTrue(self.p._handle_binary_sensor(dev, [0x30, 0x03, 0xFF, 0x06]))
self.assertTrue(dev.state_writes["waterLeak"]["value"])
self.assertEqual(dev.state_writes["waterLeak"]["uiValue"], "leak")

Expand All @@ -883,9 +883,9 @@ def test_smoke_alarm(self):
self.assertTrue(dev.state_writes["smoke"]["value"])

def test_tamper(self):
"""0xFF + type=0x06 -> tamper=True."""
"""0xFF + type=0x08 (Tamper) -> tamper=True."""
dev = self._dev("generic")
self.assertTrue(self.p._handle_binary_sensor(dev, [0x30, 0x03, 0xFF, 0x06]))
self.assertTrue(self.p._handle_binary_sensor(dev, [0x30, 0x03, 0xFF, 0x08]))
self.assertTrue(dev.state_writes["tamper"]["value"])

def test_v1_no_type_byte_fallback(self):
Expand Down Expand Up @@ -2002,7 +2002,7 @@ def setUp(self):
self.p = make_plugin()

def test_crc16_multichannel_supervision_nest(self):
inner = [0x30, 0x03, 0xFF, 0x08] # SENSOR_BINARY motion active
inner = [0x30, 0x03, 0xFF, 0x0C] # SENSOR_BINARY motion (type 0x0C) active
sup = [0x6C, 0x01, 0x2A, len(inner)] + inner
mc = [0x60, 0x0D, 0x01, 0x00] + sup # src_ep=1
crc = [0x56, 0x01] + mc + [0xAB, 0xCD]
Expand Down
9 changes: 9 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ nav_order: 10

The newest version is at the top.

## 5.16 — 1 November 2026

- **Sensor readings are filed under the right name.** A sensor says what kind of reading it is sending with a code number, and two of the plugin's lookup tables had several codes wrong:
- From a sensor using the older on/off (binary) report, a **water leak** set **Tamper** instead of **Water Leak**, and a **tamper** (the cover being removed) set **Motion**. A CO2 alarm set **Water Leak**, and aux and tilt reports set **Motion**.
- Among measured readings, temperature, light, power, humidity and pressure were right, but most of the rest were not: **current** was stored as power in watts, **voltage** as CO2, **CO2** as UV index, and so on.
- Both tables now follow the Z-Wave standard. Check any trigger you built on one of the affected states, because it will now see the reading it was meant to.
- A reading the plugin has no state for, such as dew point or weight, is now reported in the Event Log as unknown rather than being stored in an unrelated state. A binary report the plugin has no state for (CO2, heat, freeze, aux, tilt, glass break) changes only the device's on/off state.
- Voltage and current sent in millivolts or milliamps are stored in volts and amps, so the states keep one unit. A thermostat's target temperature sent in Fahrenheit is converted like any other temperature.

## 5.15 — 27 September 2026

- A sensor's **Online** state now shows online as soon as the plugin starts the device, and again every time the sensor reports. Before, it only changed when a sensor went quiet or came back, so a sensor that had never gone quiet could be listed as offline in **Show Status**. A sensor still shows offline when it has sent nothing for longer than the **Stale threshold**.
Expand Down
23 changes: 23 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Filename: conftest.py
# Description: Shared seam for the tests in tests/. Puts the bundle's
# "Server Plugin" folder on sys.path and imports the bundle's own
# test_plugin.py, which installs the ONE indigo stand-in this
# suite uses (a MagicMock with real kStateImageSel names), so
# plugin.py can be imported here with no Indigo server. Does not
# define a second stub.
# Author: CliveS & Claude Opus 5.5
# Date: 01-11-2026
# Version: 1.0

import os
import sys

REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
SERVER_PLUGIN = os.path.join(REPO_ROOT, "UniversalZWaveSensor.indigoPlugin",
"Contents", "Server Plugin")
if SERVER_PLUGIN not in sys.path:
sys.path.insert(0, SERVER_PLUGIN)

import test_plugin # noqa: E402,F401 (installs sys.modules["indigo"])
71 changes: 71 additions & 0 deletions tests/test_xml_callbacks_and_changelog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Filename: test_xml_callbacks_and_changelog.py
# Description: Generic checks this repo did not have yet:
# - every <CallbackMethod> and every <List method="..."> named in
# the XML exists on Plugin (a missing one only fails when the
# user opens that dialog or menu)
# - every state plugin.py writes by name is declared on at
# least one device type in Devices.xml
# - docs/changelog.md's newest entry is the version Info.plist
# ships
# Author: CliveS & Claude Opus 5.5
# Date: 01-11-2026
# Version: 1.0

import ast
import glob
import os
import plistlib
import re
import xml.etree.ElementTree as ET

import plugin as plugin_module
from conftest import REPO_ROOT, SERVER_PLUGIN

NATIVE_STATES = {"onOffState"} # supplied by Indigo for relay / sensor types


def _xml_root(name):
return ET.parse(os.path.join(SERVER_PLUGIN, name)).getroot()


def test_every_xml_callback_exists_on_the_plugin():
named = []
for path in sorted(glob.glob(os.path.join(SERVER_PLUGIN, "*.xml"))):
root = ET.parse(path).getroot()
for el in root.iter("CallbackMethod"):
named.append((os.path.basename(path), (el.text or "").strip()))
for el in root.iter("List"):
if el.get("method"):
named.append((os.path.basename(path), el.get("method")))
assert len(named) >= 6, "expected the menu callbacks and the device pickers"
missing = [f"{f}: {m}" for f, m in named
if not callable(getattr(plugin_module.Plugin, m, None))]
assert not missing, f"XML names methods plugin.py does not define: {missing}"


def test_every_state_written_by_name_is_declared_somewhere():
with open(os.path.join(SERVER_PLUGIN, "plugin.py"), encoding="utf-8") as fh:
tree = ast.parse(fh.read())
written = set()
for node in ast.walk(tree):
if (isinstance(node, ast.Call) and isinstance(node.func, ast.Attribute)
and node.func.attr in ("updateStateOnServer", "_safe_update")):
args = node.args[1:] if node.func.attr == "_safe_update" else node.args
if args and isinstance(args[0], ast.Constant) and isinstance(args[0].value, str):
written.add(args[0].value)
declared = {s.get("id") for s in _xml_root("Devices.xml").iter("State")}
assert {"lastUpdate", "deviceOnline", "displayStatus"} <= written
undeclared = written - declared - NATIVE_STATES
assert not undeclared, f"written but declared on no device type: {sorted(undeclared)}"


def test_docs_changelog_newest_entry_is_this_version():
plist = glob.glob(os.path.join(REPO_ROOT, "*.indigoPlugin", "Contents", "Info.plist"))[0]
with open(plist, "rb") as fh:
version = plistlib.load(fh)["PluginVersion"]
with open(os.path.join(REPO_ROOT, "docs", "changelog.md"), encoding="utf-8") as fh:
entries = re.findall(r"^##\s+v?(\d+(?:\.\d+)+)\b", fh.read(), re.M)
assert entries, "docs/changelog.md has no '## <version>' entries"
assert entries[0] == version, f"newest changelog entry {entries[0]}, Info.plist {version}"
Loading
Loading