Hallo,
ich habe in einer Regentonne einen Wemos D1 mini mit Ultraschalsensor verbaut. Dieser sendet alle 2 Minuten auf meinen MQTT Broker seinen Abstandswert. Dieser kommt wiederum im openhab sauber an.
Nun möchte ich (für eine bessere Visualisierung) diese Werte in % (bzw weiterhin als Number, es reicht in der Anzeige des Items das %).
Somit habe ich mir eine Rule gebaut, in dieser ich die Werte umrechne.
Aber es klappt nicht. ich glaube ich habe die falschen "von bis" eingebaut, finde aber auch mithilfe von google keinen passenden Beispiele :-\
Rule:
im Prinzip entspricht der Abstand 13cm Abstand = Voll (100%) und der Abstand 76cm Abstand = leer (<10%)
folgender Fehler kommt:
wie kriege ich das zum laufen? 
DANKE!
edit: ich habe dann doch noch ein beispiel gefunden, wo mit mehrere Werten gearbeitet wurde.
Habe meinen Code aufbereitet und er funktioniert jetzt auch:
ich habe es vereinfacht, da der Abstand auch nur in vollen cm übergeben wird, habe ich die Rule nun auch nicht an die "tatsächlichen" Prozenzualen Werte angepasst, sondern gerundete ganze Zahlen genommen.
Da der Tank noch voll ist, kann ich noch nicht sagen ob es richtig funktioniert. Aber ich habe jetzt schonmal auf dem item meine 100% Füllstand
ich habe in einer Regentonne einen Wemos D1 mini mit Ultraschalsensor verbaut. Dieser sendet alle 2 Minuten auf meinen MQTT Broker seinen Abstandswert. Dieser kommt wiederum im openhab sauber an.
Nun möchte ich (für eine bessere Visualisierung) diese Werte in % (bzw weiterhin als Number, es reicht in der Anzeige des Items das %).
Somit habe ich mir eine Rule gebaut, in dieser ich die Werte umrechne.
Aber es klappt nicht. ich glaube ich habe die falschen "von bis" eingebaut, finde aber auch mithilfe von google keinen passenden Beispiele :-\
Rule:
Code:
rule "Regentonne 01 cm in Prozent umrechnen" when Item WemosD1_Abstand_Regentonne01 received update then { if (WemosD1_Abstand_Regentonne01.state <= 19.2 ) { Regentonne01_Prozent.postUpdate(100) } if (WemosD1_Abstand_Regentonne01.state >= 19.3 && <= 25.5 ) { Regentonne01_Prozent.postUpdate(90) } if (WemosD1_Abstand_Regentonne01.state >= 25.6 && <= 31.8 ) { Regentonne01_Prozent.postUpdate(80) } if (WemosD1_Abstand_Regentonne01.state >= 31.9 && <= 38.1 ) { Regentonne01_Prozent.postUpdate(70) } if (WemosD1_Abstand_Regentonne01.state >= 38.2 && <= 44.4 ) { Regentonne01_Prozent.postUpdate(60) } if (WemosD1_Abstand_Regentonne01.state >= 44.5 && <= 50.7 ) { Regentonne01_Prozent.postUpdate(50) } if (WemosD1_Abstand_Regentonne01.state >= 50.8 && <= 57.0 ) { Regentonne01_Prozent.postUpdate(40) } if (WemosD1_Abstand_Regentonne01.state >= 57.1 && <= 63.3 ) { Regentonne01_Prozent.postUpdate(30) } if (WemosD1_Abstand_Regentonne01.state >= 63.4 && <= 69.6 ) { Regentonne01_Prozent.postUpdate(20) } if (WemosD1_Abstand_Regentonne01.state >= 69.7) { Regentonne01_Prozent.postUpdate(10) } } end
Code:
[TABLE="width: 190"] [TR] [TD][SIZE=15px][COLOR=black][FONT=Calibri]Abstand in cm[/FONT][/COLOR][/SIZE][/TD] [TD][SIZE=15px][COLOR=black][FONT=Calibri]Füllstand in %[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]76[/FONT][/COLOR][/SIZE][/TD] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]0[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]69,7[/FONT][/COLOR][/SIZE][/TD] [TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]10%[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]63,4[/FONT][/COLOR][/SIZE][/TD] [TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]20%[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]57,1[/FONT][/COLOR][/SIZE][/TD] [TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]30%[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]50,8[/FONT][/COLOR][/SIZE][/TD] [TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]40%[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]44,5[/FONT][/COLOR][/SIZE][/TD] [TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]50%[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]38,2[/FONT][/COLOR][/SIZE][/TD] [TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]60%[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]31,9[/FONT][/COLOR][/SIZE][/TD] [TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]70%[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]25,6[/FONT][/COLOR][/SIZE][/TD] [TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]80%[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]19,3[/FONT][/COLOR][/SIZE][/TD] [TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]90%[/FONT][/COLOR][/SIZE][/TD] [/TR] [TR] [TD="align: right"][SIZE=15px][COLOR=black][FONT=Calibri]13[/FONT][/COLOR][/SIZE][/TD] [TD="class: xl65, align: right"][SIZE=15px][COLOR=black][FONT=Calibri]100%[/FONT][/COLOR][/SIZE][/TD] [/TR] [/TABLE]
Code:
2020-09-14 08:33:04.754 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'testrules.rules' has errors, therefore ignoring it: [32,56]: no viable alternative at input '=' [32,58]: mismatched input '25' expecting '>' [32,63]: mismatched input ')' expecting '}' [34,56]: no viable alternative at input '=' [34,58]: mismatched input '31' expecting '>' [34,63]: mismatched input ')' expecting 'end'

DANKE!
edit: ich habe dann doch noch ein beispiel gefunden, wo mit mehrere Werten gearbeitet wurde.
Habe meinen Code aufbereitet und er funktioniert jetzt auch:
Code:
rule "Regentonne 01 cm in Prozent umrechnen" when Item WemosD1_Abstand_Regentonne01 received update then { if ((WemosD1_Abstand_Regentonne01.state as Number) <19 ) { Regentonne01_Prozent.postUpdate(100) } if (((WemosD1_Abstand_Regentonne01.state as Number) >19 ) && (WemosD1_Abstand_Regentonne01.state as Number) <25 ) { Regentonne01_Prozent.postUpdate(90) } if (((WemosD1_Abstand_Regentonne01.state as Number) >25 ) && (WemosD1_Abstand_Regentonne01.state as Number) <31 ) { Regentonne01_Prozent.postUpdate(80) } if (((WemosD1_Abstand_Regentonne01.state as Number) >31 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 38 ) { Regentonne01_Prozent.postUpdate(70) } if (((WemosD1_Abstand_Regentonne01.state as Number) >38 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 44 ) { Regentonne01_Prozent.postUpdate(60) } if (((WemosD1_Abstand_Regentonne01.state as Number) >44 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 50 ) { Regentonne01_Prozent.postUpdate(50) } if (((WemosD1_Abstand_Regentonne01.state as Number) >50 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 57 ) { Regentonne01_Prozent.postUpdate(40) } if (((WemosD1_Abstand_Regentonne01.state as Number) >57 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 63 ) { Regentonne01_Prozent.postUpdate(30) } if (((WemosD1_Abstand_Regentonne01.state as Number) >63 ) && (WemosD1_Abstand_Regentonne01.state as Number) < 69 ) { Regentonne01_Prozent.postUpdate(20) } if ((WemosD1_Abstand_Regentonne01.state as Number) > 69) { Regentonne01_Prozent.postUpdate(10) } } end
Da der Tank noch voll ist, kann ich noch nicht sagen ob es richtig funktioniert. Aber ich habe jetzt schonmal auf dem item meine 100% Füllstand
Kommentar