Because I got it work now, here my example (maybe it helps others).
- installed mosquitto on ubuntu out of the box (no additonal configuration yet)
- installes mqtt binding in openhab (only the binding, no actions)
- Hint for checking: iOS App MQTTAnalyzer was very helpful for me to control Shelly sends correctly and to find the structure my shelly uses in MQTT. Looks like they changed a lot.
.things:
Bridge mqtt:broker:mosquitto "_Mosquitto MQTT Broker" [
host="xx.xx.xx.xx (Enter yout IP here)",
// secure=false,
port=1883,
clientID="OpenHAB"
// username="user MQTT",
// password="PASSWORD MQTT"
]
// Thing fĂŒr Device-Status fehlt noch (TODO)
Thing mqtt:topic:mosquitto:EG_Shelly4Pro_R1 "_EG-Flur Shelly: Relais 1 - Solar" (mqtt:broker:mosquitto) {
Channels:
// Relais-Status
Type switch : Switch0 "_Relais 1: Schalter" [
commandTopic="EG_Flur_Shelly4Pro/events/rpc",
formatBeforePublish="'{\"src\":\"MQTT\",\"method\":\"Switch.Set\", \"params\":{\"id\":0,\"on\":%s}}'",
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.output",
on="true",
off="false"
]
// Apower? Watt lt. Beschreibung
Type number : Watt0 "_Relais 1: Watt aktuell" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.apower"
]
// Voltage
Type number : Voltage0 "_Relais 1: Volt" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.voltage"
]
// current? Ampere
Type number : Ampere0 "_Relais 1: Ampere" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.current"
]
// pf? Power Faktor? Last measured power factor lt. Shelly
Type number : PF0 "_Relais 1: PowerFaktor??? ist was?" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.pf"
]
// aenergy (eigenes Array)
// ... total (kwh Verbrauch in Wh Watt Stunden?)
Type number : Usage0 "_Relais 1: kwh Total" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.aenergy.total"
]
// ... byminute (letzten 3 Minuten?
Type number : Usage0_Minute0 "_Relais 1: kwh current Minute" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.aenergy.by_minute[0]"
]
Type number : Usage0_Minute1 "_Relais 1: kwh last Minute" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.aenergy.by_minute[1]"
]
Type number : Usage0_Minute2 "_Relais 1: kwh prelast Minute" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.aenergy.by_minute[2]"
]
// ... minute_ts?
Type number : Usage0_Minute0_Timestamp "_Relais 1: kwh Minute Timestamp" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.aenergy.minute_ts"
]
// ... Transformed in DateTime
Type datetime : Usage0_Minute0_DateTime "_Relais 1: kwh Minute DateTime" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JS:MQTT_ts_to_datetime.js"
]
// ... temperature (array)
// ...tC (Celcius)
Type number : Temperature0C "_Relais 1: Temperatur in °C" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.temperature.tC"
]
// ...tF (Fahrenheit)
Type number : Temperature0F "_Relais 1: Temperatur in °F" [
stateTopic="EG_Flur_Shelly4Pro/status/switch:0",
transformationPattern="JSONPATH:$.temperature.tF"
]
}
.items
Switch Shelly_Test_Switch "_Test Shelly" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Switch0" }
Number Shelly_Test_Watt "_Test Shelly W" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Watt0" }
Number Shelly_Test_Volt "_Test Shelly V" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Voltage0" }
Number Shelly_Test_Ampere "_Test Shelly A" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Ampere0" }
Number Shelly_Test_PF "_Test Shelly Power Faktor?" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:PF0" }
Number Shelly_Test_kwh "_Test Shelly kwh? Wh?" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Usage0" }
Number Shelly_Test_kwh_M0 "_Test Shelly kwh? Wh? aktuelle Minute" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Usage0_Minute0" }
Number Shelly_Test_kwh_M1 "_Test Shelly kwh? Wh? letzte Minute" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Usage0_Minute1" }
Number Shelly_Test_kwh_M2 "_Test Shelly kwh? Wh? vorletzte Minute" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Usage0_Minute2" }
Number Shelly_Test_kwh_M0_TS "_Test Shelly kwh? Wh? Timestamp" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Usage0_Minute0_Timestamp" }
DateTime Shelly_Test_kwh_M0_DT "_Test Shelly kwh? Wh? DateTime" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Usage0_Minute0_DateTime" }
Number Shelly_Test_Temperature "_Test Shelly [%.1f °C]" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Temperature0C" }
Number Shelly_Test_TemperatureF "_Test Shelly [%.1f °F]" (gAll, gHistoryCh) { channel="mqtt:topic:mosquitto:EG_Shelly4Pro_R1:Temperature0F" }
MQTT_ts_to_datetime.js (directory /etc/openhab/transform)
(function(i){
var parsed = JSON.parse(i);
var ts = new Date(parsed.aenergy.minute_ts * 1000);
return (ts.toISOString());
})(input)```