MichielVanwelsenaere/HomeAutomation.CoDeSys3

Feature request: basic function block: FB_INPUT_MOTIONSENSOR_MQTT

ArjanM83 opened this issue · 10 comments

When testing the Panasonic AMN31112J motion sensor I noticed that the output changes to HIGH when motion is detected. But quickly again it goes back to LOW, and it fluctuates quickly in situations of change. When a person walks into a room this could result in 10-100 times HIGH within a couple of seconds.

To avoid excessive traffic between the PLC and the MQTT broker, it would be nice to have a basic function block designed specific for motion sensors. The following rules could be an example of its behaviour:

  • When LOW and detecting motion the state becomes HIGH.
  • When no motion has been detected for at least 5 seconds the state becomes LOW.
    The number of seconds could be provided as a parameter of the function block.

@MichielVanwelsenaere has referred to the concept of hysteresis.

Thanks for the feedback with your findings! Would it also make sense to you to implement an additional parameter to the binary sensor FB that allows for configurable hysteresis on the output?

What are you by the way using to transform the 5V signal from the motion sensor to something the PLC can read?

Would it also make sense to you to implement an additional parameter to the binary sensor FB that allows for configurable hysteresis on the output?

Can you provide an example of how this would work?

What are you by the way using to transform the 5V signal from the motion sensor to something the PLC can read?

I'm using the Wago 753-434 with 8 digital inputs, receiving power from the 750-612, wired to an external power supply (5v DC).

I would create a method 'ConfigureFunctionBlock' that can be called like below:

FB_MOTION_001.ConfigureFunctionBlock(hysteresis:=T#5S)

by default it would be disabled, by calling the method it would be configured (only required once during startup).
Behavior in this case would be that the output remains high for 5 seconds after the last input pulse.
For example: if you have 20 pulses over a period of 5 seconds, the output would be high for 10 seconds.

Let me know your thoughts!

Behavior in this case would be that the output remains high for 5 seconds after the last input pulse.
For example: if you have 20 pulses over a period of 5 seconds, the output would be high for 10 seconds.

Implementation and behavior sounds good!

I enhanced the binary sensor input FB so it can be configured with a 'turnoffdelay'.
Code can be found here; link
Updates docs can be found here; link

But in short, the below is what you need to add:
FB_INPUT_BINARYSENSOR_MQTT.ConfigureFunctionBlock(T_TurnOffDelay:= T#5S);

Could you let me know when you've found some time to test this and the implementation is behaving as you would expect so I can merge this to the master branch?

Thanks for your quick update!

The code and docs look good. After my recent tests I have 'dismantled' my PLC test situation. My plan is to continue testing again at the end of the year. My project is long term, the house to implement this project in will be finished in 2021 or 2022.

Maybe @DomiGijzen could test the new functionality? Just an idea, I don't know if he has time available..

I have a similare use in my project and used a near identical FB like that .
So it was a drop in replacement and work as expercted for me.
Thank you very much for the work

Perfect! Thanks for checking!

I saw someone checked. Git to it just today and it is also working in my code. Tnx!