Implement onoff for light entities#88
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for an onoff keyword to publish a Home Assistant MQTT light entity that is ON/OFF-only (no brightness slider), and documents the new option.
Changes:
- Document
onoffusage and provide an example configuration in the README. - Extend discovery keyword parsing to recognize
onoffand emit a simplified MQTT light discovery payload when enabled. - Bump the embedded “Downloaded version” string to 1.1.0.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| README.md | Documents the new onoff keyword and shows an example for ON/OFF-only light entities. |
| MQTT send receive.lua | Adds onoff to recognized keywords and changes MQTT light discovery payload generation to omit brightness topics when onoff is set. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
MQTT send receive.lua:134
- This change removes support for the legacy
includeunitkeyword (singular). Since previous versions usedincludeunit, this is a breaking behavior change for existing installs; consider accepting both spellings to preserve backward compatibility while keepingincludeunitsas the documented form.
'includeunits', 'preset', 'noleveltranslate', 'exactpn', 'label', 'onoff'
MQTT send receive.lua:836
- To preserve backward compatibility for existing configs that used the old
includeunitspelling, add a synonym mapping soincludeunitis treated asincludeunitsduring tag parsing.
local synonym = { binarysensor = 'binary_sensor', fanpct = 'fan_pct' }
local special = { includeunits = false, preset = false, dec = false, noleveltranslate = false, exactpn = false, label = false, onoff = false }
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (1)
MQTT send receive.lua:862
includeunit/includeunitskeyword handling looks broken:getKeyValue()appliessynonymmapping before checkingspecial, but the synonym mapsincludeunit -> includeunitswhilespecialonly definesincludeunit. As a result, neitherincludeunitnorincludeunitswill ever setspecial.includeunit, and units will never be appended even when the keyword is present.
local synonym = { binarysensor = 'binary_sensor', fanpct = 'fan_pct', includeunit = 'includeunits' }
local special = { includeunit = false, preset = false, dec = false, noleveltranslate = false, exactpn = false, label = false, onoff = false }
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
MQTT send receive.lua:580
- In
trackTransitions,goto nextis used before local variables (closing,rate,increment, etc.) are declared, but the::next::label is after those declarations. In Lua 5.2+ this is a compile-time error (agotocannot jump forward into the scope of locals declared later in the same block). Refactor to avoidgotohere and use conditional blocks instead.
for k, v in pairs(transition) do
if t < v.ts then goto next end
local closing = v.state == 'closing'
if not mqttDevices[k] or not mqttDevices[k].rate then goto next end
local rate = closing and tonumber(mqttDevices[k].rate[2]) or tonumber(mqttDevices[k].rate[1])
if not rate then goto next end
local increment = (t - v.ts) / rate * 256
if closing then v.level = v.level - increment else v.level = v.level + increment end
coverLevel[k] = math.floor(v.level + 0.5)
v.ts = t
if coverLevel[k] < 0 then coverLevel[k] = 0 elseif coverLevel[k] > 255 then coverLevel[k] = 255 end
if (coverLevel[k] == 0 and closing) or (coverLevel[k] == 255 and not closing) then kill[k] = true end
client:publish(mqttReadTopic..k..'/state', v.state, mqttQoS, RETAIN)
client:publish(mqttReadTopic..k..'/open', coverLevel[k], mqttQoS, RETAIN)
if logging then log('Publishing state and open '..mqttReadTopic..k..' to '..state..'/'..coverLevel[k]) end
::next::
end
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
MQTT send receive.lua:226
parseAddressdocuments an expected format ofnet/app/group[/channel], but currently accepts addresses with more than 4 segments (e.g.1/2/3/4/5) and silently ignores the extra parts. Treat#parts > 4as invalid to avoid mis-parsing malformed addresses.
local parts = string.split(address, '/')
if #parts < 3 then
log('Error: Invalid '..fieldName..' format for '..name..': '..tostring(address)..', expected format: net/app/group[/channel]')
return nil, nil, nil, nil
end
No description provided.