MichielVanwelsenaere / HomeAutomation.CoDeSys3

Home Automation system build in CoDeSys 3 with MQTT communication to any third party Home Automation software
MIT License
115 stars 38 forks source link

Add pulse output #67

Closed domoticafan closed 4 years ago

domoticafan commented 4 years ago

First of all, thanks for this great project. I was able to get it work on a 750-8212 without any PLC/e-cockpit knowledge.

Beside the output high/low toggle I would like to control my bi-stable relay which need a pulse signal. So can you add also a 'pulse' output feature? I did some testing with the TOF timer, however I have no idea if this is the best way to do it.

TOFInst(IN := PULSE, PT:= T#1S); OUT := TOFInst.Q;

MichielVanwelsenaere commented 4 years ago

Hi,

Good to hear that you were able to get this working swiftly.

Problem with a bistable relay is that it's not possible to know the state of the relais in the PLC.

So how would you know in your home automation software what the state is of your device?

Technically I can make a pulse output FB, I just don't see how it would work functionally because you don't know the eventual state of the relay?

Let me know your thoughts!

domoticafan commented 4 years ago

I will use an interface relay or aux contact to detect the status of the relay. Yes it is quite 'expensive' to use an extra input for the status. However, in this case I'm able to control the most important lights without any automation (hass/plc/whatever).

MichielVanwelsenaere commented 4 years ago

I'll look into this. Idea would be to create a new FB 'FB_OUTPUT_SWITCH_MQTT' which has configurable pulse duration at the output and can be triggered by:

  1. a pulse on the input
  2. a 'Pulse' MQTT message on the FB 'in' MQTT topic

If the FB generates a pulse on its output it will generate a 'pulse' messsage on the FB 'out' topic.

Sounds good?

primsam commented 4 years ago

Hello,

I think that this would be a very special Solution and not so popular even? Maybe a simple way to do it can be to use the some output from the FB_INPUT_PUSHBUTTON_MQTT and on the feedback the FB_INPUT_BINARYSENSOR_MQTT to check the state of the relay.

like so : In the writeSwitches section TOFinst(IN:=FB_DI_PB_001.SINGLE(*Or Whatever you want to use*) , PT:= T#1S, Q=> YOUROUTPUT(*to the physical output*));

_Corresction...sorry i have not in mind that the FB_INPUT_PUSHBUTTONMQTT has no Subsription to a Mqtt topic XD

domoticafan commented 4 years ago

I'll look into this. Idea would be to create a new FB 'FB_OUTPUT_SWITCH_MQTT' which has configurable pulse duration at the output and can be triggered by:

1. a pulse on the input

2. a 'Pulse' MQTT message on the FB 'in' MQTT topic

If the FB generates a pulse on its output it will generate a 'pulse' messsage on the FB 'out' topic.

Sounds good?

Sounds good to me.

primsam commented 4 years ago

Hello again

I made some thoughts again mabe it could be useful for someone if there exists a FB_OUTPUT_PB_MQTT? I just tested it and for me it can make sense for some cases . please can someone take a look at it ?

FB_OUTPUT_PB_MQTT.zip

MichielVanwelsenaere commented 4 years ago

Yes, I'll have a look! But if I'm getting things right idea would be to incorporate the bistable relay feedback to the FB so the state is known an you can still send 'ON'/'OFF' MQTT messages to the FB to control the bistable relay?

MichielVanwelsenaere commented 4 years ago

still need to check your codesample but could you both check if this docs page describes the behaviour FB that you require: https://github.com/MichielVanwelsenaere/HomeAutomation.CoDeSys3/blob/feature/FB_OUTPUT_BISTABLE_MQTT/docs/FunctionBlocks/FB_OUTPUT_BISTABLE_MQTT.md

MichielVanwelsenaere commented 4 years ago

@primsam , looking at your FB I see no feedback input. You guys do plan to wire a feedback loop back into the PLC right? If so, I would have a FEEDBACK input in the FB and control the state from in the FB.

domoticafan commented 4 years ago

But if I'm getting things right idea would be to incorporate the bistable relay feedback to the FB so the state is known an you can still send 'ON'/'OFF' MQTT messages to the FB to control the bistable relay?

That's correct.

MichielVanwelsenaere commented 4 years ago

I made a branch that has a FB_OUTPUT_BISTABLE in the codebase. My initial tests indicate that it is working. Can you guys do a test as well? Branch: link FB docs: link

domoticafan commented 4 years ago

Just did some tests and it seems to work correctly. Thanks for the very fast response and fix.

primsam commented 4 years ago

Unfortunately i can not test it becouse i don´t have any hardware for it .