Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Zigbee2MQTTHelper.php #194

Merged
merged 6 commits into from
Jul 14, 2024
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
2 changes: 2 additions & 0 deletions Device/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@
"Detection Distance Min": "Erkennungsbereich Min",
"Detection Distance Max": "Erkennungsbereich Max",
"Detection Interval": "Erkennungsintervall",
"Device Fault": "Gerät Defekt",
"Device Temperature": "Geräte Temperatur",
"Dial Rotate Left Fast": "Rad schnell links gedreht",
"Dial Rotate Left Slow": "Rad langsam links gedreht",
Expand Down Expand Up @@ -711,6 +712,7 @@
"Small Detection Sensitivity": "Bewegungserkennungsempfindlichkeit klein",
"Smitten": "Verliebt",
"Smoke Alarm State": "Rauchalarmstatus",
"Smoke Concentration": "Rauch Konzentration",
"Smoke Density db/m": "Rauchdichte in db/m",
"Smoke Density": "Rauchdichte",
"Smoke": "Rauch",
Expand Down
84 changes: 38 additions & 46 deletions libs/Zigbee2MQTTHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public function RequestAction($Ident, $Value)
$Payload['displayed_temperature'] = strval($Value);
break;
case 'Z2M_RemoteTemperature':
$Payload['remote_temperature'] = strval($Value);
$Payload['remote_temperature'] = $Value;
break;
case 'Z2M_TemperatureUnit':
$Payload['temperature_unit'] = strval($Value);
Expand Down Expand Up @@ -871,6 +871,12 @@ public function ReceiveData($JSONString)
$this->RegisterVariableInteger('Z2M_LastSeen', $this->Translate('Last Seen'), '~UnixTimestamp');
$this->SetValue('Z2M_LastSeen', ($Payload['last_seen'] / 1000));
}
if (array_key_exists('device_fault', $Payload)) {
$this->handleStateChange('device_fault', 'Z2M_DeviceFault', 'Device Fault', $Payload);
}
if (array_key_exists('smoke_concentration', $Payload)) {
$this->SetValue('Z2M_SmokeConcentration', $Payload['smoke_concentration']);
}
if (array_key_exists('charging_protection', $Payload)) {
$this->handleStateChange('charging_protection', 'Z2M_ChargingProtection', 'Charging Protection', $Payload);
}
Expand Down Expand Up @@ -1135,28 +1141,13 @@ public function ReceiveData($JSONString)
$this->SetValue('Z2M_CycleIrrigationNumTimes', $Payload['cycle_irrigation_num_times']);
}
if (array_key_exists('irrigation_start_time', $Payload)) {
try {
$startTime = $this->convertToUnixTimestamp($Payload['irrigation_start_time']);
$this->SetValue('Z2M_IrrigationStartTime', $startTime);
} catch (Exception $e) {
echo $e->getMessage();
}
$this->SetValue('Z2M_IrrigationStartTime', $Payload['irrigation_start_time']);
}
if (array_key_exists('irrigation_end_time', $Payload)) {
try {
$endTime = $this->convertToUnixTimestamp($Payload['irrigation_end_time']);
$this->SetValue('Z2M_IrrigationEndTime', $endTime);
} catch (Exception $e) {
echo $e->getMessage();
}
$this->SetValue('Z2M_IrrigationEndTime', $Payload['irrigation_end_time']);
}
if (array_key_exists('last_irrigation_duration', $Payload)) {
try {
$duration = $this->convertToUnixTimestamp($Payload['last_irrigation_duration']);
$this->SetValue('Z2M_LastIrrigationDuration', $duration);
} catch (Exception $e) {
echo $e->getMessage();
}
$this->SetValue('Z2M_LastIrrigationDuration', $Payload['last_irrigation_duration']);
}
if (array_key_exists('water_consumed', $Payload)) {
$this->SetValue('Z2M_WaterConsumed', $Payload['water_consumed']);
Expand Down Expand Up @@ -2227,6 +2218,10 @@ public function ReceiveData($JSONString)

public function convertToUnixTimestamp($timeString)
{
if ($timeString === '--:--:--') {
$this->SendDebug(__FUNCTION__, 'Invalid time string received, setting Unix timestamp to 0', 0);
return 0;
}
$this->SendDebug(__FUNCTION__, 'Input time string: ' . $timeString, 0);
$currentDate = date('d.m.Y');
$this->SendDebug(__FUNCTION__, 'Current date: ' . $currentDate, 0);
Expand Down Expand Up @@ -4239,6 +4234,11 @@ private function registerVariableProfile($expose)
break;
case 'numeric':
switch ($expose['property']) {
case 'smoke_concentration':
if (!IPS_VariableProfileExists($ProfileName)) {
$this->RegisterProfileInteger($ProfileName, 'Information', '', ' ppm', 0, 0, 1, 0);
}
break;
case 'tds':
if (!IPS_VariableProfileExists($ProfileName)) {
$this->RegisterProfileFloat($ProfileName, 'Information', '', ' ' . $expose['unit'], 0, 0, 0, 2);
Expand Down Expand Up @@ -4392,13 +4392,6 @@ private function registerVariableProfile($expose)
$this->RegisterProfileInteger($ProfileName, 'Clock', '', ' ', $expose['value_min'], $expose['value_max'], 1, 0);
}
break;
case 'irrigation_end_time':
case 'last_irrigation_duration':
case 'irrigation_start_time':
if (!IPS_VariableProfileExists($ProfileName)) {
$this->RegisterProfileInteger($ProfileName, 'Clock', '', ' ', ' ', 0, 0, 2);
}
break;
case 'water_consumed':
if (!IPS_VariableProfileExists($ProfileName)) {
$this->RegisterProfileFloat($ProfileName, 'Drops', '', ' L', ' ', 0, 0, 2);
Expand Down Expand Up @@ -4747,7 +4740,6 @@ private function registerVariableProfile($expose)
case 'calibration_time':
case 'calibration_time_left':
case 'calibration_time_right':
$ProfileName .= '_' . $expose['unit'];
if (!IPS_VariableProfileExists($ProfileName)) {
$this->RegisterProfileFloat($ProfileName, 'Clock', '', ' ' . $expose['unit'], 0, 0, 0, 2);
}
Expand All @@ -4760,7 +4752,6 @@ private function registerVariableProfile($expose)
}
break;
case 'target_distance':
$ProfileName .= '_' . $expose['unit'];
if (!IPS_VariableProfileExists($ProfileName)) {
$this->RegisterProfileFloat($ProfileName, 'Move', '', ' ' . $expose['unit'], 0, 0, 0, 2);
}
Expand Down Expand Up @@ -5346,6 +5337,9 @@ private function mapExposesToVariables(array $exposes)
break; //Lock break
case 'binary':
switch ($expose['property']) {
case 'device_fault':
$this->RegisterVariableBoolean('Z2M_DeviceFault', $this->Translate('Device Fault'), '~Switch');
break;
case 'charging_protection':
$this->RegisterVariableBoolean('Z2M_ChargingProtection', $this->Translate('Charging Protection'), '~Switch');
$this->EnableAction('Z2M_ChargingProtection');
Expand Down Expand Up @@ -6207,6 +6201,12 @@ private function mapExposesToVariables(array $exposes)
break; //enum break
case 'numeric':
switch ($expose['property']) {
case 'smoke_concentration':
$ProfileName = $this->registerVariableProfile($expose);
if ($ProfileName != false) {
$this->RegisterVariableInteger('Z2M_SmokeConcentration', $this->Translate('Smoke Concentration'), $ProfileName);
}
break;
case 'charging_limit':
$ProfileName = $this->registerVariableProfile($expose);
if ($ProfileName != false) {
Expand Down Expand Up @@ -6556,24 +6556,6 @@ private function mapExposesToVariables(array $exposes)
$this->EnableAction('Z2M_CycleIrrigationNumTimes');
}
break;
case 'irrigation_start_time':
$ProfileName = $this->registerVariableProfile($expose);
if ($ProfileName != false) {
$this->RegisterVariableFloat('Z2M_IrrigationStartTime', $this->Translate('Irrigation Start Time'), $ProfileName);
}
break;
case 'irrigation_end_time':
$ProfileName = $this->registerVariableProfile($expose);
if ($ProfileName != false) {
$this->RegisterVariableFloat('Z2M_IrrigationEndTime', $this->Translate('Irrigation End Time'), $ProfileName);
}
break;
case 'last_irrigation_duration':
$ProfileName = $this->registerVariableProfile($expose);
if ($ProfileName != false) {
$this->RegisterVariableFloat('Z2M_LastIrrigationDuration', $this->Translate('Last Irrigation Duration'), $ProfileName);
}
break;
case 'water_consumed':
$ProfileName = $this->registerVariableProfile($expose);
if ($ProfileName != false) {
Expand Down Expand Up @@ -7358,6 +7340,16 @@ private function mapExposesToVariables(array $exposes)
$this->EnableAction('Z2M_BrightnessWhite');
}
break;
// Sonderfälle: numeric im Payload, string wird gesetzt
case 'irrigation_start_time':
$this->RegisterVariableString('Z2M_IrrigationStartTime', $this->Translate('Irrigation Start Time'), '');
break;
case 'irrigation_end_time':
$this->RegisterVariableString('Z2M_IrrigationEndTime', $this->Translate('Irrigation End Time'), '');
break;
case 'last_irrigation_duration':
$this->RegisterVariableString('Z2M_LastIrrigationDuration', $this->Translate('Last Irrigation Duration'), '');
break;
default:
$missedVariables['numeric'][] = $expose;
break;
Expand Down