Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende Überarbeitung | |||
manuals:symcon:mqtt-integration [2018/09/22 18:52] – admin | manuals:symcon:mqtt-integration [2018/09/23 19:15] (aktuell) – paulg4h | ||
---|---|---|---|
Zeile 65: | Zeile 65: | ||
mit folgendem Inhalt: | mit folgendem Inhalt: | ||
<code php><? | <code php><? | ||
- | $d = false; $msg = ""; | + | include_once(IPS_GetScript(42011 )[" |
+ | |||
+ | $d = true; $msg = ""; | ||
$value = ""; | $value = ""; | ||
- | if ($d){ $msg .= " | + | |
- | //if (($_IPS[' | + | if ($d){ |
- | if ($_IPS[' | + | $msg .= " |
- | | + | $msg .= print_r($_IPS, true); |
- | if ($value == $_IPS[' | + | |
- | $msg .= " | + | |
- | $run = false; | + | |
- | } | + | |
} | } | ||
- | if (($_IPS[' | + | |
- | $value = $_IPS[' | + | if ($_IPS[' |
+ | //On Manual Execute check child events and set Event Trigger to "On Change" | ||
+ | foreach (IPS_GetChildrenIDs($_IPS[' | ||
+ | if (IPS_GetObject($value)[' | ||
+ | IPS_SetEventTrigger($value, | ||
+ | } | ||
+ | } | ||
+ | } else { | ||
+ | if (($_IPS[' | ||
+ | if ($_IPS[' | ||
+ | //$value = (GetValueBoolean($_IPS[' | ||
+ | $value = ($_IPS[' | ||
+ | } | ||
+ | if (($_IPS[' | ||
+ | $value = ($_IPS[' | ||
+ | } | ||
+ | |||
+ | if (($value == (GetValueBoolean($_IPS[' | ||
+ | if($d){ $msg .= " | ||
+ | $run = false; | ||
+ | } | ||
+ | |||
+ | if ($d){ | ||
+ | $msg .= " | ||
+ | } | ||
+ | |||
+ | $topic = explode(";", | ||
+ | |||
+ | if((strlen($topic) > 3) and ($run)){ | ||
+ | if ($d){ | ||
+ | $msg .= " | ||
+ | $msg .= " | ||
+ | $msg .= " | ||
+ | $msg .= " | ||
+ | } | ||
+ | MQTT_Publish($idMQTTBroker , $topic ,$value ,1 , true); | ||
+ | } | ||
+ | } | ||
} | } | ||
- | if ($d){ $msg .= " | ||
- | $id = $_IPS[' | ||
- | $topic = explode(";", | ||
- | if((strlen($topic) > 3) and ($run)){ | ||
- | switch(IPS_GetVariable($id)[' | ||
- | case 0: //boolean | ||
- | if($value == 1){ $value = " | ||
- | break; | ||
- | case 1: //Integer | ||
- | |||
- | | ||
- | case 2: //float | ||
- | |||
- | | ||
- | case 3: //string | ||
- | |||
- | | ||
- | } | ||
- | if($d){ $msg .= " | ||
- | MQTT_Publish(50729 / | ||
- | } | ||
- | |||
- | if ($d){ $msg .= " | ||
- | |||
| | ||
| | ||
} | } | ||
- | ?> | + | ?></ |
- | </ | + | |
Zeile 118: | Zeile 128: | ||
// mqtt topic to symcon variable id mapping | // mqtt topic to symcon variable id mapping | ||
$idParent = IPS_GetParent($_IPS[' | $idParent = IPS_GetParent($_IPS[' | ||
- | $archiveId = 32289 / | + | $archiveId = 32289; |
- | $relaisScriptId = 17676 / | + | $relaisScriptId = 17676; //Relais Script ID |
// get value from mqtt variable | // get value from mqtt variable | ||
if( array_key_exists(" | if( array_key_exists(" | ||
- | + | $topic = $_IPS[' | |
- | $topic = $_IPS[' | + | |
- | $topics = explode("/", | + | |
- | $payload = $_IPS[' | + | |
- | + | | |
- | $payload = str_replace(array(" | + | |
- | + | if ($d){ $msg .= " | |
- | if ($d){ $msg .= " | + | |
- | + | // Datentyp der payload herausfinden und ins Format für IPS Übersetzen | |
- | // Datentyp der payload herausfinden und ins Format für IPS Übersetzen | + | |
- | $contType = 99; | + | if (is_float($payload+0)){ |
- | if (is_float($payload+0)){ | + | |
- | //Float | + | |
- | $contType = 2; | + | } |
- | } | + | if (($contType == 99) and (is_numeric($payload))){ |
- | if (($contType == 99) and (is_numeric($payload))){ | + | |
- | //Integer | + | |
- | $contType = 1; | + | } |
- | } | + | if (($contType == 99) and (is_string($payload))){ |
- | if (($contType == 99) and (is_string($payload))){ | + | if ((strtolower($payload) == " |
- | if ((strtolower($payload) == " | + | //Boolean |
- | //Boolean | + | $contType = 0; |
- | $contType = 0; | + | } else { |
- | } else { | + | //String |
- | //String | + | $contType = 3; |
- | $contType = 3; | + | } |
- | } | + | } |
- | } | + | $idf = $idParent; |
- | $idf = $idParent; | + | // |
- | //Pfad durchlaufen und Prüfen ob die Kategorien / Variablen vorhanden sind und bei bedarf Anlegen | + | |
- | for($i = 0; $i < count($topics); | + | if ($i == (count($topics) -1)){ |
- | if ($i == (count($topics) -1)){ | + | $type = 2; |
- | $type = 2; | + | } else { |
- | } else { | + | $type = 0; |
- | $type = 0; | + | } |
- | } | + | $idf = checkIfElementExists($idf, |
- | $idf = checkIfElementExists($idf, | + | } |
- | } | + | |
- | + | | |
- | if($d){ | + | |
- | $msg .= " | + | |
- | $msg .= "Set Itend to: " | + | } |
- | } | + | |
- | + | | |
- | IPS_SetIdent($idf, | + | |
- | + | //mqset($idf, $payload); | |
- | mqset($idf, | + | |
} | } | ||
if ((strlen($msg) > 0) and ($d)){ | if ((strlen($msg) > 0) and ($d)){ | ||
Zeile 185: | Zeile 195: | ||
function mqset($id, $value){ | function mqset($id, $value){ | ||
+ | Global $msg, $d; | ||
if(GetValue($id) != $value){ | if(GetValue($id) != $value){ | ||
switch(IPS_GetVariable($id)[" | switch(IPS_GetVariable($id)[" | ||
case 0: // boolean | case 0: // boolean | ||
- | $val = filter_var($value, | + | $val = filter_var($value, |
+ | if($d){ $msg .= "val: " | ||
SetValue($id, | SetValue($id, | ||
break; | break; | ||
Zeile 232: | Zeile 244: | ||
} | } | ||
IPS_SetName($id, | IPS_SetName($id, | ||
- | IPS_SetParent($id, | + | |
- | if($type == 2){ // Variable | + | if($type == 2){ // Variable |
- | | + | |
- | if (strpos(" | + | if (strpos(" |
- | | + | |
- | | + | |
- | | + | |
- | } elseif(strpos(" | + | } elseif(strpos(" |
- | IPS_SetVariableCustomProfile($id, | + | |
- | } elseif ($name == " | + | } elseif ($name == " |
- | IPS_SetVariableCustomProfile($id, | + | |
- | } else { | + | } else { |
- | //Wenn es eine Boolean Variable ist das Profile ~Switch zuweisen | + | |
- | IPS_SetVariableCustomProfile($id, | + | |
- | IPS_SetVariableCustomAction($id, | + | |
- | checkCreateEvent($id, | + | |
- | } | + | } |
- | } | + | |
- | if (strpos(" | + | |
- | | + | IPS_SetVariableCustomProfile($id, |
- | } | + | |
- | if (strpos(" | + | |
- | | + | IPS_SetVariableCustomProfile($id, |
- | } | + | |
- | if (strpos(" | + | |
- | | + | IPS_SetVariableCustomProfile($id, |
- | } | + | |
IPS_SetInfo($id, | IPS_SetInfo($id, | ||
// | // | ||
- | | + | AC_SetLoggingStatus($archiveId, |
- | IPS_ApplyChanges($archiveId); | + | |
} | } | ||
} | } | ||
Zeile 287: | Zeile 299: | ||
} | } | ||
if ($create){ | if ($create){ | ||
- | //Event Anlegen | + | |
- | $eid = IPS_CreateEvent(0); | + | $eid = IPS_CreateEvent(0); |
- | IPS_SetEventTrigger($eid, | + | IPS_SetEventTrigger($eid, |
- | IPS_SetParent($eid, | + | IPS_SetParent($eid, |
IPS_SetEventActive($eid, | IPS_SetEventActive($eid, | ||
} | } | ||
} | } | ||
?></ | ?></ | ||
- | ==== Mosquitto (MQTT Broker) ==== | + | |
+ | ==== MQTT Broker | ||
aptitude install mosquitto mosquitto-clients python-pip git -y | aptitude install mosquitto mosquitto-clients python-pip git -y | ||
| |