Hallo zusammen,
ich stelle diese Frage mal im Anfängerforum da ich mit einem vielleicht leichtem Problem nicht mehr weiter komme.
Ich habe folgendes noitfy mit dem ich Lampen duch einen Taster einschalte, oder ausschalte wenn sie schon an waren. Dies funktioniert auch.
1PortB1_Wohnlichttaster:.on {if (Value("1PortA5_Wohnlicht") eq "on") {fhem ("set 1PortA5_Wohnlicht off")}else {fhem ("set 1PortA5_Wohnlicht on")} }
Jetzt brauche ich diese Funktion als DOIF und trotz vieler Versuche komme ich nicht auf die richtige Formel.
Kann mir jemand helfen?
Vielen Dank,
Byllyy
Hier ein funktionierendes Beispiel.
musst Dir nur entsprechend umbauen.
defmod Licht_HSA DOIF ([GPIO_IN_07:"^on$"] and [?OUT_1:PortA3] eq "off") (set OUT_1 PortA3 on)\
DOELSEIF ([GPIO_IN_07:"^on$"] and [?OUT_1:PortA3] eq "on") (set OUT_1 PortA3 off)
attr Licht_HSA cmdState on|off
attr Licht_HSA devStateIcon on:on:cmd_2 initialize|initialized|off:off:cmd_1
attr Licht_HSA do always
Hallo und Danke für die schnelle Antwort
Ich habe deinen Tipp ausprobiert und er " sollte" auch so klappen, jedoch scheint mein Problem tiefer zu liegen.
Nach dem Einschalten wird bei mir der Status des geschalteten Device nicht aktualisiert, dann kann die Ausschaltfunktion natürlich auch nicht klappen.
Ich brauche jetzt einen Tipp weshalb das Device nicht aktualisiert.
Es ist ein " readingProxy" von einem Port eines I2C Busses.
Internals:
DEF icMCP23017:PortA5
DEVICE icMCP23017
FUUID 5ff5d8e4-f33f-bc18-5596-cb6e9b91fb357a33
NAME 1PortA5_Wohnlicht
NOTIFYDEV global,icMCP23017
NR 169
NTFY_ORDER 50-1PortA5_Wohnlicht
READING PortA5
STATE off
TYPE readingsProxy
CONTENT:
icMCP23017 1
READINGS:
2021-01-19 14:12:23 lastCmd on
2021-01-19 14:12:23 state off
Attributes:
group HuboOut
room GuteNachtAus,HuboOut,I2c,Unsorted
setFn {($CMD eq "on")?"PortA5 on":"PortA5 off"}
setList off on
valueFn {($VALUE eq "off")?"off":"on"}
Danke für eure Hilfe,
Byllyy
versuche es direkt auf das MCP23017 loszulassen.
So ist das bei meinem Beispiel auch.
Taster = GPIO des PI.
Relais = am I2C_MCP23017
Wie schafft man es denn direkt einen Port des MCP23017 abzufragen oder zu schalten. Ich dachte das geht immer nur mit einem "readingProxy".
Kann du mir bitte den "set" Befehle zum Schalten eines Ports nennen?
Oder habe ich deinen Hinweis falsch interpretiert?
Danke für deine Hilfe,
Byllyy
Zitat von: Byllyy am 19 Januar 2021, 15:56:13
Kann du mir bitte den "set" Befehle zum Schalten eines Ports nennen?
Oder habe ich deinen Hinweis falsch interpretiert?
ist doch in meinem Beispiel drin. ;-)
set OUT_1 PortA3 on
OUT_1 ist das MCP23017 Device, PortA3 der Port und "on" der Befehl.
OK, das schalten der Ports mit "set icMCP23017 PortA5 on" funktioniert so auch bei mir, doch in meinem DOIF ([1PortB1_Wohnlichttaster]eq "on" and [icMCP23017:PortA5] eq "on")(set icMCP23017 PortA5 off)
frage ich ja auch den Zustand des Ports ab und das klappt nicht. Ich habe es mit "[icMCP23017:PortA5] eq "on")" und "[icMCP23017 PortA5] eq "on")" pobiert.
So sieht mein MCM23017 aus :Internals:
DEF 0x22
FUUID 5ff5d196-f33f-bc18-0431-19c1436c004a19ba
I2C_Address 34
IODev i2cBus
NAME icMCP23017
NR 153
STATE Ok
TYPE I2C_MCP23017
i2cBus_SENDSTAT Ok
READINGS:
2021-01-18 17:38:05 PortA0 off
2021-01-19 14:05:11 PortA1 off
2021-01-18 17:38:03 PortA2 off
2021-01-19 15:23:59 PortA3 off
2021-01-18 17:38:02 PortA4 off
2021-01-19 17:44:35 PortA5 on
2021-01-12 09:01:46 PortA6 off
2021-01-11 12:10:30 PortA7 off
2021-01-19 15:43:48 PortB0 on
2021-01-19 17:34:36 PortB1 on
2021-01-06 16:49:28 PortB2 on
2021-01-06 16:49:32 PortB3 on
2021-01-19 17:33:13 PortB4 on
2021-01-19 16:15:10 PortB5 on
2021-01-19 12:17:31 PortB6 on
2021-01-19 16:15:24 PortB7 off
2021-01-19 18:00:31 state Ok
Attributes:
IODev i2cBus
Interrupt B0,B1,B2,B3,B4,B5,B6,B7
InterruptOut connected_active-low
OutputPorts A0,A1,A2,A3,A4,A5,A6,A7
Pullup B0,B1,B2,B3,B4,B5,B6,B7
group Hubo
room I2c,Unsorted
Poste mal bitte ein List vom doif im jetzigen Zustand.
Nett das du dran bleibst und mir hilfst. Hier das DOIF:
Internals:
CFGFN
DEF ([1PortB1_Wohnlichttaster]eq "on" and [icMCP23017:PortA5] eq "off")(set icMCP23017 PortA5 on)
FUUID 6006c221-f33f-bc18-0f68-58085ba9044f398f
MODEL FHEM
NAME WohnlichtDOIF
NOTIFYDEV global,1PortB1_Wohnlichttaster,icMCP23017
NR 2678
NTFY_ORDER 50-WohnlichtDOIF
STATE initialized
TYPE DOIF
VERSION 23466 2021-01-03 17:14:46
READINGS:
2021-01-20 08:00:52 Device 1PortB1_Wohnlichttaster
2021-01-20 07:59:51 cmd 0
2021-01-20 08:00:52 e_1PortB1_Wohnlichttaster_STATE off
2021-01-20 08:00:38 e_icMCP23017_PortA5 off
2021-01-20 08:00:52 error condition c01: Unrecognized character \xE2; marked by <-- HERE after rtA5') eq <-- HERE near column 117, line 1, <GEN5327> line 19.
2021-01-20 07:59:51 mode enabled
2021-01-20 07:59:51 state initialized
Regex:
accu:
cond:
1PortB1_Wohnlichttaster:
0:
&STATE ^1PortB1_Wohnlichttaster$
icMCP23017:
0:
PortA5 ^icMCP23017$:^PortA5:
attr:
cmdState:
wait:
waitdel:
condition:
0 ::InternalDoIf($hash,'1PortB1_Wohnlichttaster','STATE')eq "on" and ::ReadingValDoIf($hash,'icMCP23017','PortA5') eq "off"
do:
0:
0 set icMCP23017 PortA5 on
1:
helper:
DEVFILTER ^global$|^1PortB1_Wohnlichttaster$|^icMCP23017$
NOTIFYDEV global|1PortB1_Wohnlichttaster|icMCP23017
event off
globalinit 1
last_timer 0
sleeptimer -1
triggerDev 1PortB1_Wohnlichttaster
triggerEvents:
off
triggerEventsState:
off
internals:
all 1PortB1_Wohnlichttaster:STATE
readings:
all icMCP23017:PortA5
trigger:
uiState:
uiTable:
Attributes:
do always
Ich habe es ganz vereinfacht um es zu Testen. Der Zustand von [icMCP23017:PortA5] wird nicht angezeigt und ein error angezeigt. Gibt es eine andere Syntax für die Abfrage des Ports?
Vielen Dank,
Byllyy
" vor off ist ein "falsches" Anführungszeichen - das muss ein " sein.
Zitat von: xenos1984 am 20 Januar 2021, 08:27:05
" vor off ist ein "falsches" Anführungszeichen - das muss ein " sein.
Dem ist nichts hinzuzufügen. ;-)
Wie immer sind es die Kleinigkeiten die einem das Leben schwer machen.
Vielen Dank das ihr "mein Missgeschick" gefunden habt. Nach Änderung des Zeichens konnte ich
das DOIF auch komplett schreiben und es funktioniert. Allerdings musste ich ein "wait" mit einbauen da sonst
die Funktion nicht ging, oder habe ich da noch andere Möglichkeiten?. Vielen Dank noch einmal!
Hier das laufende DOIF
Internals:
CFGFN
DEF ([1PortB1_Wohnlichttaster]eq "on" and [icMCP23017:PortA5]eq "off")(set icMCP23017 PortA5 on) DOELSEIF ([1PortB1_Wohnlichttaster]eq "on" and [icMCP23017:PortA5]eq "on")(set icMCP23017 PortA5 off)
FUUID 6006c221-f33f-bc18-0f68-58085ba9044f398f
MODEL FHEM
NAME WohnlichtDOIF
NOTIFYDEV icMCP23017,global,1PortB1_Wohnlichttaster
NR 2678
NTFY_ORDER 50-WohnlichtDOIF
STATE cmd_2
TYPE DOIF
VERSION 23466 2021-01-03 17:14:46
READINGS:
2021-01-20 09:04:22 Device 1PortB1_Wohnlichttaster
2021-01-20 09:04:22 cmd 2
2021-01-20 09:04:22 cmd_event 1PortB1_Wohnlichttaster
2021-01-20 09:04:22 cmd_nr 2
2021-01-20 09:04:22 e_1PortB1_Wohnlichttaster_STATE off
2021-01-20 09:00:20 e_icMCP23017_PortA5 on
2021-01-20 08:59:01 mode enabled
2021-01-20 09:04:22 state cmd_2
2021-01-20 09:04:22 wait_timer no timer
Regex:
accu:
cond:
1PortB1_Wohnlichttaster:
0:
&STATE ^1PortB1_Wohnlichttaster$
1:
&STATE ^1PortB1_Wohnlichttaster$
icMCP23017:
0:
PortA5 ^icMCP23017$:^PortA5:
1:
PortA5 ^icMCP23017$:^PortA5:
attr:
cmdState:
wait:
0:
0.5
1:
0.5
waitdel:
condition:
0 ::InternalDoIf($hash,'1PortB1_Wohnlichttaster','STATE')eq "on" and ::ReadingValDoIf($hash,'icMCP23017','PortA5')eq "off"
1 ::InternalDoIf($hash,'1PortB1_Wohnlichttaster','STATE')eq "on" and ::ReadingValDoIf($hash,'icMCP23017','PortA5')eq "on"
do:
0:
0 set icMCP23017 PortA5 on
1:
0 set icMCP23017 PortA5 off
2:
helper:
DEVFILTER ^global$|^1PortB1_Wohnlichttaster$|^icMCP23017$
NOTIFYDEV global|1PortB1_Wohnlichttaster|icMCP23017
event on
globalinit 1
last_timer 0
sleepdevice 1PortB1_Wohnlichttaster
sleepsubtimer -1
sleeptimer -1
timerdev 1PortB1_Wohnlichttaster
timerevent on
triggerDev 1PortB1_Wohnlichttaster
DOIF_eventa:
cmd_nr: 2
cmd: 2
cmd_event: 1PortB1_Wohnlichttaster
cmd_2
DOIF_eventas:
cmd_nr: 2
cmd: 2
cmd_event: 1PortB1_Wohnlichttaster
state: cmd_2
timerevents:
on
timereventsState:
on
triggerEvents:
on
triggerEventsState:
on
internals:
all 1PortB1_Wohnlichttaster:STATE
readings:
all icMCP23017:PortA5
trigger:
uiState:
uiTable:
Attributes:
do always
wait 0.5:0.5
Danke,
Byllyy
Zitat von: Byllyy am 20 Januar 2021, 09:09:44
Allerdings musste ich ein "wait" mit einbauen da sonst die Funktion nicht ging,
Was ging nicht?
Im Idealfall zeigst uns ein List im Fehlerzustand.
Ich würde aber die Abfrage des Zustandes nicht triggernd einbauen, also mit ? wie in meinem Beispiel.
Denke das wird auch dein "Problem" beheben.
WOW, das mit dem Fragezeichen kannte ich noch gar nicht und habe es in deinem Beispiel falsch interpretiert.
Es funktioniert aber !!
Kannst du mir bitte noch die Funktion des Fragezeichens erklären, dann bin ich etwas schlauer.
Wie immer vielen Dank, ohne eure Hilfe wäre ich hier wohl gescheitert,
Byllyy
https://fhem.de/commandref_DE.html#DOIF_Zeitintervalle_Readings_und_Status_ohne_Trigger
Perfekt, dann werde ich mein Problem als Gelöst makieren und sage nochmal Danke.