Hi everybody,
I'm new with Fhem. Reading forums I manage to connect my Comfoair ventilation system, and now I'm trying to send a value (temperature) to dweet.io to display it in freeboard.io.
To do this, I created the following DOIF in fhem.cfg that send to dweet a fake external temperature value "30":
define dw_P49 DOIF ([+00:05:00]) ("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=30" )
attr dw_P49 do always
It works correctly, but my problem is how to replace the "30" value with "ZL:Temp_EWT" fhem value. Anybody can help me?
Thanks!
Andrea
Hi Andrea,
I am not shure if this will help you, but inside the {system("")} call Perl variables will be replaced by there values.
I have a call like this {system("./Aufruf.sh $NAME $EVENT &")}
and $NAME and $EVENT will be replaced during the call.
May be you have to do this like the example in the commandref {my $name="Peter"; system ("wmail $name is at home");}
and you could use ReadingsVal("ZL","Temp_EWT","") to read your value.
May be there is a easier way.
Otto
Thanks Otto,
This give no error but doesn't send any value to dweet.io:
define dw_P49 DOIF ([+00:05:00]) ( { my $data=ReadingsVal("ZL","Temp_EWT","") ;;;;\ system ("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=$data")})
If I replace with my $data="60" it's the same, no value received.
Any suggestion?
Thank you
I learned yesterday, that DOIF can handle direkt to Perl in this way:
DOIF () {}
And may be there ar to many ;;;;
Inside the DEF there should be one ;
Inside the define there should be two ;;
You should try define dw_P49 DOIF ([+00:05:00]) { my $data=ReadingsVal("ZL","Temp_EWT","") ;; system ("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=$data")}
Otto
I tried but I receive this error:
configfile: dw_P49 DOIF: expected DOELSEIF or DOELSE: { my $data=ReadingsVal("ZL","Temp_EWT","") ; system ("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=$data")}
I think that Fhem expect () with command, instead of {}:
define <name> DOIF (<condition>) (<commands>)
It's very complicate mixing fhem, shell and perl commands :(
Thank you again
Andrea
Zitat von: andreafno am 09 Juli 2017, 13:36:59
Hi everybody,
I'm new with Fhem. Reading forums I manage to connect my Comfoair ventilation system, and now I'm trying to send a value (temperature) to dweet.io to display it in freeboard.io.
To do this, I created the following DOIF in fhem.cfg that send to dweet a fake external temperature value "30":
define dw_P49 DOIF ([+00:05:00]) ("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=30" )
attr dw_P49 do always
It works correctly, but my problem is how to replace the "30" value with "ZL:Temp_EWT" fhem value. Anybody can help me?
Thanks!
Andrea
In DOIF you usually access Readings by [<devicename>:<readingname>]. So this should work:
("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=[ZL:Temp_EWT]" )
Hi Ellert,
I tried but it doesn't works.
Trying this in the "command line" inside Fhem webserver I obtain the correct value:
{(ReadingsVal("ZL","Temp_EWT",""))}
But can't find how to combine with "curl" command. This doesn't works:
("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49={(ReadingsVal("ZL","Temp_EWT",""))}")
Hi Andrea,
I am not shure about the feature from DOIF dependend from the version. Is your fhem up to date?
I tried this in the FHEM commandline as a "oneliner"{my $data="Willi";; system ("echo $data > willi.txt")}
This works, I will get a file /opt/fhem/willi.txt with Willi inside. So in my case, $data is filled with "Willi" and inside the system command $data is replaced by the string "Willi".
The same construct with DOIF is working too: define di_Test DOIF ([23:59]) ({my $data="Willi";; system ("echo $data > willi.txt")})
Also the "Perl only" Version is working without any errors:define di_Test DOIF ([00:06]) {my $data="Willi";; system ("echo $data >> willi.txt")}
Otto
Zitat von: CommandREFPerlbefehle werden in geschweifte Klammern gesetzt: ... {system ("wmail Peter is at home")}. In diesem Fall können die runden Klammern des Ausführungsteils weggelassen werden.
This possibility is relatively new : svn 13635 07.03.2017 https://svn.fhem.de/trac/browser/trunk/fhem/FHEM/98_DOIF.pm?rev=13635
ZitatI created the following DOIF in fhem.cfg
:o :-X
("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49={(ReadingsVal("ZL","Temp_EWT",""))}")
Cannot work because you are mixing perl in a system command.
("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=[ZL:Temp_EWT]" )
Probably a similar problem (mixing DOIF syntax and system command).
{my $name="Peter"; system ("wmail $name is at home");}
works because "system" is a perl command. You are doing only perl.
Try this in DEF, supposing you have the last version of DOIF module:
([+00:05:00])
{my $var = ReadingsVal("ZL","Temp_EWT",""); system ("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=$var");}
or
([+00:05:00])
{system ("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=".ReadingsVal("ZL","Temp_EWT","")); }
If DOIF is crying because of the result of system(), just add return 0 at the end:
([+00:05:00])
{system ("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=".ReadingsVal("ZL","Temp_EWT","")); return 0;}
Zitat von: Ellert am 09 Juli 2017, 21:00:54
In DOIF you usually access Readings by [<devicename>:<readingname>]. So this should work:
("sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=[ZL:Temp_EWT]" )
May be this will work:
([+00:05:00]) {system "sudo /usr/bin/curl -i https://dweet.io/dweet/for/dw_P49?P49=[ZL:Temp_EWT]"}
Thank you all!! ;D
Finally it works: the problem was I didn't updated DOIF
Zitat
define dw_P49 DOIF ([+00:05:00]) {my $data=ReadingsVal("ZL","Temp_EWT","");; system ("curl -i https://dweet.io/dweet/for/dw_P49?P49=$data")}
Have a nice weekend
Andrea