Write Modubs register after (re)connect

  • Platform information:
    Raspberry PI 4 with the newes raspbian version and openjdk version "1.8.0_152
    • openHAB version: 2.5.7-1
  • Issue of the topic: i use a Beckhoff Modbus Interface to Control my Lights. The Interface is working, but it needs as first command after powreup the configuration of the watchdog. at the moment after a powercycle i must stop openhab2, configure with a external tool the Watchdog and restart openhab2 again.
    My idea was to create a Roule, which describes the necessary register after (RE)connecting. unfortunately I can’t find the right event. can someone give me a short example how this works or suggest an alternative?

many thanks

Maybe you can explain what you need actually need to do, in Modbus terms. Write some magic code to a particular register?

Again, you’ll have to provide some detail.
In order to run such a rule, openHAB would need to know when to run it.
Is there some way for openHAB to detect when this device is turned on?
Or must it blindly try from time to time? Will it be able to detect when it has worked, and stop trying? Will it know when it has been turned off, to start trying again?

Sorry for the less Details, but all other is not my Problem.
In one Controller Register is the value 1 after the reboot. 1 meens to invert a 0/1 value in an other Register each 0,x Seconds, If not the Controller stops working. If this Happens, Sendung an acknowledge To an 3rd Register is required. This watchdog function can be disabled by writing 0 in the First watchdigregister. that’s what i want to do. Writing 0 in this Register is not my Problem. Just the Event. My Idea was to send 0 in this Register If openhub connets to This device. This works if i reboot all or If only the Beckhoff Controller was rebooted. So Back to the Questionen. Hase openhub an Event by Connection Things? If yes i can weiter 0 to the Item “disable_watchdog”.

Only “kind of”, for Modbus.
Let’s look at how Modbus works.
openHAB is a Modbus master, your PLC is a slave.
A Modbus slave never talks unless it is spoken to. Your PLC cannot announce "here I am’.
So openHAB can never know if a slave is turned on or not unless it tries to read something from it, polls it.

So you are going to have to poll your slave in some way.
Probably you have “normal” read polls of various registers that will do for this purpose.
If the read poll fails, because the PLC is switched off, it will generate a timeout error at openHAB’s end.
The read error will cause openHAB’s Thing to go OFFLINE with an error.
The read poll will continue to be carried out, logging new errors every time.

If the PLC is eventually switched back on, presumably the read poll will then succeed? I don’t know, does it work before you have done this watchdog write business??
If the read poll does work, openHAB will change the Thing status from OFFLINE to ONLINE.
A rule can look for that change, it indicates your PLC has come online again.
That rule can do whatever write it is that you want.

If you have other Modbus devices as well, beware that continual errors on one device can badly effect performance of any remaining devices.
You probably ought to understand this post about the effects.
It also shows an example of a rule acting on Thing status changes.

You might also have to think about what you would like to happen if some other kind of real error causes your Thing to go OFFLINE.