hi,
da es ein paar private Anfragen zu meiner mqtt hack loesung gegeben hat, hier einfach oeffentlich.
Ich verwende mqttwarn https://github.com/jpmens/mqttwarn um gewisse topics per JSON RPC nach symcon zu pushen. Im Detail hierzu ein auszug aus der mqttwarn.ini:
[config:http]
timeout = 60
targets = {
#method #URL # query params or None # list auth
'get1' : [ "get", "http://example.org?", { 'q': '{name}', 'isod' : '{_dtiso}', 'xx': 'yy' }, ('username', 'password') ],
'post1' : [ "post", "http://example.net", { 'q': '{name}', 'isod' : '{_dtiso}', 'xx': 'yy' }, None ],
'postIPS' : [ "post", "http://10.0.0.11:82/api/", None, ('username', 'passwd') ]
}
...
[40/7/1]
targets = http:postIPS
template = ipsrpc.json
...
und im templates folder dann das entsprechende ninja json template:
{% set data = {
'method': "SetValue",
'params': [25963, topic +";"+ payload],
'jsonrpc': "2.0",
'id': '0'
}
%}
{{ data | jsonify }}
25963 ist eine string variable in symcon, die dann topic;payload/message per json geschrieben bekommt. Auf der Variable haengt per update event ein PHP script, dass die Werte dann in die jeweiligen richtigen symcon variablen schreibt:
<?
// mqtt topic to symcon variable id mapping
$idmap = [
"13/7/2" => 18846,
"13/7/5" => 10300,
"15/7/2" => 32631,
// ....
"40/7/1" => 21172,
];
// get value from mqtt variable
$var = GetValue(25963 /*[Sensor\Arduino\mqttString]*/);
$varsplit = explode(";", $var);
if(count($varsplit)>1)
{
$topic=$varsplit[0];
$payload=$varsplit[1];
$id=getIDforTopic($topic);
if($id > -1)
mqset($id, $payload);
}
function mqset($id, $value)
{
$obj=IPS_GetVariable($id);
switch($obj["VariableType"])
{
case 0: // boolean
$val = filter_var($value, FILTER_VALIDATE_BOOLEAN);
SetValue($id, $val);
break;
case 1: // integer
$val = intval($value);
SetValue($id, $val);
break;
case 2: // float
$val = floatval($value);
SetValue($id, $val);
break;
case 3: // string
SetValue($id, $value);
break;
}
}
function getIDforTopic($strTopic)
{
global $idmap;
$return = -1;
if (array_key_exists($strTopic, $idmap))
$return = $idmap[$strTopic];
return $return;
}
?>
wie schon frueher gesagt, eigentlich ein schlimmer hack, aber funktioniert nun schon seit vielen Monaten mit ca. 10-15 variablen aus mqttstabil. ich verwende es hauptsaechlich fuer die selbst gebastelten wireless arduino/nodemcu sensoren die ihre werte automatisch direkt oder indirekt auf mqtt publishen, und von dort dann eben weiter nach symcon.
Wie viele andere auch wuerde ich mir natuerlich eine direkte Integration von mqtt in symcon wuenschen, aber so funktioniert es derzeit zumindest.