<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[openhab sendCommand problem with serialbinding (Solved)]]></title><description><![CDATA[<p dir="auto">Hello</p>
<p dir="auto">I did not find the solution for the loopback problem:</p>
<p dir="auto">when I use sendCommand with serialbinding the message is sent to the gateway.<br />
but at the same time this message is presented as an incoming message to openhab.</p>
<p dir="auto">so this message is processed again and creates a deathloop.</p>
<p dir="auto">I tried to move the sendCommand from the processing incoming message rule to a separate one<br />
but the problem is the same. With this new code I use cron so the message does not come immediately<br />
but the loop is still here.</p>
<p dir="auto">I could set up a workaround but I would like to know if there is a clean solution ?<br />
Is it the way the rule are working ?  Is it due to serialbinding ?   I tried to have a look at the serial binding code<br />
but did not find what could create the loopback.</p>
<p dir="auto">Help help        thank you for your support !</p>
<p dir="auto">here is the code :</p>
<pre><code>//receiving msg from mysensors gateway
rule "Arduino sends to Openhab"
    when
        Item Arduino received update
    then
        var String lineBuffer =  Arduino.state.toString.split("\n")
        for (String line : lineBuffer) {
            var String[] message = line.split(";")
            var Integer nodeId = new Integer(message.get(0))
            var Integer childId = new Integer(message.get(1))
            var Integer msgType = new Integer(message.get(2))
            var Integer ack = new Integer(message.get(3))
            var Integer subType = new Integer(message.get(4))
            var String msg = message.get(5)
      
            // Internal Command
            if ( msgType == C_INT ){
                 if(subType == I_TIME ){ 
                        println("Time request from node : " + nodeId)   
                        timeToNodeId = nodeId
                        sendTime = 1
                  }              
            }
        }
end
//
//
//
rule "send time"
when
               Time cron "0 * * * * ?"
then
               if (sendTime == 1) {
                   var Integer time2 = now().getMillis()/1000 +7200
                   sendCommand(Arduino, timeToNodeId+";255;3;0;1;" + time2+"\n") 
                   sendTime = 0 
               }       
end
</code></pre>
]]></description><link>https://forum.mysensors.org/topic/1224/openhab-sendcommand-problem-with-serialbinding-solved</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 05:14:36 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/1224.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 08 Apr 2015 19:21:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to openhab sendCommand problem with serialbinding (Solved) on Sun, 04 Oct 2015 15:40:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/shasha" aria-label="Profile: Shasha">@<bdi>Shasha</bdi></a>, have you tried this? <a href="https://github.com/openhab/openhab/wiki/Rules#concurrency-guard" rel="nofollow ugc">https://github.com/openhab/openhab/wiki/Rules#concurrency-guard</a></p>
<p dir="auto">I'm currently trying the same (because I have the same issue) and wondering if you tried this before.</p>
]]></description><link>https://forum.mysensors.org/post/22212</link><guid isPermaLink="true">https://forum.mysensors.org/post/22212</guid><dc:creator><![CDATA[Dave Dan]]></dc:creator><pubDate>Sun, 04 Oct 2015 15:40:54 GMT</pubDate></item><item><title><![CDATA[Reply to openhab sendCommand problem with serialbinding (Solved) on Fri, 10 Apr 2015 17:55:55 GMT]]></title><description><![CDATA[<p dir="auto">Thank you for the info</p>
<p dir="auto">so all the sendCommand to Arduino I will initiate will be seen again when using a trigger like "Arduino received update".</p>
<p dir="auto">The workaround I was thinking is the one you suggested. That is to say to check the payload of the incoming message.</p>
<p dir="auto">So this problem is solved   !</p>
<p dir="auto">Thank you !</p>
]]></description><link>https://forum.mysensors.org/post/12585</link><guid isPermaLink="true">https://forum.mysensors.org/post/12585</guid><dc:creator><![CDATA[shasha]]></dc:creator><pubDate>Fri, 10 Apr 2015 17:55:55 GMT</pubDate></item><item><title><![CDATA[Reply to openhab sendCommand problem with serialbinding (Solved) on Thu, 09 Apr 2015 11:45:39 GMT]]></title><description><![CDATA[<p dir="auto">OpenHAB is using a message bus and every message send to that bus is received by every one/rule.<br />
Simply moving the code will not help.</p>
<p dir="auto">I think the best way is to differentiate between the request and answer(sendCommand).</p>
<p dir="auto">Currently the rule is triggered whenever a message with "subType == I_TIME" is received by openHAB.</p>
<pre><code>if(subType == I_TIME ){ 
                        println("Time request from node : " + nodeId)   
                        timeToNodeId = nodeId
                        sendTime = 1
                  } 
</code></pre>
<p dir="auto">So, in the code above you need to differ between request and answer. I don't know how the request looks like, so I'm only able to give a hint.</p>
<p dir="auto">In the answer the payload of the message is the content of "time", something like 1234567. I suppose the payload in the request differs for example in length, it's shorter I suppose.</p>
<p dir="auto">So you could go with:</p>
<pre><code>if(subType == I_TIME ){ 
                        if(msg.length &lt; 1) {
                           sendCommand(Arduino, timeToNodeId+";255;3;0;1;" + time2+"\n")
                        }
                  } 
</code></pre>
<p dir="auto">I hope this helps.</p>
]]></description><link>https://forum.mysensors.org/post/12554</link><guid isPermaLink="true">https://forum.mysensors.org/post/12554</guid><dc:creator><![CDATA[TimO]]></dc:creator><pubDate>Thu, 09 Apr 2015 11:45:39 GMT</pubDate></item></channel></rss>