Using perl in scripts

Begonnen von jacko, 10 Februar 2023, 11:46:16

Vorheriges Thema - Nächstes Thema

jacko

I see some posts that describe the solution using perl constructs. It's been a long time since I used perl but I can see that I am going to have to dust the  manual off and start to use for my FHEM installation as I have some quite complex state machines from my old system that I need to port across.

I have seen the "perl Specials" section of the Command Ref but it's unclear to me whether I add the perl functionality within the fhem.cfg file or whether I need to run a perl script independent of FHEM and make calls into FHEM as required (I hope not!).

Any pointers would be appreciated.

rudolfkoenig

A lot of modules accept perl expressions for different purposes. E.g. the at module can execute a FHEM command, a shell-script or a perl expression, the same with notify.
Other example: if you dont like the icon shown in FHEMWEB for a device, you can "compute" your HTML code for displaying the state of this device in a perl function (see https://fhem.de/commandref_modular.html#FHEMWEB-attr-devStateIcon)

Shorter expressions can be specified directly as part of the definition or the attribute value, longer ones should be stored as a function in your own module (e.g. 99_myUtils.pm). In the latter case notify/at/etc will call the function from the perl expression.

Torxgewinde

It's a bit hard to tell which direction you are aiming for. In general, FHEM has a lot of devices and especially the DOIF device might be of interest for your use-case. However, after years of trying to get along without using perl, I think it is a lot easier to also consider perl for simple one-liners or low complexity functons and leave the heavy lifting and orchestration to FHEM. Good luck anyway!