diff --git a/lib/extension/publish.js b/lib/extension/publish.js index d3becfb5..fb7e1ce2 100644 --- a/lib/extension/publish.js +++ b/lib/extension/publish.js @@ -178,14 +178,13 @@ class EntityPublish extends Extension { // When the key has a endpointName included (e.g. state_right), this will override the target. if (resolvedEntity.type === 'device' && key.includes('_')) { - const underscoreIndex = key.lastIndexOf('_'); - const possibleEndpointName = key.substring(underscoreIndex + 1, key.length); - if (utils.getEndpointNames().includes(possibleEndpointName)) { - endpointName = possibleEndpointName; - key = key.substring(0, underscoreIndex); + const endpointNameMatch = utils.getEndpointNames().find((n) => key.endsWith(`_${n}`)); + if (endpointNameMatch) { + endpointName = endpointNameMatch; + key = key.replace(`_${endpointNameMatch}`, ''); + const device = target.getDevice(); actualTarget = device.getEndpoint(definition.endpoint(device)[endpointName]); - if (!actualTarget) { logger.error(`Device '${resolvedEntity.name}' has no endpoint '${endpointName}'`); continue;