Modbus write back delay

Hi all, I have had this flow implemented for a while for my air condition integration and thought it was working but found that under some situations it gets in to a re write loop some how, I think it might be because Modbus polls every 5 seconds and the the automation system is witting back changes too quickly to the air con when the user maybe still selecting what setting they want.
This happens only when the user is using the wall controller.

I though maybe this could be fixed by altering the write flows to have a delay that waits for x amount of time to pass without new changes then pass the write command on out to Modbus. This would ensure the user has finished selection the modes and fan speed ect.

[{"id":"bb45bf76.08d16","type":"modbus-read","z":"8ed5f9cc.f21988","name":"AirCon Indoor Temp","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"InputRegister","adr":"0","quantity":"1","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"496a1d37.f41384","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":190,"y":520,"wires":[["ee558b4c.cbcb08"],[]]},{"id":"496a1d37.f41384","type":"modbus-client","name":"Air Con","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"COM1","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true}]

Any ideas on a simple fix?
Thanks

You have only exported one node, so that doesn't give us much to go on.

When it gets into a loop have you identified the nodes involved in the loop? If not then add some debug nodes to work that out. The first requirement when trying to fix a problem is to work out what is the cause.
Please post that part of the flow please (the nodes involved in the loop) so we can suggest what could be going on.

Woops sorry about that hopefully I have copied it correctly this time.

Maybe the way I explained it was not very good, A different way to understand it would be ...
Any changes on the Modbus system are read by the MQTT and the send to Homeseer then those updated changes in Homeseer are written back to MQTT and then Back to Modbus.
So I think the changes are getting written back to quickly , This i why i thought a delay in written the changes back to Modbus would over come the problem.

[{"id":"8ed5f9cc.f21988","type":"tab","label":"AirCon","disabled":false,"info":""},{"id":"d60bd3c2.74331","type":"modbus-read","z":"8ed5f9cc.f21988","name":"AirCon On/Off Read","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"Coil","adr":"0","quantity":"1","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"496a1d37.f41384","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":190,"y":160,"wires":[["d59bf820.2b2d48"],[]]},{"id":"1bf5fde.8cbfb02","type":"mqtt out","z":"8ed5f9cc.f21988","name":"AirCon On Off","topic":"AirCon/OnOff","qos":"","retain":"","broker":"502e6de5.e10924","x":700,"y":140,"wires":[]},{"id":"1a099064.1564","type":"modbus-response","z":"8ed5f9cc.f21988","name":"","registerShowMax":20,"x":710,"y":200,"wires":[]},{"id":"48d53567.8ada8c","type":"mqtt out","z":"8ed5f9cc.f21988","name":"AirCon Fan","topic":"AirCon/FanSpeed","qos":"","retain":"","broker":"502e6de5.e10924","x":690,"y":260,"wires":[]},{"id":"8ebe10eb.24fbb","type":"modbus-read","z":"8ed5f9cc.f21988","name":"AirCon Fan Read","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"2","quantity":"1","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"496a1d37.f41384","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":180,"y":280,"wires":[["3b92cca5.afa794"],[]]},{"id":"b79f7224.b31f3","type":"modbus-response","z":"8ed5f9cc.f21988","name":"","registerShowMax":20,"x":710,"y":320,"wires":[]},{"id":"6a1294b1.15619c","type":"mqtt out","z":"8ed5f9cc.f21988","name":"AirCon Mode","topic":"AirCon/Mode","qos":"","retain":"","broker":"502e6de5.e10924","x":690,"y":380,"wires":[]},{"id":"3370b628.1ca73a","type":"modbus-read","z":"8ed5f9cc.f21988","name":"AirCon Mode","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"1","quantity":"1","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"496a1d37.f41384","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":170,"y":400,"wires":[["c394546.84911a8"],[]]},{"id":"805563b2.ee85d","type":"modbus-response","z":"8ed5f9cc.f21988","name":"","registerShowMax":20,"x":710,"y":440,"wires":[]},{"id":"3f8d51ea.63242e","type":"mqtt out","z":"8ed5f9cc.f21988","name":"AirCon Indoor Temp","topic":"AirCon/CurrentIndoorTemp","qos":"","retain":"","broker":"502e6de5.e10924","x":720,"y":500,"wires":[]},{"id":"bb45bf76.08d16","type":"modbus-read","z":"8ed5f9cc.f21988","name":"AirCon Indoor Temp","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"InputRegister","adr":"0","quantity":"1","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"496a1d37.f41384","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":190,"y":520,"wires":[["ee558b4c.cbcb08"],[]]},{"id":"6d3e7dd4.806384","type":"modbus-response","z":"8ed5f9cc.f21988","name":"","registerShowMax":20,"x":710,"y":560,"wires":[]},{"id":"f6572434.554e28","type":"mqtt out","z":"8ed5f9cc.f21988","name":"AirCon Set Point","topic":"AirCon/SetPoint","qos":"","retain":"","broker":"502e6de5.e10924","x":710,"y":620,"wires":[]},{"id":"e0edc941.532918","type":"modbus-read","z":"8ed5f9cc.f21988","name":"AirCon Set Point","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"0","quantity":"1","rate":"5","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"496a1d37.f41384","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":180,"y":640,"wires":[["51b3e82d.90d3b8"],[]]},{"id":"6383c2eb.0ec62c","type":"modbus-response","z":"8ed5f9cc.f21988","name":"","registerShowMax":20,"x":710,"y":680,"wires":[]},{"id":"703666b6.354628","type":"mqtt in","z":"8ed5f9cc.f21988","name":"","topic":"AirCon/SetFan","qos":"2","datatype":"auto","broker":"502e6de5.e10924","x":160,"y":760,"wires":[["770b11bd.94edd"]]},{"id":"770b11bd.94edd","type":"modbus-write","z":"8ed5f9cc.f21988","name":"","showStatusActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"2","quantity":"1","server":"496a1d37.f41384","emptyMsgOnFail":false,"keepMsgProperties":false,"x":460,"y":760,"wires":[[],["c21ab30a.63deb"]]},{"id":"b5be0e54.78bfb","type":"mqtt in","z":"8ed5f9cc.f21988","name":"","topic":"AirCon/SetMode","qos":"2","datatype":"auto","broker":"502e6de5.e10924","x":160,"y":840,"wires":[["c854674a.1d7e18"]]},{"id":"c854674a.1d7e18","type":"modbus-write","z":"8ed5f9cc.f21988","name":"","showStatusActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"1","quantity":"1","server":"496a1d37.f41384","emptyMsgOnFail":false,"keepMsgProperties":false,"x":460,"y":840,"wires":[[],["943382c1.a7cfb"]]},{"id":"ee558b4c.cbcb08","type":"change","z":"8ed5f9cc.f21988","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":520,"wires":[["3f8d51ea.63242e","6d3e7dd4.806384"]]},{"id":"51b3e82d.90d3b8","type":"change","z":"8ed5f9cc.f21988","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":640,"wires":[["f6572434.554e28","6383c2eb.0ec62c"]]},{"id":"c394546.84911a8","type":"change","z":"8ed5f9cc.f21988","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":400,"wires":[["6a1294b1.15619c","805563b2.ee85d"]]},{"id":"3b92cca5.afa794","type":"change","z":"8ed5f9cc.f21988","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0]","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":280,"wires":[["48d53567.8ada8c","b79f7224.b31f3"]]},{"id":"d59bf820.2b2d48","type":"change","z":"8ed5f9cc.f21988","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload[0] = true ? 1 : 0\t\t  ","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":160,"wires":[["1a099064.1564","1bf5fde.8cbfb02"]]},{"id":"c21ab30a.63deb","type":"modbus-response","z":"8ed5f9cc.f21988","name":"","registerShowMax":20,"x":710,"y":760,"wires":[]},{"id":"36b74a10.5ad066","type":"modbus-response","z":"8ed5f9cc.f21988","name":"","registerShowMax":20,"x":970,"y":1000,"wires":[]},{"id":"943382c1.a7cfb","type":"modbus-response","z":"8ed5f9cc.f21988","name":"","registerShowMax":20,"x":710,"y":840,"wires":[]},{"id":"b2c529dc.a5df08","type":"mqtt in","z":"8ed5f9cc.f21988","name":"","topic":"AirCon/SetSetPoint","qos":"2","datatype":"auto","broker":"502e6de5.e10924","x":170,"y":920,"wires":[["2efb2bbd.4cae54"]]},{"id":"2efb2bbd.4cae54","type":"modbus-write","z":"8ed5f9cc.f21988","name":"","showStatusActivities":false,"showErrors":false,"unitid":"","dataType":"HoldingRegister","adr":"0","quantity":"1","server":"496a1d37.f41384","emptyMsgOnFail":false,"keepMsgProperties":false,"x":460,"y":920,"wires":[[],["e765f2f6.d0171"]]},{"id":"e765f2f6.d0171","type":"modbus-response","z":"8ed5f9cc.f21988","name":"","registerShowMax":20,"x":710,"y":920,"wires":[]},{"id":"53d01ff.3b633e","type":"modbus-flex-write","z":"8ed5f9cc.f21988","name":"","showStatusActivities":false,"showErrors":false,"server":"496a1d37.f41384","emptyMsgOnFail":false,"keepMsgProperties":false,"x":710,"y":1000,"wires":[[],["36b74a10.5ad066"]]},{"id":"4f69880f.a81568","type":"function","z":"8ed5f9cc.f21988","name":"","func":"msg.payload = { \n    value: Number(msg.payload), \n    'fc': 5, \n    'unitid': 1, \n    'address': 0 , \n    'quantity': 1     \n} \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":1000,"wires":[["53d01ff.3b633e"]]},{"id":"a05adb5.ff5ef28","type":"mqtt in","z":"8ed5f9cc.f21988","name":"","topic":"AirCon/SetOnOff","qos":"2","datatype":"auto","broker":"502e6de5.e10924","x":160,"y":1000,"wires":[["4f69880f.a81568"]]},{"id":"496a1d37.f41384","type":"modbus-client","name":"Air Con","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"COM1","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectOnTimeout":true,"reconnectTimeout":2000,"parallelUnitIdsAllowed":true},{"id":"502e6de5.e10924","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

I still don't fully understand. Can you work through an example with actual device name (aircon for example) and relate that to the flow you posted?

Yep sure , In the flow you will see a set of write functions and read functions , If we take just the fan read and fan set functions for example.

When I change the fan speed on the wall controller on the air con lets say form speed 3 to 2 and then to 1
the Modbus system will write that change to homeseer via Node Red and MQTT and when it does change the value in Homeseer that value is then sent back via MQTT and Node Red to Modbus through the FanSet write functions.

But because of the 5 seconds delay in the Modbus updates times modbus some times will read speed 2 as I went from 3 to 2 then to 1 and update Homeseer with speed 2 not the speed I actually selected. Then of course it update the Air con to speed 2 not 1 as its syncs back.

My through was to delay the changes read from Modbus in Node Red To the latest value that has not changed for say 10 sec then send that value to MQTT and on to Homeseer to insure the vaule the user has selected on the wall controller is then sent to Homeseer.

This scenario could happen on all functions.

Home this make's sense.

Let me pick that apart a bit more.

  1. You change the fan speed on the wall controller.
  2. Node red polls the speed controller via modbus
  3. Node-red publishes the new speed to AirCon/FanSpeed
  4. I am not sure about this bit, but I think you mean that Homeseer sees the new speed as it is subscribed to that topic.
  5. This is where I get lost. I think you are saying that Homeseer then writes it back to MQTT topic AirCon/SetFan. Why does it do that? Can you stop that from happening?

Yes that is correct
5, homeseer writes changes via the write nodes back to air con controller so that when users are using the Web interface or app the changes are sent.

Are you sure that you have got homeseer setup with the right topics? It sounds as if you have told it that the fanspeed topic is the topic used to request a fanspeed rather than the one telling it that the fan is now running at that speed.

However there is a solution. That is to feed both the fanspeed and the setfan topics into a Join node set to key/value pair so you can get an output whenever either one of them changes. Then when a setfan message arrives only pass it to aircon unit if the value differs from the current speed. Then the operation will be as follows, starting at item 5 in the sequence above.
5. Homeseer publishes a setfan request for the speed that it has just been told about
6. The new logic will see that the speed is already set to that value and will ignore the setfan request.

Are you able to code that suggestion up to try it or do you need some help with it? If you haven't used a Join node in that way then see this article in the cookbook for an example of how to join messages into one object.

Thanks for that idea, I will give that a go and let you know how i get on.

I still think there must be a way of preventing Homeseer from publishing a fanset when it is told that the fan is already at that speed.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.