Also, grundsätzlich gibt es zwei Möglichkeiten, mit der AWtrix zu kommunizieren.
Beide Varianten verwenden mqtt
1. Natives Generic mqtt Thing:
Code: Alles auswählen
Thing topic awtrix01 "AwTrix Schreibtisch" @ "mqtt" [
availabilityTopic="awtrix3_1/stats/device",
payloadNotAvailable="offline",
payloadAvailable= "online"
]{
Type string : settings "Settings" [ commandTopic="awtrix3_1/settings" ]
Type string : notify "Notify" [ commandTopic="awtrix3_1/notify" ]
Type string : dismiss "Dismiss" [ commandTopic="awtrix3_1/notify/dismiss" ]
Type string : appsel "Select app" [ commandTopic="awtrix3_1/switch" ]
Type string : timer "Timer" [ commandTopic="awtrix3_1/timer" ]
Type string : car "Custom car" [ commandTopic="awtrix3_1/custom/car",retained="true" ]
Type string : strom "Custom strom" [ commandTopic="awtrix3_1/custom/strom" ]
Type string : stats "Stats" [ stateTopic="awtrix3_1/stats" ]
Type switch : power "Anzeige" [ commandTopic="awtrix3_1/power",on="true",off="false",formatBeforePublish="{'power':%2s}"]
Type trigger : btnLeft "Taste links" [ stateTopic="awtrix3_1/stats/buttonLeft" ]
Type trigger : btnRight "Taste rechts" [ stateTopic="awtrix3_1/stats/buttonRight" ]
Type trigger : btnSelect "Taste mitte" [ stateTopic="awtrix3_1/stats/buttonSelect" ]
Type color : ind1 "oben" [ commandTopic="awtrix3_1/indicator1",formatBeforePublish="{\"color\":[%1$d,%2$d,%3$d]}",colorMode="RGB" ]
Type color : ind2 "mitte" [ commandTopic="awtrix3_1/indicator2",formatBeforePublish="{\"color\":[%1$d,%2$d,%3$d]}",colorMode="RGB" ]
Type color : ind3 "unten" [ commandTopic="awtrix3_1/indicator3",formatBeforePublish="{\"color\":[%1$d,%2$d,%3$d]}",colorMode="RGB" ]
}
Die verschiedenen Channel werden zum steuern der Uhr in genau definierten Funktionen verwendet. Die drei trigger Channel können verwendet werden, um auf einen Knopfdruck zu reagieren.
Die drei color Channel ind1 bis ind3 können verwendet werden, um die drei Index-Anzeigen (rechts oben, rechte Seite, rechts unten) mit einer beliebigen Farbe zu setzen.
Power kann verwendet werden, um die Anzeige aus- und einzuschalten (die Uhr läuft dabei weiter, die Hardware kann nicht über Software geschaltet werden)
stats liefert den aktuellen Zustand als JSON
timer kann einen Timer setzen, appsel kann die Anzeige auf eine bestimmte App wechseln, notify kann eine Notification einblenden (mit Vorrang), dismiss kann die Notification wegbestätigen, settings dient dem Setzen von Einstellungen und die beiden übrigen Channel car und strom sind "Custom Apps"
Dazu gibt es logischerweise Items:
Code: Alles auswählen
String AwTrixSchreibtischSettings "Settings" (gAwTrix) ["Control"] {channel="mqtt:topic:mymqtt:awtrix01:settings"}
String AwTrixSchreibtischNotify "Notify" (gAwTrix) ["Control"] {channel="mqtt:topic:mymqtt:awtrix01:notify"}
String AwTrixSchreibtischDismiss "Notify" (gAwTrix) ["Control"] {channel="mqtt:topic:mymqtt:awtrix01:dismiss"}
String AwTrixSchreibtischAppsel "Select app" (gAwTrix) ["Control"] {channel="mqtt:topic:mymqtt:awtrix01:appsel"}
String AwTrixSchreibtischTimer "Timer" (gAwTrix) ["Control"] {channel="mqtt:topic:mymqtt:awtrix01:timer"}
String AwTrixSchreibtischStats "Stats" (gAwTrix) ["Status"] {channel="mqtt:topic:mymqtt:awtrix01:stats"}
String AwTrixSchreibtischCar "Custom car" (gAwTrix) ["Status"] {channel="mqtt:topic:mymqtt:awtrix01:car"}
String AwTrixSchreibtischStrom "Custom Strom" (gAwTrix) ["Status"] {channel="mqtt:topic:mymqtt:awtrix01:strom"}
Switch AwTrixSchreibtischPower "Anzeige" (gAwTrix) ["Switch"] {channel="mqtt:topic:mymqtt:awtrix01:power"}
Color AwTrixSchreibtischInd1 "Oben" (gAwTrix) ["Status"] {channel="mqtt:topic:mymqtt:awtrix01:ind1"}
Color AwTrixSchreibtischInd2 "Mitte" (gAwTrix) ["Status"] {channel="mqtt:topic:mymqtt:awtrix01:ind2"}
Color AwTrixSchreibtischInd3 "Unten" (gAwTrix) ["Status"] {channel="mqtt:topic:mymqtt:awtrix01:ind3"}
Und ein paar Rules:
Code: Alles auswählen
rule "Awtrix ein" // morgens um 6 Uhr Anzeige einschalten
when
Time cron "0 0 6 * * ?"
then
logInfo("awtrix","Anzeige ein")
AwTrixSchreibtischPower.sendCommand(ON)
end
rule "Awtrix aus"
when
Time cron "0 0 2 * * ?" // Um 2 Uhr Anzeige ausschalten
then
logInfo("awtrix","Anzeige aus")
AwTrixSchreibtischPower.sendCommand(OFF)
end
rule "Grid Power changed" // Bezug/Lieferung geändert -> Stromapp aktualisieren
when
Item PVPowerflowchannelpgrid changed
then
if(!(newState instanceof Number))
return;
var Number nPFlow = (newState as Number).floatValue / 1000
var strColor = "#FF0000"
var strIcon = "52715" // Icon für Bezug
if(nPFlow < 0) {
strColor = "#00FF00"
nPFlow = - nPFlow
strIcon = "52648" // Icon für Lieferung
}
val strZahl = String.format("%.1f",nPFlow).replace(',','.')
var json='{"pos" : 3,"text" : "' + strZahl + 'kW","icon" : ' + strIcon + ',"duration" : 9,"color" : "' + strColor + '"}'
AwTrixSchreibtischStrom.sendCommand(json)
end
rule "ID.3 Batterie SOC"
when
Item VWDomChargeSOC changed or
Item VWDomChargeStatState changed or
Item VWParkingPosition changed
then
var strColor = "#FF0000"
var strIcon = "53423"
switch(VWDomChargeStatState.state.toString) {
case "notReadyForCharging" : strColor = "#FF7070"
case "readyForCharging" : strColor = "#60AF80"
case "charging" : {strColor = "#00FF00" strIcon="53424"}
case "chargePurposeReachedAndConservation" : strColor = "#0000FF"
case "chargePurposeReachedAndNotConservationCharging" : strColor = "#FFFFFF"
case "conservation" : strColor = "#7F7FFF"
}
val strSOC = VWDomChargeSOC.state.toString
var json='{"pos" : 2,"text" : "' + strSOC + '","icon" : ' + strIcon + ',"duration" : 9,"color" : "' + strColor + '"}'
if(bCarAway)
json = ''
AwTrixSchreibtischCar.sendCommand(json)
end
rule "Vigor Offline"
when
Item Vigor165Online changed from ON
then
var iCount = 0
if(Vigor165OfflineCount.state instanceof Number)
iCount = (Vigor165OfflineCount.state as Number).intValue
iCount += 1
Vigor165OfflineCount.postUpdate(iCount)
var json='{"text" : "OFFLINE! (' + iCount.toString + ')", "hold" : true, "color" : "#FF0000", "blinkText" : 500}'
AwTrixSchreibtischNotify.sendCommand(json)
end
rule "get last offline timestamp"
when
Item Vigor165Online changed from OFF to ON
then
logInfo("online","Wieder online!")
var dtOnline = Vigor165Online.previousState(true,"jdbc").timestamp
if(dtOnline === null) dtOnline = now
Vigor165OnlineTimestamp.postUpdate(new DateTimeType(dtOnline))
AsteriskRestartRun.sendCommand(ON)
AwTrixSchreibtischDismiss.sendCommand("")
end
Es gibt also für jede "App" eine Rule, welche das entsprechende JSON an den zugehörigen Channel schickt. Wie man oben sehen kann, ist die car-App retained, weshalb diese App von der TC001 auch automatisch beim booten vom Broker geladen wird. Im Unterschied dazu wird die Strom App nur aktiv von openHAB auf die TC001 geschrieben.
Die Anzeigen werden dann von der TC001 selbständig gewechselt, mit dem jeweiligen aktuellen Inhalt.
Meine Anzeigen sind hier auf den LAdezustand des BEV, Bezug/Lieferung Strom und Fehlerzustand Internetzugang reduziert, letztere ist mit rot blinkender Anzeige und Counter realisiert (ich hatte hier eine Zeit lang bis zu 40 Verbindungsabbrüche am Tag...)
Was die Icons betrifft, so wird der Iconname ohne Endung und ohne Verzeichnis angegeben.
Die zweite Variante läuft über das Awtirx3 Binding, welches auf mqtt aufsetzt.
Code: Alles auswählen
Thing awtrixclock awtrix01 "Awtrix Schreibtisch" [
appLockTimeout=10,
discoverDefaultApps=false,
basetopic="awtrix3_1",
lowBatteryThreshold=25
]
Die zugehörigen Items werden dann dynamisch erzeugt:
Code: Alles auswählen
Number AwtrixSchreibtischBatterylevel "Batterieladung" (gAwTrixNew) ["Status"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:batterylevel"}
Switch AwtrixSchreibtischLowBattery "Niedriger batteriestatus" (gAwTrixNew) ["Status"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:low-battery"}
Switch AwtrixSchreibtischDisplay "Betrieb" (gAwTrixNew) ["Switch"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:display"}
Number:Dimensionless AwtrixSchreibtischHumidity "Luftfeuchtigkeit" (gAwTrixNew) ["Status"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:humidity"}
Number:Illuminance AwtrixSchreibtischLux "Lux" (gAwTrixNew) ["Status"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:lux"}
Switch AwtrixSchreibtischAutoBrightness "Automatc brightness" (gAwTrixNew) ["Switch"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:autoBrightness"}
Number:Dimensionless AwtrixSchreibtischBrightness "Display brightness" (gAwTrixNew) ["Status"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:brightness"}
Number:Temperature AwtrixSchreibtischTemperature "Innentemperatur" (gAwTrixNew) ["Status"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:temperature"}
Number:Dimensionless AwtrixSchreibtischRssi "Wi fi signal" (gAwTrixNew) ["Status"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:rssi"}
String AwtrixSchreibtischApp "Active app" (gAwTrixNew) ["Status"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:app"}
//Image AwtrixSchreibtischScreen "Screen mirror" (gAwTrixNew) ["Status"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:screen"}
Switch AwtrixSchreibtischIndicator1 "Indicator" (gAwTrixNew) ["Switch"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:indicator1"}
Switch AwtrixSchreibtischIndicator2 "Indicator" (gAwTrixNew) ["Switch"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:indicator2"}
Switch AwtrixSchreibtischIndicator3 "Indicator" (gAwTrixNew) ["Switch"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:indicator3"}
String AwtrixSchreibtischSound "Play melody from melodies folder" (gAwTrixNew) ["Control"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:sound"}
String AwtrixSchreibtischRtttl "Play rtttl" (gAwTrixNew) ["Control"] {channel="mqtt:awtrixclock:mymqtt:awtrix01:rtttl"}
Und es gibt für jede existente Custom App automatisch ein entsprechendes Thing, für die dann alle möglichen Details als einzelne Items zur Verfügung stehen.
Ich habe das bei mir auch mit eingebunden, aber da ich die TC001 schon nativ mit mqtt in Betrieb hatte, habe ich mir bisher nicht die Mühe gemacht, das Interface entsprechend umzubauen. Mir ist auch nicht so ganz klar, wie ich das mit dynamisch erzeugten Things erledigen soll (Custom Apps), aber statt ein JSON zusammenzuzimmern und an die TC001 zu schicken, werden dann halt für jeden Parameter im JSON, den man verwenden möchte Items angelegt, welche den PArameter passend aufnehmen können.