fix: refactor MQTT topic generation and enhance variable classification logic

This commit is contained in:
jhartworks
2026-04-16 15:41:39 +02:00
parent 9702a88cb3
commit d85e01ca16
2 changed files with 330 additions and 157 deletions
+329 -156
View File
@@ -12,10 +12,10 @@ class CounterClient extends IPSModule
$this->RegisterPropertyBoolean('EnableMQTT', false); $this->RegisterPropertyBoolean('EnableMQTT', false);
$this->RegisterPropertyInteger('MqttClientID', 0); $this->RegisterPropertyInteger('MqttClientID', 0);
$this->RegisterPropertyString('Projectname', ''); $this->RegisterPropertyString('Projectname', '');
$this->RegisterPropertyInteger('Projectyear', 2026); $this->RegisterPropertyInteger('Projectyear', 2026);
$this->RegisterPropertyInteger('Projectnumber', 0); $this->RegisterPropertyInteger('Projectnumber', 0);
$this->RegisterTimer('Update', 0, 'SECC_BuildAndStorePayload('.$this->InstanceID.');'); $this->RegisterTimer('Update', 0, 'SECC_BuildAndStorePayload(' . $this->InstanceID . ');');
} }
public function ApplyChanges() public function ApplyChanges()
@@ -46,7 +46,7 @@ class CounterClient extends IPSModule
if ($this->ReadPropertyBoolean('EnableMQTT')) { if ($this->ReadPropertyBoolean('EnableMQTT')) {
$mqttClientId = $this->ReadPropertyInteger('MqttClientID'); $mqttClientId = $this->ReadPropertyInteger('MqttClientID');
$mqttTopic = 'Projekte'.$this->ReadPropertyInteger('Projectyear').'/P'.$this->ReadPropertyInteger('Projectnumber').'/Counters'; $mqttTopic = 'Projekte' . $this->ReadPropertyInteger('Projectyear') . '/P' . $this->ReadPropertyInteger('Projectnumber') . '/Counters';
if ($mqttClientId > 0 && IPS_InstanceExists($mqttClientId) && $mqttTopic !== '') { if ($mqttClientId > 0 && IPS_InstanceExists($mqttClientId) && $mqttTopic !== '') {
$this->MqttPublish($mqttClientId, $mqttTopic, $json, true); $this->MqttPublish($mqttClientId, $mqttTopic, $json, true);
@@ -65,23 +65,29 @@ class CounterClient extends IPSModule
} }
$counterIds = IPS_GetChildrenIDs($counterCategoryId); $counterIds = IPS_GetChildrenIDs($counterCategoryId);
$payload = [ $payload = [
'timestamp' => date('Y-m-d H:i:s'), 'timestamp' => date('Y-m-d H:i:s'),
'counters' => [] 'counters' => []
]; ];
foreach ($counterIds as $counterObjectId) { foreach ($counterIds as $counterObjectId) {
if (!IPS_ObjectExists($counterObjectId)) {
continue;
}
$obj = IPS_GetObject($counterObjectId); $obj = IPS_GetObject($counterObjectId);
if ($obj['ObjectType'] != 0) { if ((int)$obj['ObjectType'] !== 0) {
continue; continue;
} }
$counterName = IPS_GetName($counterObjectId); $counterName = IPS_GetName($counterObjectId);
$counterId = $this->makeSlug($counterName); $counterId = $this->makeSlug($counterName);
$varIds = $this->CollectVariablesRecursive($counterObjectId); $entries = $this->CollectEntriesRecursive($counterObjectId, [$counterName], []);
if (count($varIds) === 0) { if (count($entries) === 0) {
IPS_LogMessage('CounterClient', 'Keine Variablen gefunden in Counter: ' . $counterName);
continue; continue;
} }
@@ -93,15 +99,15 @@ class CounterClient extends IPSModule
$tempSlots = []; $tempSlots = [];
$pressureSlots = []; $pressureSlots = [];
foreach ($varIds as $varId) { foreach ($entries as $entry) {
$classified = $this->ClassifyVariable($varId); $classified = $this->ClassifyEntry($entry);
if ($classified === null) { if ($classified === null) {
continue; continue;
} }
$field = $classified['field']; $field = $classified['field'];
$value = $classified['value']; $value = $classified['value'];
$unit = $classified['unit']; $unit = $classified['unit'];
if ($field === 'temperature_auto') { if ($field === 'temperature_auto') {
$tempSlots[] = $classified; $tempSlots[] = $classified;
@@ -123,64 +129,98 @@ class CounterClient extends IPSModule
$this->assignInOutValues($counterData, $tempSlots, 'temperature_in_value', 'temperature_out_value'); $this->assignInOutValues($counterData, $tempSlots, 'temperature_in_value', 'temperature_out_value');
$this->assignInOutValues($counterData, $pressureSlots, 'pressure_in_value', 'pressure_out_value'); $this->assignInOutValues($counterData, $pressureSlots, 'pressure_in_value', 'pressure_out_value');
$counterData['type'] = $this->DetectCounterType($counterData); $contextString = mb_strtolower($counterName . ' ' . implode(' ', array_map(function ($e) {
return $e['context'];
}, $entries)));
$counterData['type'] = $this->DetectCounterType($counterData, $contextString);
if (!isset($counterData['unit'])) { if (!isset($counterData['unit'])) {
$counterData['unit'] = $this->inferDefaultUnit($counterData); $counterData['unit'] = $this->inferDefaultUnit($counterData);
} }
if (count($counterData) > 3) { if ($this->hasUsableMeasurement($counterData)) {
$payload['counters'][] = $counterData; $payload['counters'][] = $counterData;
} else {
IPS_LogMessage('CounterClient', 'Counter ohne erkannte Messwerte übersprungen: ' . $counterName);
} }
} }
return json_encode($payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); return json_encode($payload, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
} }
private function CollectVariablesRecursive(int $objectId): array private function CollectEntriesRecursive(int $objectId, array $pathParts, array $visited): array
{ {
$result = []; $result = [];
if (isset($visited[$objectId])) {
return $result;
}
$visited[$objectId] = true;
if (!IPS_ObjectExists($objectId)) {
return $result;
}
if (IPS_LinkExists($objectId)) {
$link = IPS_GetLink($objectId);
$targetId = (int)$link['TargetID'];
$linkName = IPS_GetName($objectId);
if ($targetId > 0 && IPS_ObjectExists($targetId)) {
$newPath = $pathParts;
if ($linkName !== '') {
$newPath[] = $linkName;
}
return $this->CollectEntriesRecursive($targetId, $newPath, $visited);
}
return $result;
}
if (IPS_VariableExists($objectId)) {
$result[] = [
'varId' => $objectId,
'context' => $this->buildContextString($pathParts, IPS_GetName($objectId)),
'path' => $pathParts,
'varName' => IPS_GetName($objectId)
];
return $result;
}
$children = IPS_GetChildrenIDs($objectId); $children = IPS_GetChildrenIDs($objectId);
foreach ($children as $childId) { foreach ($children as $childId) {
if (IPS_LinkExists($childId)) { if (!IPS_ObjectExists($childId)) {
$link = IPS_GetLink($childId);
$targetId = (int) $link['TargetID'];
if (IPS_VariableExists($targetId)) {
$result[$targetId] = $targetId;
} elseif (IPS_ObjectExists($targetId)) {
foreach ($this->CollectVariablesRecursive($targetId) as $subVarId) {
$result[$subVarId] = $subVarId;
}
}
continue; continue;
} }
if (IPS_VariableExists($childId)) { $childName = IPS_GetName($childId);
$result[$childId] = $childId; $newPath = $pathParts;
continue;
if ($childName !== '') {
$newPath[] = $childName;
} }
if (IPS_ObjectExists($childId)) { $sub = $this->CollectEntriesRecursive($childId, $newPath, $visited);
foreach ($this->CollectVariablesRecursive($childId) as $subVarId) { foreach ($sub as $entry) {
$result[$subVarId] = $subVarId; $result[] = $entry;
}
} }
} }
return array_values($result); return $result;
} }
private function ClassifyVariable(int $varId): ?array private function ClassifyEntry(array $entry): ?array
{ {
$varId = (int)$entry['varId'];
if (!IPS_VariableExists($varId)) { if (!IPS_VariableExists($varId)) {
return null; return null;
} }
$var = IPS_GetVariable($varId); $var = IPS_GetVariable($varId);
$type = (int) $var['VariableType']; $type = (int)$var['VariableType'];
if ($type !== 1 && $type !== 2) { if ($type !== 1 && $type !== 2) {
return null; return null;
@@ -194,15 +234,17 @@ class CounterClient extends IPSModule
} }
if ($profileName === '' || !IPS_VariableProfileExists($profileName)) { if ($profileName === '' || !IPS_VariableProfileExists($profileName)) {
IPS_LogMessage('CounterClient', 'Variable ohne gültiges Profil ignoriert: ' . $entry['context']);
return null; return null;
} }
$profile = IPS_GetVariableProfile($profileName); $profile = IPS_GetVariableProfile($profileName);
$suffix = trim((string) $profile['Suffix']); $suffix = trim((string)$profile['Suffix']);
$prefix = trim((string) $profile['Prefix']); $prefix = trim((string)$profile['Prefix']);
$unit = trim($prefix . ' ' . $suffix); $unit = trim($prefix . ' ' . $suffix);
if ($unit === '') { if ($unit === '') {
IPS_LogMessage('CounterClient', 'Variable ohne Einheit ignoriert: ' . $entry['context']);
return null; return null;
} }
@@ -211,135 +253,144 @@ class CounterClient extends IPSModule
return null; return null;
} }
$value = round((float) $value, 3); $value = round((float)$value, 3);
$context = mb_strtolower($entry['context']);
$varName = mb_strtolower(IPS_GetName($varId));
$parentId = IPS_GetParent($varId);
if ($parentId > 0) {
$varName = mb_strtolower(IPS_GetName($parentId) . ' ' . IPS_GetName($varId));
}
$unitNorm = $this->normalizeUnit($unit); $unitNorm = $this->normalizeUnit($unit);
if (in_array($unitNorm, ['kwh', 'kw/h', 'wh', 'mwh', 'm3', 'l'], true)) { if ($this->isTotalUnit($unitNorm, $context)) {
return [ return [
'field' => 'total_value', 'field' => 'total_value',
'value' => $value, 'value' => $value,
'unit' => $suffix !== '' ? trim($suffix) : $unitNorm, 'unit' => $this->formatOutputUnit($suffix, $unitNorm),
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
if (in_array($unitNorm, ['kw', 'w', 'mw'], true)) { if ($this->isPowerUnit($unitNorm, $context)) {
return [ return [
'field' => 'power_value', 'field' => 'power_value',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
if (in_array($unitNorm, ['m3/h', 'l/h', 'l/min'], true)) { if ($this->isFlowUnit($unitNorm, $context)) {
return [ return [
'field' => 'flow_value', 'field' => 'flow_value',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
if ($unitNorm === 'a') { if ($unitNorm === 'a') {
return [ return [
'field' => 'current_value', 'field' => 'current_value',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
if ($unitNorm === 'v') { if ($unitNorm === 'v') {
return [ return [
'field' => 'voltage_value', 'field' => 'voltage_value',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
if ($unitNorm === 'hz') { if ($unitNorm === 'hz') {
return [ return [
'field' => 'frequency_value', 'field' => 'frequency_value',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
if (in_array($unitNorm, ['bar', 'mbar', 'pa'], true)) { if (in_array($unitNorm, ['bar', 'mbar', 'pa'], true)) {
if ($this->looksLikeIn($varName)) { if ($this->looksLikeIn($context)) {
return [ return [
'field' => 'pressure_in_value', 'field' => 'pressure_in_value',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
if ($this->looksLikeOut($varName)) { if ($this->looksLikeOut($context)) {
return [ return [
'field' => 'pressure_out_value', 'field' => 'pressure_out_value',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
return [ return [
'field' => 'pressure_auto', 'field' => 'pressure_auto',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
if (in_array($unitNorm, ['°c', 'c', 'k'], true)) { if (in_array($unitNorm, ['°c', 'c', 'k'], true)) {
if ($this->looksLikeIn($varName)) { if ($this->looksLikeIn($context)) {
return [ return [
'field' => 'temperature_in_value', 'field' => 'temperature_in_value',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
if ($this->looksLikeOut($varName)) { if ($this->looksLikeOut($context)) {
return [ return [
'field' => 'temperature_out_value', 'field' => 'temperature_out_value',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
return [ return [
'field' => 'temperature_auto', 'field' => 'temperature_auto',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
if ($unitNorm === 'cos' || $unitNorm === 'cosphi' || $unitNorm === 'pf') { if ($unitNorm === 'cos' || $unitNorm === 'cosphi' || $unitNorm === 'pf') {
return [ return [
'field' => 'power_factor', 'field' => 'power_factor',
'value' => $value, 'value' => $value,
'unit' => $unitNorm, 'unit' => $unitNorm,
'name' => $varName 'name' => $context,
'context' => $context
]; ];
} }
IPS_LogMessage('CounterClient', 'Nicht erkannt: ' . $context . ' | Unit: ' . $unitNorm . ' | Profile: ' . $profileName);
return null; return null;
} }
private function assignInOutValues(array &$counterData, array $items, string $fieldIn, string $fieldOut): void private function assignInOutValues(array &$counterData, array $items, string $fieldIn, string $fieldOut): void
{ {
foreach ($items as $item) { foreach ($items as $item) {
@@ -367,72 +418,182 @@ class CounterClient extends IPSModule
} }
} }
private function DetectCounterType(array $counterData): string private function DetectCounterType(array $counterData, string $context): string
{ {
$unit = isset($counterData['unit']) ? $this->normalizeUnit((string) $counterData['unit']) : ''; $unit = isset($counterData['unit']) ? $this->normalizeUnit((string)$counterData['unit']) : '';
$ctx = mb_strtolower($context);
if (isset($counterData['voltage_value']) || isset($counterData['current_value']) || isset($counterData['frequency_value']) || isset($counterData['power_factor'])) { if (isset($counterData['voltage_value']) || isset($counterData['current_value']) || isset($counterData['frequency_value']) || isset($counterData['power_factor'])) {
return 'electricity'; return 'electricity';
} }
if (isset($counterData['temperature_in_value']) || isset($counterData['temperature_out_value'])) { if (isset($counterData['temperature_in_value']) || isset($counterData['temperature_out_value'])) {
if (strpos($ctx, 'kalt') !== false || strpos($ctx, 'cool') !== false || strpos($ctx, 'kaelte') !== false || strpos($ctx, 'kälte') !== false) {
return 'cooling';
}
return 'heat'; return 'heat';
} }
if ($unit === 'm3' || $unit === 'l') { if ($unit === 'm3' || $unit === 'l') {
if (strpos($ctx, 'gas') !== false) {
return 'gas';
}
return 'water'; return 'water';
} }
if ($unit === 'kwh' || $unit === 'mwh' || $unit === 'wh') { if ($unit === 'kwh' || $unit === 'kw/h' || $unit === 'mwh' || $unit === 'wh') {
if (isset($counterData['temperature_in_value']) || isset($counterData['flow_value'])) { if (isset($counterData['flow_value']) || strpos($ctx, 'waerme') !== false || strpos($ctx, 'wärme') !== false || strpos($ctx, 'warmwasser') !== false || strpos($ctx, 'heizung') !== false) {
return 'heat'; return 'heat';
} }
return 'electricity'; return 'electricity';
} }
if (strpos($ctx, 'gas') !== false) {
return 'gas';
}
return 'other'; return 'other';
} }
private function inferDefaultUnit(array $counterData): string private function inferDefaultUnit(array $counterData): string
{ {
if (isset($counterData['total_value'])) { if (isset($counterData['total_value'])) {
if ($counterData['type'] === 'water') { if ($counterData['type'] === 'water' || $counterData['type'] === 'gas') {
return 'm3'; return 'm3';
} }
return 'kWh'; return 'kWh';
} }
return ''; return '';
} }
private function hasUsableMeasurement(array $counterData): bool
{
$fields = [
'total_value',
'consumption_value',
'power_value',
'flow_value',
'current_value',
'voltage_value',
'temperature_in_value',
'temperature_out_value',
'pressure_in_value',
'pressure_out_value',
'frequency_value',
'power_factor'
];
foreach ($fields as $field) {
if (array_key_exists($field, $counterData)) {
return true;
}
}
return false;
}
private function isTotalUnit(string $unitNorm, string $context): bool
{
if (in_array($unitNorm, ['kwh', 'wh', 'mwh', 'm3', 'l'], true)) {
return true;
}
if ($unitNorm === 'kw/h' || $unitNorm === 'w/h' || $unitNorm === 'mw/h') {
return true;
}
if (strpos($context, 'energy') !== false && in_array($unitNorm, ['kw', 'w', 'mw'], true)) {
return true;
}
if (strpos($context, 'volume') !== false && in_array($unitNorm, ['m3', 'l'], true)) {
return true;
}
return false;
}
private function isPowerUnit(string $unitNorm, string $context): bool
{
if (in_array($unitNorm, ['kw', 'w', 'mw'], true)) {
if (strpos($context, 'energy') !== false) {
return false;
}
return true;
}
return false;
}
private function isFlowUnit(string $unitNorm, string $context): bool
{
if (in_array($unitNorm, ['m3/h', 'l/h', 'l/min'], true)) {
return true;
}
if (strpos($context, 'flow') !== false && in_array($unitNorm, ['m3', 'l'], true)) {
return true;
}
return false;
}
private function formatOutputUnit(string $suffix, string $unitNorm): string
{
$suffix = trim($suffix);
if ($suffix !== '') {
return $suffix;
}
if ($unitNorm === 'm3') {
return 'm³';
}
if ($unitNorm === 'kwh') {
return 'kWh';
}
if ($unitNorm === 'kw/h') {
return 'kW/h';
}
return $unitNorm;
}
private function looksLikeIn(string $name): bool private function looksLikeIn(string $name): bool
{ {
$name = mb_strtolower($name);
return strpos($name, 'vorlauf') !== false return strpos($name, 'vorlauf') !== false
|| strpos($name, 'vl') !== false || strpos($name, 'vl') !== false
|| strpos($name, 'flow') !== false || strpos($name, 'flow') !== false
|| strpos($name, 'ein') !== false || strpos($name, 'ein') !== false
|| strpos($name, ' in ') !== false || strpos($name, 'iv') !== false
|| strpos($name, 'iv') !== false; || strpos($name, 'inlet') !== false;
} }
private function looksLikeOut(string $name): bool private function looksLikeOut(string $name): bool
{ {
$name = mb_strtolower($name);
return strpos($name, 'ruecklauf') !== false return strpos($name, 'ruecklauf') !== false
|| strpos($name, 'rücklauf') !== false || strpos($name, 'rücklauf') !== false
|| strpos($name, 'rl') !== false || strpos($name, 'rl') !== false
|| strpos($name, 'return') !== false || strpos($name, 'return') !== false
|| strpos($name, 'aus') !== false || strpos($name, 'aus') !== false
|| strpos($name, ' out ') !== false || strpos($name, 'ri') !== false
|| strpos($name, 'ri') !== false; || strpos($name, 'outlet') !== false;
} }
private function normalizeUnit(string $unit): string private function normalizeUnit(string $unit): string
{ {
$unit = mb_strtolower(trim($unit)); $unit = mb_strtolower(trim($unit));
$unit = str_replace([' ', '°'], ['', '°'], $unit); $unit = str_replace(["\xc2\xa0", ' '], '', $unit);
$unit = str_replace(['m³', '㎥'], 'm3', $unit); $unit = str_replace(['m³', '㎥'], 'm3', $unit);
$unit = str_replace(['°'], '°', $unit);
$unit = str_replace(['kw/hh'], 'kw/h', $unit);
$unit = str_replace(['㎾/h'], 'kw/h', $unit);
return $unit; return $unit;
} }
@@ -449,73 +610,85 @@ class CounterClient extends IPSModule
return $text; return $text;
} }
public function MqttPublish($server_id, $topic, $payload, $retain) {
// ensure server instance exists private function buildContextString(array $pathParts, string $varName): string
if(!IPS_InstanceExists($server_id)) { {
$parts = $pathParts;
if ($varName !== '') {
$parts[] = $varName;
}
$parts = array_values(array_filter($parts, function ($v) {
return trim((string)$v) !== '';
}));
return implode(' ', $parts);
}
public function MqttPublish($server_id, $topic, $payload, $retain)
{
if (!IPS_InstanceExists($server_id)) {
return false; return false;
} }
$ips_var_type = 3; $ips_var_type = 3;
$module_id = '{01C00ADD-D04E-452E-B66A-D253278743FE}';
$ident = 'TempMQTTDevice_' . $this->InstanceID;
if (!IPS_SemaphoreEnter($ident, 100)) {
return false;
}
$module_id = "{01C00ADD-D04E-452E-B66A-D253278743FE}" /* Module ID of MQTT Server Device */; try {
$ident = "TempMQTTDevice"; $id = @IPS_GetObjectIDByIdent($ident, $this->InstanceID);
if ($id === false) {
// enter semaphore to ensure the temporary device gets used by one thread at a time
if(IPS_SemaphoreEnter($ident, 100)) {
// get temporary MQTT Server Device or create if needed
$id = @IPS_GetObjectIDByIdent($ident, $_IPS['SELF']);
if($id === false) {
$id = @IPS_CreateInstance($module_id); $id = @IPS_CreateInstance($module_id);
if($id === false) { if ($id === false) {
IPS_SemaphoreLeave($ident);
return false; return false;
} }
IPS_SetParent($id, $_IPS['SELF']); IPS_SetParent($id, $this->InstanceID);
IPS_SetIdent($id, $ident); IPS_SetIdent($id, $ident);
} }
// ensure the specified server instance is actually compatible if (!IPS_IsInstanceCompatible($id, $server_id)) {
if(!IPS_IsInstanceCompatible($id, $server_id)) { IPS_SemaphoreLeave($ident);
return false; return false;
} }
// ensure that the temporary device is actually connected to the correct server instance
$inst_config = IPS_GetInstance($id); $inst_config = IPS_GetInstance($id);
if($inst_config["ConnectionID"] != $server_id) { if ((int)$inst_config['ConnectionID'] !== (int)$server_id) {
IPS_DisconnectInstance($id); IPS_DisconnectInstance($id);
if(!@IPS_ConnectInstance($id, $server_id)) { if (!@IPS_ConnectInstance($id, $server_id)) {
IPS_SemaphoreLeave($ident);
return false; return false;
} }
} }
// name object to help with debugging IPS_SetName($id, 'Temporary MQTT Device for: ' . $topic);
IPS_SetName($id, "Temporary MQTT Device for: " . $topic);
// configure temporary device $config_arr = [
$config_arr = array( 'Retain' => $retain,
"Retain" => $retain, 'Topic' => $topic,
"Topic" => $topic, 'Type' => $ips_var_type
"Type" => $ips_var_type ];
);
$config_str = json_encode($config_arr); IPS_SetConfiguration($id, json_encode($config_arr));
IPS_SetConfiguration($id, $config_str); IPS_SetHidden($id, true);
IPS_SetHidden($id,true);
IPS_ApplyChanges($id); IPS_ApplyChanges($id);
// get Value variable and use it to publish the payload $var_id = @IPS_GetObjectIDByIdent('Value', $id);
$var_id = @IPS_GetObjectIDByIdent("Value", $id); if ($var_id === false) {
RequestAction($var_id, $payload); IPS_SemaphoreLeave($ident);
return false;
}
RequestAction($var_id, $payload);
} finally {
IPS_SemaphoreLeave($ident); IPS_SemaphoreLeave($ident);
} else { // semaphore timeout
return false;
} }
return true; return true;
} // MQTT_Publish }
} }
?> ?>
+1 -1
View File
@@ -8,6 +8,6 @@
"date": 1491343200 "date": 1491343200
}, },
"version": "1.1", "version": "1.1",
"build": 4, "build": 5,
"date": 0 "date": 0
} }