Autor Thema: DOIF shell command  (Gelesen 797 mal)

Offline andreafno

  • New Member
  • *
  • Beiträge: 6
DOIF shell command
« 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

Offline Otto123

  • Hero Member
  • *****
  • Beiträge: 7050
    • Otto's Technik Blog
Antw:DOIF shell command
« Antwort #1 am: 09 Juli 2017, 13:55:39 »
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
« Letzte Änderung: 09 Juli 2017, 18:24:31 von Otto123 »
Viele Grüße aus Leipzig
RaspberryPi,HMLAN,HMUART,Homematic,Fritz!Box 7490,Sonos,ET9200,Arduino nano,ESP8266

Offline andreafno

  • New Member
  • *
  • Beiträge: 6
Antw:DOIF shell command
« Antwort #2 am: 09 Juli 2017, 15:15:58 »
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

Offline Otto123

  • Hero Member
  • *****
  • Beiträge: 7050
    • Otto's Technik Blog
Antw:DOIF shell command
« Antwort #3 am: 09 Juli 2017, 17:45:13 »
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
« Letzte Änderung: 09 Juli 2017, 21:28:50 von Otto123 »
Viele Grüße aus Leipzig
RaspberryPi,HMLAN,HMUART,Homematic,Fritz!Box 7490,Sonos,ET9200,Arduino nano,ESP8266

Offline andreafno

  • New Member
  • *
  • Beiträge: 6
Antw:DOIF shell command
« Antwort #4 am: 09 Juli 2017, 20:39:04 »
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

Offline Ellert

  • Developer
  • Hero Member
  • ****
  • Beiträge: 2528
Antw:DOIF shell command
« Antwort #5 am: 09 Juli 2017, 21:00:54 »
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]" )

Offline andreafno

  • New Member
  • *
  • Beiträge: 6
Antw:DOIF shell command
« Antwort #6 am: 13 Juli 2017, 22:24:03 »
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",""))}")


Offline Otto123

  • Hero Member
  • *****
  • Beiträge: 7050
    • Otto's Technik Blog
Antw:DOIF shell command
« Antwort #7 am: 14 Juli 2017, 00:02:16 »
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
« Letzte Änderung: 14 Juli 2017, 00:07:58 von Otto123 »
Viele Grüße aus Leipzig
RaspberryPi,HMLAN,HMUART,Homematic,Fritz!Box 7490,Sonos,ET9200,Arduino nano,ESP8266

Offline amenomade

  • Hero Member
  • *****
  • Beiträge: 1983
Antw:DOIF shell command
« Antwort #8 am: 14 Juli 2017, 00:51:05 »
Zitat von: CommandREF
Perlbefehle 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
Zitat
I 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;}

« Letzte Änderung: 14 Juli 2017, 00:55:44 von amenomade »
FHEM 5.8 Pi 3, EchoDot, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, und HM Komponenten

F:"Schatz? Mach aus bitte"
M: "Alexa? Licht aus"-"Ich bin mir leider nicht sicher"  M:"Alexa? aus Licht"-"Das weiss ich leider nicht" M:"Alexa? Schalte...
F: "Drück mal auf den blöden Knopf!

Offline Ellert

  • Developer
  • Hero Member
  • ****
  • Beiträge: 2528
Antw:DOIF shell command
« Antwort #9 am: 14 Juli 2017, 01:05:23 »
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]"}

Offline andreafno

  • New Member
  • *
  • Beiträge: 6
Antw:DOIF shell command
« Antwort #10 am: 14 Juli 2017, 18:46:24 »
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