Hauptmenü

Scripting basics

Begonnen von andyBex0791, 12 November 2024, 11:06:20

Vorheriges Thema - Nächstes Thema

andyBex0791

Hi. I have a set of ELV Max devices with a nanocul device that I have managed to get setup.

I am moving from openHab in which I had some code that polled the wall thermostats for thier room temperature and set temperature. If any of those needed heat it triggered the boiler.

I have seen that this seems to be doable in FHEM? I have the following questions.

Where do I actually put this code?

Can my code be triggered by an event from one of those stats? I.e change of set temperature or changing of room temperature? If so is it a notify that is used?

Do I need to setup a notify for each stat? Or can one monitor all of them?

Beta-User

Welcome to the FHEM forum!

Zitat von: andyBex0791 am 12 November 2024, 11:06:20Where do I actually put this code?
Most likely you do not have to put any own code to pull the MAX devices. To get these as FHEM entities, you just can use the MAX modules - afaik the versions in https://forum.fhem.de/index.php?msg=1092466 should be recommended.

For triggering the boiler, you can indeed use e.g. one notify with some lines of code to loop over all of your MAX devices. (As always in FHEM, there are a bunch of other options to achieve the same result, but that's the most "basic" or "generic" way).
The needed regex will be dependent on your naming scheme, so let us go on as soon as you have your MAX devices in FHEM.

As a starting point, I'd recommend to have a short look at https://wiki.fhem.de/wiki/Quick-Start/en and the links there.
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

andyBex0791

Thanks that's cleared some things up.

So can I assign the wall stats to a group and create a notify for that group?

If so then I would put some code in the DEF to evaluate the set temps vs the actuals? ReadingsVal? If one of them is below the set temp then switch on the boiler?

Beta-User

Zitat von: andyBex0791 am 12 November 2024, 20:50:40So can I assign the wall stats to a group and create a notify for that group?
Imo you don't need no "group", a suitable regex for the notify should do that kind of job as well. (If there exists some kind of "grouping" function in the MAX ecosystem, you may check the MAX- commandref, -FHEM-Wiki and forum area for infos how to do that).

Zitat von: andyBex0791 am 12 November 2024, 20:50:40If so then I would put some code in the DEF to evaluate the set temps vs the actuals? ReadingsVal? If one of them is below the set temp then switch on the boiler?
ReadingsVal()/ReadingsNum() (see Perl Specials in commandref) might be a good starting point.

Note: For getting a consolidated view on heating demands, you may also have a look at VALVES (start at https://forum.fhem.de/index.php?topic=131849.0).
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

andyBex0791

Hi i am trying to bumble my way through this. I have a couple of questions.

My device naming convention is as follows.

MAX_<device type>_<room>
MAX_Wall_Lounge

So I setup a notify to test
triggering as follows.

Define n1 notify MAX_Wall_.* Log 3 "Hello World"

This works but puts approx 10-15 entries in the log.
So then I was trying to workout where those rows are triggered is it all the devices or a row for every row of data received from the update?

As after one or two times of this it then runs out of credit..

How can I print to the log triggering device details so I can work forward?

https://forum.fhem.de/index.php?topic=11974.0

I have seen the abive but it uses a notify for every room. I could use this directly assuming it works but it seems cumbersome on code.

You had mentioned regexp could be used. Could you expand on that please? I have read the regexp documentation but

i can't work out how to build so that I can achieve the desired.

I am a looking to trigger my code based onthe following events
desiredTemperate change and Temperature change only.

I apologise if I have missed some info but I have googled èto this point to try to move forward to no avail.

Actually to the point of looking at purchasing a new system as I know the MAX is old now. But apeart from the cube everything is stll working fine. And I have lots of spare components.

Thanks

rudolfkoenig

ZitatHow can I print to the log triggering device details so I can work forward?
The most relevant ist probably $EVENT and $NAME, for details see https://fhem.de/commandref_modular.html#notify
But IMHO is easier to follow the events in the FHEMWEB Event Monitor, and filter for the device or the event there.
You can even create your notify there by selecting the whole event and clicking on "Create/Modify Device".

ZitatI am a looking to trigger my code based onthe following events desiredTemperate change and Temperature change only.
That would be MAX_Wall_.*:(desiredTemperate|Temperature):.*, e.g.
defmod n1 notify MAX_Wall_.*:(desiredTemperate|Temperature):.* { Log 1, "EVENT from $NAME: $EVENT. Word #2 is $EVTPART1" }

You can access the Readings via ReadingsVal/ReadingsNum, for more detail see https://fhem.de/commandref_modular.html#perl

andyBex0791

Thanks so much that has really helped me progress my knowledge. I have been able to try lots of differing variations on the code provided. this has lead me to the conclusion that the the events are triggered regardless of if they actually changed. I will open another question in the MAX section as this may be unique to MAX devices.

Once again thankyou so much.

Beta-User

Most modules are triggering events when new messages arrive, here by rf.

See esp. event-on-change attribute how to reduce events.
Server: HP-elitedesk@Debian 12, aktuelles FHEM@ConfigDB | CUL_HM (VCCU) | MQTT2: MiLight@ESP-GW, BT@OpenMQTTGw | MySensors: seriell, v.a. 2.3.1@RS485 | ZWave | ZigBee@deCONZ | SIGNALduino | MapleCUN | RHASSPY
svn: u.a MySensors, Weekday-&RandomTimer, Twilight,  div. attrTemplate-files

andyBex0791

Thanks I spent ages trying to workout why my notify was being triggered by other updates. I never even considered coming at it from the device side.

Prof. Dr. Peter Henning

#9
Have a look at the event monitor (button left menu) to see which event are generated. If you activate a filter in the event monitor, you can concentrate on the device in question. Moreover, you may generate a notify by directly selecting one of the desired event lines.

Concerning the question where to put your own code: You always have to distinguish between Perl code and FHEM scripting code. The real magic of FHEM is unlocked if you learn how to combine these two.

In particular, if you have something like
define mynotify1 notify <regex> <code>the latter is assumed to be FHEM scripting code (and stored in the fhem.cfg file, or its database version).

define mynotify2 notify <regex> {<code>}the latter is assumed to be Perl code. While smaller pieces can also be part of the definition (and therefore reside in the fhem.cfg file), you should think of writing longer Perl code in the file 99_myUtils.pm in the module directory.

This allows you to write really complex handling routines, taking the events apart, adding external conditions (time? daylight?) and then performing FHEM magic using the Perl function fhem(<code>), where the enclosed code is again FHEM scripting.

You might be reluctant to get into Perl programming. But let me tell you: I have written several books on programming languages, and fancy myself to know most of them to at least a certain degree. Perl as a programming language is quite old (fashioned). But still one of the most useful tools around.

Regards

pah