FHEM Forum

FHEM => Anfängerfragen => Thema gestartet von: fhemer am 16 Mai 2016, 14:47:27

Titel: Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 16 Mai 2016, 14:47:27
Hallo,

bin jetzt schon echt weit und meine Zeitschaltuhren mit Zufallswert funktionieren auch! :-)
Nur beim devStateIcon bin ich etwas zu doof. Es ist immer falschherum. Also die Birne ist dunkel, wenn der Ausgang high ist und umgekehrt. Die on und off Befehle funktionieren korrekt. Hier mal mein aktueller Code (habe schon mehrere Varianten bei devStateIcon probiert):

setdefaultattr valueFn {($VALUE eq "on")?"off":"on"} #gilt für alle?!?

define i2c20pA2 readingsProxy i2c20:PortA2
attr i2c20pA2 room ops
attr i2c20pA2 devStateIcon off:off:on on:on:off  #war auch schon on:on:off off:off:on
attr i2c20pA2 alias AZ Rolladen 2 runter
attr i2c20pA2 setList on off
attr i2c20pA2 setFn {($CMD eq "on")?"PortA2 on":"PortA2 off"}
attr i2c20pA2 webCmd on:off:on-for-timer 10

(danach kommt die Zeitschaltuhr, die ja funktioniert (mit dem Symbol in falscher Logik!))

Danke schonmal

VG
fhemer

Titel: Antw:devStateIcon hat umgekehrte Logik
Beitrag von: viegener am 17 Mai 2016, 15:02:51
Du hast doch eine valueFn angegeben, die den Wert invertiert, unabhängig, dass ich das extrem verwirrend finde sorgt doch genau diese dafür das alles verdreht ist. Mit anderen Worten PortA2 ist on, dann ist in i2c20 das Reading auf on und in i2c20pA2 der state auf off  :o

Mich würde das in den Wahnsinn treiben  ::)
Titel: Antw:devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 17 Mai 2016, 22:34:48
Hallo viegener,

Danke für die Antwort. Hast recht, war wohl ein Übrigbleibsel und ich habs entfernt und entsprechend angepasst.
Jetzt geht auch alles, außer das Icon für A1. Das bleibt auf "an", in der Realität ist aber alles OK und die Lampe ist physikalisch aus! So wie es sein soll. Das Problem ist nur beim Icon für A1, bei A2 ist alles in Ordnung. Hintergrund: B0 und A0 steuern einen Rollladenmotor (hoch/runter), A1 und A2 einen anderen. Die Ausgänge sollen sich gegenseitig softwaremäßig verriegeln. Das funktioniert wie gesagt in der Realität, das Icon bei A1 bleibt aber an!

Hier mal der Code:

attr global logfile ./log/fhem-%Y-%m.log
attr global modpath .
attr global statefile ./log/fhem.save
attr global verbose 3
attr global updateInBackground
attr global latitude 50.111
attr global longitude 8.682

define telnetPort telnet 7072 global

define WEB FHEMWEB 8083 global

define WEBphone FHEMWEB 8084 global
attr WEBphone stylesheetPrefix smallscreen

define WEBtablet FHEMWEB 8085 global
attr WEBtablet stylesheetPrefix touchpad

# Fake FileLog entry, to access the fhem log from FHEMWEB
define Logfile FileLog ./log/fhem-%Y-%m.log fakelog

define autocreate autocreate
attr autocreate filelog ./log/%NAME-%Y.log

define eventTypes eventTypes ./log/eventTypes.txt

# Disable this to avoid looking for new USB devices on startup
define initialUsbCheck notify global:INITIALIZED usb create

define i2c RPII2C 1
attr i2c alias Onboard I2C Controller 1
attr i2c room ops

define i2c20 I2C_MCP23017 0x20
attr i2c20 IODev i2c
attr i2c20 room ops
attr i2c20 OutputPorts A0,A1,A2,A3,A4,A5,A6,A7,B0,B1,B2,B3,B4,B5,B6,B7
set i2c20 PortB0 off # ausschalten
set i2c20 PortA0 off # ausschalten
set i2c20 PortA1 off
set i2c20 PortA2 off

define i2c20pB0 readingsProxy i2c20:PortB0
attr i2c20pB0 room ops
attr i2c20pB0 devStateIcon on:on:off off:off:on
attr i2c20pB0 alias AZ Rolladen 1 hoch
attr i2c20pB0 setList on off
attr i2c20pB0 setFn {($CMD eq "on")?"PortB0 on":"PortB0 off"}
attr i2c20pB0 webCmd on:off:on-for-timer 10

define i2c20pA0 readingsProxy i2c20:PortA0
attr i2c20pA0 room ops
attr i2c20pA0 devStateIcon on:on:off off:off:on
attr i2c20pA0 alias AZ Rolladen 1 runter
attr i2c20pA0 setList on off
attr i2c20pA0 setFn {($CMD eq "on")?"PortA0 on":"PortA0 off"}
attr i2c20pA0 webCmd on:off:on-for-timer 10

define i2c20pA1 readingsProxy i2c20:PortA1
attr i2c20pA1 room ops
attr i2c20pA1 devStateIcon on:on:off off:off:on
attr i2c20pA1 alias AZ Rolladen 2 hoch
attr i2c20pA1 setList on off
attr i2c20pA1 setFn {($CMD eq "on")?"PortA1 on":"PortA1 off"}
attr i2c20pA1 webCmd on:off:on-for-timer 10

define i2c20pA2 readingsProxy i2c20:PortA2
attr i2c20pA2 room ops
attr i2c20pA2 devStateIcon on:on:off off:off:on
attr i2c20pA2 alias AZ Rolladen 2 runter
attr i2c20pA2 setList on off
attr i2c20pA2 setFn {($CMD eq "on")?"PortA2 on":"PortA2 off"}
attr i2c20pA2 webCmd on:off:on-for-timer 10

# Rollladenmotorschutz

define RollladenschutzA0 notify i2c20pB0:on set i2c20pA0 off
define RollladenschutzB0 notify i2c20pA0:on set i2c20pB0 off
define RollladenschutzA2 notify i2c20pA1:on set i2c20pA2 off
define RollladenschutzA1 notify i2c20pA2:on set i2c20pA1 off



Titel: Antw:devStateIcon hat umgekehrte Logik
Beitrag von: viegener am 18 Mai 2016, 01:15:31
Beim drüberschauen konnte ich jetzt auch nicht sehen, warum sich A1 anders verhalten sollte, ich denke Du musst da nochmal genau die Unterschiede zwischen den Roladenschaltpaaren anschauen.

Allerdings möchte ich Bedenken anmelden, ob Deine Motorschutz-Notifys so wirklich funktionieren. Wenn eine Fehlschaltung auftritt wird FHEM doch eine geiwsse Zeit brauchen, bis entsprechend der Notify zu schlägt. Bei einer solchen Situation würde ich immer dafür sorgen, dass direkt an der Schaltung sichergestellt ist, dass keine Fehlschaltung erfolgen kann. Ich kenne natürlich Deine Motoren und die Schaltung nicht, aber wenn wirklich ein Motorschutz notwendig ist, dann sollte der in die Hardware wandern.

Titel: Antw:devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 18 Mai 2016, 11:28:15
Habe es jetzt mal ausgedruckt und konnte keinen Unterscheid finden. Auch nicht in der Hardware. Wir haben also ein Problem :-) Entweder ein Bug in FHEM (I2C Implementierung), was ich aber nicht glaube oder das IC (das I2C IC :-) hat einen Schlag weg. Deswegen die Frage: Woher genau erhält FHEM den Status des Ausgangs? Wird das über den I2C Bus angefragt (eher nicht oder?) oder merkt sich FHEM intern, was Phase am Ausgang ist? Der gute Entwickler weiß die Antwort bestimmt aus dem ff :-)

Ja, stimmt, sollte man in der Hardware machen. Aber der Rollladenmotor hat nochmal eine eigene Elektronik und läuft sowieso erst nach 1 Sekunde los. Es ist nur ein zusätzlicher Schutz.
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: viegener am 18 Mai 2016, 11:44:08
Ist denn nur das Icon falsch oder auch der Status am Device selber?

Ich würde jetzt Schritt für Schritt vorgehen bevor gleich ein Fehler in FHEM oder der HW vermutet wird.
Also ausserhalb der ganzen Readingproxies etc, also ganz ohne irgendeine Automatik (alle diese Devices kurzzeitig komplett entfernen und nur den I2C-Device erhalten ohne notfies und weitere Automatik-Attribute)

Schalte den Ausgang PortA1 an / aus und schaue wie in FHEM der STatus sich ändert.
Wenn das nicht geht (HW ?) oder der Status nicht stimmt (Einrichtung oder HW) kann man von da aus ausgehen.
Ohne funktionierendes Grundgerüst, kommst Du mit den ganzen proxies, notifes etc nur ins Chaos

Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 18 Mai 2016, 22:37:44
Zu Frage 1 (ein Bild sagt mehr als 1000 Worte). Auch physikalisch ist der Ausgang super (Verbraucher ist aus, so wie es sein soll)! Nur state steht noch auf on.

siehe Readings A1.png
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: viegener am 18 Mai 2016, 22:41:46
Also ist der Status am Gerät falsch?

Dann wiederhole ich meine Empfehlung erstmal das gesamte Kunstwerk drumherum zu entfernen und zu schauen, ob das Device wirklich nicht funktioniert.
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 18 Mai 2016, 23:04:51
Die Hardware und die Anzeige funktionieren jetzt, mit diesem Code:
Was nun???


attr global logfile ./log/fhem-%Y-%m.log
attr global modpath .
attr global statefile ./log/fhem.save
attr global verbose 3
attr global updateInBackground
attr global latitude 50.111
attr global longitude 8.682

define telnetPort telnet 7072 global

define WEB FHEMWEB 8083 global

define WEBphone FHEMWEB 8084 global
attr WEBphone stylesheetPrefix smallscreen

define WEBtablet FHEMWEB 8085 global
attr WEBtablet stylesheetPrefix touchpad

# Fake FileLog entry, to access the fhem log from FHEMWEB
define Logfile FileLog ./log/fhem-%Y-%m.log fakelog

define autocreate autocreate
attr autocreate filelog ./log/%NAME-%Y.log

define eventTypes eventTypes ./log/eventTypes.txt

# Disable this to avoid looking for new USB devices on startup
define initialUsbCheck notify global:INITIALIZED usb create


define i2c RPII2C 1
attr i2c alias Onboard I2C Controller 1
attr i2c room ops

define i2c20 I2C_MCP23017 0x20
attr i2c20 IODev i2c
attr i2c20 room ops
attr i2c20 OutputPorts A0,A1,A2,A3,A4,A5,A6,A7,B0,B1,B2,B3,B4,B5,B6,B7
set i2c20 PortB0 off # ausschalten
set i2c20 PortA0 off # ausschalten
set i2c20 PortA1 off
set i2c20 PortA2 off

define i2c20pA1 readingsProxy i2c20:PortA1
attr i2c20pA1 room ops
attr i2c20pA1 devStateIcon on:on:off off:off:on
attr i2c20pA1 alias AZ Rolladen 2 hoch
attr i2c20pA1 setList on off
attr i2c20pA1 setFn {($CMD eq "on")?"PortA1 on":"PortA1 off"}
attr i2c20pA1 webCmd on:off:on-for-timer 10

define i2c20pA2 readingsProxy i2c20:PortA2
attr i2c20pA2 room ops
attr i2c20pA2 devStateIcon on:on:off off:off:on
attr i2c20pA2 alias AZ Rolladen 2 runter
attr i2c20pA2 setList on off
attr i2c20pA2 setFn {($CMD eq "on")?"PortA2 on":"PortA2 off"}
attr i2c20pA2 webCmd on:off:on-for-timer 10


Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: viegener am 19 Mai 2016, 00:02:02
OK, wenn das geht, würde ich wie gesagt Schritt-Für-Schritt jeweils mehr wieder hinzufügen und jeweils überprüfen ob das verhalten korrekt bleibt
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 19 Mai 2016, 21:06:24


define SchutzA1 notify i2c20pA2:on set i2c20pA1 off
define SchutzA2 notify i2c20pA1:on set i2c20pA2 off



Somit haben wir wieder das Problem! Ist da was falsch geschrieben?

Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: igami am 19 Mai 2016, 21:12:42
Was steht denn im Event monitor?
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 19 Mai 2016, 21:23:02
2016-05-19 21:20:14 readingsProxy i2c20pA1 on
2016-05-19 21:20:14 I2C_MCP23017 i2c20 PortA1: on
2016-05-19 21:20:14 I2C_MCP23017 i2c20 Ok
2016-05-19 21:20:14 I2C_MCP23017 i2c20 Ok
2016-05-19 21:20:14 I2C_MCP23017 i2c20 Ok
2016-05-19 21:20:14 I2C_MCP23017 i2c20 Ok
2016-05-19 21:20:17 readingsProxy i2c20pA2 on
2016-05-19 21:20:17 I2C_MCP23017 i2c20 PortA2: on
2016-05-19 21:20:17 I2C_MCP23017 i2c20 PortA1: off
2016-05-19 21:20:17 I2C_MCP23017 i2c20 Ok
2016-05-19 21:20:17 I2C_MCP23017 i2c20 Ok
2016-05-19 21:20:17 I2C_MCP23017 i2c20 Ok
2016-05-19 21:20:17 I2C_MCP23017 i2c20 Ok

Draußen in der Wirklichkeit ist alles korrekt!
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: igami am 19 Mai 2016, 21:32:14
Ich sehe da kein "i2c20pA2:on", sondern ein "i2c20 PortA2: on" oder ein "i2c20pA2 on"
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 19 Mai 2016, 22:38:26
Zitat von: igami am 19 Mai 2016, 21:32:14
Ich sehe da kein "i2c20pA2:on", sondern ein "i2c20 PortA2: on" oder ein "i2c20pA2 on"

Was möchtest Du damit sagen? Ist der Code (siehe oben) falsch? Wie gesagt, nach draußen funktioniert ja alles völlig korrekt. D.h. doch, der Code ist korrekt und FHEM hat einen Bug! Habe eben alles mal von Port A auf B abgeändert, gleiche Reaktion der Icons.
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: igami am 19 Mai 2016, 22:45:28
Das notify löst nicht aus, da da Event nicht überein stimmt. Beim Event steht ein Leerzeichen vor on, im notify wird ein Doppelpunkt erwartet. Diesen durch einen Punkt ersetzen und es sollte gehen
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 20 Mai 2016, 08:38:18
Zitat von: igami am 19 Mai 2016, 22:45:28
Das notify löst nicht aus, da da Event nicht überein stimmt. Beim Event steht ein Leerzeichen vor on, im notify wird ein Doppelpunkt erwartet. Diesen durch einen Punkt ersetzen und es sollte gehen
Aber die angeschlosse Lampe schaltet doch automatisch aus, wenn die andere eingeschaltet wird und umgekehrt. Dann müssten die notifys doch auslösen! Ich möchte das jetzt umschreiben wie folgt, erhalte aber noch Fehlermeldungen, u.a. wegen einer geschweiften Klammer. Raff das mit den Sonderzeichen noch nicht so. Der Punkt soll der Platzhalter für 1 und 2 sein:


define Schutz notify i2c20pA. { \
  {Log 1, "Schutz notify START"};;\
  if (Value("i2c20pA1") eq "on") {set PortA2 off};;\
  if (Value("i2c20pA2") eq "on") {set PortA1 off};;\
  {Log 1, "Schutz notify STOPP"};;\
}

Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: igami am 20 Mai 2016, 09:14:32
Stimmt, ich hatte mich vertan  :-[

Was für eine Fehlermeldun erhältst du denn?
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 21 Mai 2016, 01:36:49
Code ist jetzt so:
define Schutz notify i2c20pB.:on { \
  {Log 3, "Schutz notify START"};; \
  if (Value("i2c20pB1") eq "on") {fhem "set i2c20pB2 off"};; \
  if (Value("i2c20pB2") eq "on") {fhem "set i2c20pB1 off"};; \
  {Log 3, "Schutz notify STOPP"};; \
}


Im Logfile steht nun folgendes. Einen begründeten Loop kann ich aber im Code nicht erkennen (Off feuert nicht das notify on!)
Nach der Änderung (zum Test) von A auf B hab ich das Problem halt jetzt mit B1. Wieso funktioniert das nicht???
Was hat das für Konsequenzen, wenn FHEM einen Loop detected? Und was soll ich nun machen? Im Code ist ja kein Loop! (Da habe ich schon ganz andere Loops programmiert, die mit Abbruchbedingung nennen sich dann rekursiver Aufruf! :-o
Ich glaube, hier ist FHEM ein bißchen unsauber!

2016.05.21 01:27:28 3: Schutz notify START
2016.05.21 01:27:28 2: i2c20pB2: ERROR: endless loop detected
2016.05.21 01:27:28 3: set i2c20pB2 off : ERROR: endless loop detected for i2c20pB2
2016.05.21 01:27:28 3: Schutz notify STOPP
2016.05.21 01:27:39 3: Schutz notify START
2016.05.21 01:27:39 3: Schutz notify STOPP
2016.05.21 01:27:42 3: Schutz notify START
2016.05.21 01:27:42 3: Schutz notify STOPP
2016.05.21 01:27:44 3: Schutz notify START
2016.05.21 01:27:44 2: i2c20pB1: ERROR: endless loop detected
2016.05.21 01:27:44 3: set i2c20pB1 off : ERROR: endless loop detected for i2c20pB1
2016.05.21 01:27:44 3: Schutz notify STOPP
2016.05.21 01:27:46 3: Schutz notify START
2016.05.21 01:27:46 2: i2c20pB2: ERROR: endless loop detected
2016.05.21 01:27:46 3: set i2c20pB2 off : ERROR: endless loop detected for i2c20pB2
2016.05.21 01:27:46 3: Schutz notify STOPP

Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: igami am 21 Mai 2016, 07:59:29
Hast du noch anderen notify die auf die devices triggern?
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 21 Mai 2016, 12:08:31
Ne. Es ist wirklich frustrierend!  :(
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: viegener am 22 Mai 2016, 17:03:36
Ich kann nur meinen Hinweis wiederholen, alles an notifies und proxies etc zu entfernen. Speichern und dann schritt für schritt einen teil hinzufügen wieder speichern und ausprobieren. Ich glaube immer noch, dass irgendetwas im zusammenspiel falsch gesetzt ist.

Sobald etwas nicht mehr geht poste doch mal den gesamten inhalt der config, der mit dem problem zu tun haben könnte.

Weiterer hinweis, in deinen notifies könntest du doch direkt den port am i2c setzen. Die readingproxies machen das debuggen eher schwieriger.
Titel: Antw:Icon ist falsch. War: devStateIcon hat umgekehrte Logik
Beitrag von: fhemer am 20 November 2016, 21:21:02
Hi.
Sorry für die etwas späte Antwort. D.h. die readingProxys brauche ich gar nicht und kann sie weglassen? Das wusste ich nicht. Das ist doch schonmal ein guter Tipp!  :)