Skip to content

Commit

Permalink
Merge pull request #27 from demel42/master
Browse files Browse the repository at this point in the history
Handling von "State100" / "Switch"
  • Loading branch information
Schnittcher authored Aug 21, 2024
2 parents d6d93c5 + 230637a commit ca17ed3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ShellyPro3EM/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,4 @@
]
}
]
}
}
4 changes: 2 additions & 2 deletions ShellyPro3EM/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"Total active Energy Offset": "Offset Wirkenergie (Gesamt)",
"Total active returned Energy Offset": "Offset für exportierte Energie (Gesamt)",
"Zeroing by unreach": "Nullung durch Unerreichbarkeit",
"State 100": "Status 100"
"Switching output": "Schaltausgang"
}
}
}
}
39 changes: 35 additions & 4 deletions ShellyPro3EM/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ class ShellyPro3EM extends ShellyModule
['cTotalActRetEnergy', 'Phase C total active returned Energy', VARIABLETYPE_FLOAT, '~Electricity', [], '', false, true, false],
['totalActEnergy', 'Total active Energy', VARIABLETYPE_FLOAT, '~Electricity', [], '', false, true, false],
['totalActRetEnergy', 'Total active returned Energy', VARIABLETYPE_FLOAT, '~Electricity', [], '', false, true, false],

//Pro 3EM Switch Addon
['State100', 'State 100', VARIABLETYPE_BOOLEAN, '~Switch', [], '', false, true, false],
['Switch', 'Switching output', VARIABLETYPE_BOOLEAN, '~Switch', [], '', true, true, false],
['Reachable', 'Reachable', VARIABLETYPE_BOOLEAN, 'Shelly.Reachable', '', '', false, true, false]
];

Expand All @@ -60,6 +61,37 @@ public function ApplyChanges()
$this->MaintainVariable('Returned', $this->Translate('Returned'), 2, '~Electricity', 0, $this->ReadPropertyBoolean('Netting'));
}

public function RequestAction($Ident, $Value)
{
$this->SendDebug(__FUNCTION__, 'ident=' . $Ident . ', value=' . $Value, 0);
switch ($Ident) {
case 'Switch':
$this->SetSwitch($Value);
break;
default:
$this->SendDebug(__FUNCTION__, 'invalid ident "', $Ident . '"', 0);
break;
}
}

private function SetSwitch(bool $Value)
{
$Topic = $this->ReadPropertyString('MQTTTopic') . '/rpc';

$Payload = [
'id' => 1,
'src' => 'user_1',
'method' => 'Switch.Set',
'params' => [
'id' => 100,
'on' => $Value,
],
];

$this->SendDebug(__FUNCTION__, 'topic=' . $Topic . ', payload='.print_r($Payload,true), 0);
$this->sendMQTT($Topic, json_encode($Payload));
}

public function ReceiveData($JSONString)
{
if (!empty($this->ReadPropertyString('MQTTTopic'))) {
Expand All @@ -84,10 +116,9 @@ public function ReceiveData($JSONString)
if (array_key_exists('switch:100', $Payload['params'])) {
$switch = $Payload['params']['switch:100'];
if (array_key_exists('output', $switch)) {
$this->SetValue('State100' . $i, $switch['output']);
$this->SetValue('Switch', (bool) $switch['output']);
}
}

if (array_key_exists('em:0', $Payload['params'])) {
$em = $Payload['params']['em:0'];
$this->SetValue('aCurrent', $em['a_current']);
Expand Down Expand Up @@ -165,4 +196,4 @@ private function Netting()
SetValue($this->GetIDForIdent('CurrentReturned'), 0);
}
}
}
}
2 changes: 1 addition & 1 deletion libs/ShellyModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function ApplyChanges()
'Action' => $NewVariable[6],
'Pos' => ++$NewPos,
'Keep' => $NewVariable[7],
'Zeroing' => $NewVariable[7]
'Zeroing' => $NewVariable[8]
];
}
IPS_SetProperty($this->InstanceID, 'Variables', json_encode($Variables));
Expand Down

0 comments on commit ca17ed3

Please sign in to comment.