FHEM Forum

FHEM => English Corner => Thema gestartet von: @lex99 am 07 Oktober 2017, 22:20:56

Titel: How to get FHEM to read a value from a file ?
Beitrag von: @lex99 am 07 Oktober 2017, 22:20:56
Hi,

I have a perl script that runs on my Pi (where FHEM is running) and updates a file with a 0 or 1.

I would like FHEM to read that file at certain times (AT command) and depending on the file contents (0 or 1) do an action (or not).

I am stuck: how to get FHEM to read the file ?

Thanks !
Titel: Antw:How to get FHEM to read a value from a file ?
Beitrag von: Deudi am 07 Oktober 2017, 23:05:10
How about using a custom reading?
https://fhem.de/commandref.html#CustomReadings (https://fhem.de/commandref.html#CustomReadings)
Titel: Antw:How to get FHEM to read a value from a file ?
Beitrag von: @lex99 am 10 Oktober 2017, 21:56:41
Hi,

Thanks, it works OK.  For those interested:

I have a Perl script that checks the weather forecast for my town and writes 0 or 1 in the status.txt file, depending if there will be sunshine or not.
Then FHEM reads the file and puts off the heater if sunshine is expected.

In fhem.cfg:
define myMeteo CustomReadings
attr myMeteo interval 3600
attr myMeteo readingDefinitions chauff:qx(cat /mnt/PiBackup/Chauffage/status.txt)

define Chauffage_6 at *06:01:00 IF ([myMeteo:chauff] eq "0") (set 0_Chaudiere off)
Titel: Antw:How to get FHEM to read a value from a file ?
Beitrag von: Otto123 am 10 Oktober 2017, 22:08:15
Hi,
for your Info, there is also a perl function inside FHEM -> https://wiki.fhem.de/wiki/DevelopmentModuleAPI#FileRead
Unfortunately this doku is in german.

Otto