FHEM Forum

FHEM => English Corner => Thema gestartet von: mtk am 28 Februar 2017, 10:57:36

Titel: problems with cLirc: fhem commands within 99_myUtils are not working
Beitrag von: mtk am 28 Februar 2017, 10:57:36
Hi
I installed cLirc https://forum.fhem.de/index.php?topic=29425.0 (https://forum.fhem.de/index.php?topic=29425.0) and I can see the events within my event monitor:

Events (Filter: .*)   FHEM log   

2017-02-28 09:01:48.782 CUL_WS CUL_WS_3 T: 4.3  H: 72.5
2017-02-28 09:01:48.782 CUL_WS CUL_WS_3 temperature: 4.3
2017-02-28 09:01:48.782 CUL_WS CUL_WS_3 humidity: 72.5
2017-02-28 09:01:54.960 cLIRC lirc_rPiNode2 received: KEY_3
2017-02-28 09:01:54.961 cLIRC lirc_rPiNode2 KEY_3
2017-02-28 09:01:59.151 dummy Heartbeat off
2017-02-28 09:02:02.599 cLIRC lirc_rPiNode2 received: KEY_4
2017-02-28 09:02:02.600 cLIRC lirc_rPiNode2 KEY_4
2017-02-28 09:02:04.148 dummy Heartbeat on
2017-02-28 09:02:04.150 at t_Heartbeat Next: 09:02:14


What is not working, is the part within 99_myUtils:
# event handler cLirc lirc_PiNode2
sub h_LircPiNode2($)
{
  my ($evt)=@_;

  if ($evt eq "KEY_CHANNELDOWN") {fhem "set IT_B_3 off" ; }
  if ($evt eq "KEY_CHANNELUP") {fhem( "set IT_B_3 on" ); } 
  if ($evt eq "KEY_3") {fhem "set IT_B_3 on" ;}
  if ($evt eq "KEY_4") {fhem "set IT_B_3 off" ;}
}


Because I want to use many Lirc Pi nodes in parallel, I just renamed some parts to realize that in FHEM:
As you can see I am not really familiar with that syntax in terms of brackets, spaces a.s.o.
so I made some tests with different notations, but there was no reaction on device IT_B_3.

define lirc_rPiNode2 cLIRC pinode2.daheim

# original was define n_lirc_rPi notify lirc_rPi:received.* {h_LircRpi($EVENT)}
define n_lirc_rPiNode2 notify lirc_rPiNode2:received.* {h_LircPiNode2($EVENT)}


So what is wrong within my configuration?
Cant find any mistakes any more ...

kind regards
Michael

Titel: Antw:problems with cLirc: fhem commands within 99_myUtils are not working
Beitrag von: MadMax-FHEM am 28 Februar 2017, 11:15:38
Hi,

first of all: are there any error messages or is it "just not working"??

Then I would do some printouts:

Log(1,"h_LircPiNode2  evt: $evt");


to see wat is going in because maybe non of the if is true ;)

EDIT: and also if the notify triggers (but it looks ok)...

And not sure but the syntax should be: {fhem("set ...");} !?
(at least the examples here https://wiki.fhem.de/wiki/99_myUtils_anlegen (https://wiki.fhem.de/wiki/99_myUtils_anlegen) show this [not able to have a look @home ;) ])

EDIT2: sorry examples are on a site in German... But the example is international ;)

Bye, Joachim
Titel: Antw:problems with cLirc: fhem commands within 99_myUtils are not working
Beitrag von: mtk am 28 Februar 2017, 12:59:34
Hi,

just added logging of the routine.
# event handler cLirc lirc_rPiNode2
sub h_LircPiNode2($)
{
my ($evt)=@_;

Log(1,"h_LircPiNode2  evt: $evt");

if (Value($evt) eq "KEY_CHANNELDOWN") {
fhem("set IT_A_2 off");
}
if (Value($evt) eq "KEY_CHANNELUP") {
fhem("set IT_A_2 on");

 
  if ($evt eq "KEY_3") {fhem("set IT_A_2 on");}
  if ($evt eq "KEY_4") {fhem("set IT_A_2 off");}
}


I also tested different kind of if statements. No success ...

But the output seems to be quiet correct:

2017.02.28 12:33:59.809 1: h_LircPiNode2  evt: received: KEY_CHANNELUP
2017.02.28 12:34:01.864 1: h_LircPiNode2  evt: received: KEY_CHANNELDOWN
2017.02.28 12:34:04.813 1: h_LircPiNode2  evt: received: KEY_1
2017.02.28 12:34:10.865 1: h_LircPiNode2  evt: received: KEY_3
2017.02.28 12:34:15.078 1: h_LircPiNode2  evt: received: KEY_4


Also made some shutdown restart in between to ensure reload of changed code.

Then I tried to make some log within if statement in 99_myUtils and there was no output from that lines:
# event handler cLirc lirc_rPiNode2
sub h_LircPiNode2($)
{
my ($evt)=@_;

Log(1,"h_LircPiNode2  evt: $evt");

if($evt eq "KEY_CHANNELDOWN") {
fhem("set IT_A_2 off");
Log(1,"h_LircPiNode2 if then KEY_CHANNELDOWN ");
}
if($evt eq "KEY_CHANNELUP") {
fhem("set IT_A_2 on");
Log(1,"h_LircPiNode2 if then KEY_CHANNELUP ");

 
  if($evt eq "KEY_3") {fhem("set IT_A_2 on"); Log(1,"h_LircPiNode2 if then KEY_3 ");}
  if($evt eq "KEY_4") {fhem("set IT_A_2 off");Log(1,"h_LircPiNode2 if then KEY_4 ");}
}



There is no log with h_LircPiNode2 if then KEY... , only the  h_LircPiNode2  evt: received: KEY was logged.
My conclusion is a problem within the if statement, but I dont know what.
But within evt there is still the string received:, this might be not correct.
I think it should contain just the KEY code without "received" ...

regards
Michael (german native speaking, thx for the link)

Titel: Antw:problems with cLirc: fhem commands within 99_myUtils are not working
Beitrag von: MadMax-FHEM am 28 Februar 2017, 13:08:56
Hmmm, the if statement looks ok for me...
As I remember (I cannot have a look right now) I have a lot of those statements...
...and they work...

The only thing (I have in mind) I do differntly is the "fhem-call"...
(not sure if it is right but it works on my system)


sub h_LircPiNode2($)
{
my ($evt)=@_;

Log(1,"h_LircPiNode2  evt: $evt");

if($evt eq "KEY_CHANNELDOWN") {
Log(1,"h_LircPiNode2 if then KEY_CHANNELDOWN ");
{fhem("set IT_A_2 off")}
}
if($evt eq "KEY_CHANNELUP") {
Log(1,"h_LircPiNode2 if then KEY_CHANNELUP ");
{fhem("set IT_A_2 on")}
}

  if($evt eq "KEY_3") {fhem("set IT_A_2 on"); Log(1,"h_LircPiNode2 if then KEY_3 ");}
  if($evt eq "KEY_4") {fhem("set IT_A_2 off");Log(1,"h_LircPiNode2 if then KEY_4 ");}
}


So I changed the log-output to the "front" to really see if we're going in there...
...and put those {} around the "fhem-statement"...

As I told it might be "wrong" or at least unnecessary but as I have in mind I do it that way (when I'm home I will have a look) and it works...

Eventually (but I think not necessary and maybe first try the other things):

if("$evt" eq "...")

Bye, Joachim
Titel: Antw:problems with cLirc: fhem commands within 99_myUtils are not working
Beitrag von: mtk am 28 Februar 2017, 13:13:33
this is working, but not sexy:
if($evt eq "received: KEY_CHANNELDOWN") {
fhem("set IT_A_2 off");
Log(1,"h_LircPiNode2 if then KEY_CHANNELDOWN ");
}
if($evt eq "received: KEY_CHANNELUP") {
fhem("set IT_A_2 on");
Log(1,"h_LircPiNode2 if then KEY_CHANNELUP ");

 


the my ($evt)=@_; might cause this problem ...
So how should I fix this problem to get only the Key code without "received" string inside?
Titel: Antw:problems with cLirc: fhem commands within 99_myUtils are not working
Beitrag von: MadMax-FHEM am 28 Februar 2017, 13:16:34
Ah now I see...

I had tomatos on my eyes ;)

You could give $EVTPART1 (or is it $EVTPART2 / I actually don't know if counting starts with one or zero) as parameter instead of $EVENT

Or use split to get rid of the unwanted stuff...

Sorry, Joachim
Titel: Antw:problems with cLirc: fhem commands within 99_myUtils are not working
Beitrag von: mtk am 28 Februar 2017, 13:23:50
took the code from developer ChrisD here: https://forum.fhem.de/index.php?topic=29425.0#top (https://forum.fhem.de/index.php?topic=29425.0#top)
If cLirc is part of the fhem update mechanisms it might be fixed there also. Otherwhise I might get the problem again.
I will inform him about this. Maybe we can create a common documentation for configuration and usage of cLirc.

kind regards
Michael
Titel: Antw:problems with cLirc: fhem commands within 99_myUtils are not working
Beitrag von: MadMax-FHEM am 28 Februar 2017, 13:51:23
Now I'm confused??

The "problem" with the "received: " is not related to lirc...
...it has to do with the notify / Event that is comming.

So $EVTPART1 ... $EVTPARTN (or starts at 0 / $EVTPART0) just takes that part from the "received" Event of the notify...

So when you just give $EVTPART1 (or $EVTPART2 depends of where counting starts) you just get inside your function what you need:

define n_lirc_rPiNode2 notify lirc_rPiNode2:received.* {h_LircPiNode2($EVTPART1)}

so
if($evt eq "KEY_CHANNELDOWN")

should work (again) instead of:

if($evt eq "received: KEY_CHANNELDOWN")

Or did I miss the real problem??

Bye, Joachim
Titel: Antw:problems with cLirc: fhem commands within 99_myUtils are not working
Beitrag von: mtk am 28 Februar 2017, 14:51:34
No, you are completely right. I was just expecting some possible side impact, because the author might change the behaviour of the event in future (maybe without receive) Are there any constraints in how to implement results from events and manage in a common way?

For all other using cLirc there should be a working description with proper installation instruction. The code I took there is not working. Thats all :-)

But thankyou very much for helping me!

Michael



Titel: Antw:problems with cLirc: fhem commands within 99_myUtils are not working
Beitrag von: MadMax-FHEM am 28 Februar 2017, 15:08:07
Ok.

No (when I understood the question right) there is nothing like constraints and (as it is free and open source) the module developer is "free" which events are thrown (so it depends on the nam of the reading that is changed).

So the only thing possible is to look into EventMonitor and try to find a pattern (regex) that matches the wanted event the best.
Then define a notify (or DOIF or or or) and invoke the desired action (directly or via calling a sub [with or without parameters]).

If a module developers decides to change the event then the notify (or DOIF or or or) will not work anymore...
...and then again: open EventMonitor and try to change the pattern (regex) that it triggers again.

But I think those events are not changed so often and normally never without good reason...

Often the code posted here is just meant as example how this (in principle) should work...
...and often is just coming from brain without testing (like my suggestions).

So have fun!

Bye, Joachim