Difficulties with openhab



  • Hello,

    I am trying to use openhab (v1.7) with a serialgateway. hum ... not easy.

    I defined an item file, a sitemap file and a rule file.

    I discovered that we need to code manythings in this rule file.

    So far I have several questions :

    1. when I want to do a postUpdate like : postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), tripped)

    I got this warning message :
    [WARN ] [.c.i.events.EventPublisherImpl] - given new state is NULL, couldn't post update for 'detecteur_hall'

    where does this error come from ? all the parameters are defined and not NULL ....

    1. I am trying to send a message to the gateway like :
      sendCommand(Arduino, nodeId +";255;3;0;1;" + "1496700000\n")

    I want to send the time in response to a time request
    the message is sent to the node great !!! BUTTTTTTTTTTT at the same time it gets to openhab
    then it is processed by the "Arduino sends to Openhab" rule. So it is decoded as a time request and
    sends it again ... here comes the death loop !!!

    Any idea on how to send a message to the network that will not be presented as an incoming message ?
    what do I do wrong here ?

    the Arduino string name has been defined the items file !

    1. is there a time variable containing the time that could be addressed from the rules ?
      haha seems the function now() returns a time value I will continue checking this !

    Thanks for your help.


  • Hero Member

    1. I had the same problem and needed some time to figure it out. My working rule looks like:
     if (subType == V_TRIPPED){
                        println ("Window item: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " status: " + Integer::parseInt(msg) )
                        if(Integer::parseInt(msg) == 1) {
                                                    postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), "OPEN")                    }
                        if(Integer::parseInt(msg) == 0) {
                            postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), "CLOSED")
                        }
                    }
    
    1. Show us the rule set you currently use, we need to find a way to differentiate between sending and receiving with the same nodeId and childId.. I don't had this problem yet, my combination of nodeId + childId is either sending or receiving.


  • Here are the two pieces of code :

                      if (subType == V_TRIPPED) {
                        var String tripped="OFF"
                        if (msg=="1"){
                            tripped="ON"
                        }
                        postUpdate(sensorToItemsMap.get( nodeId + ";" + childId + ";"), tripped)
                        println ("Unit: " + sensorToItemsMap.get( nodeId + ";" + childId + ";") + " etat: " + tripped )
    
    

    ah seems you solved one of my problems. If I change ON to OPEN and OFF to CLOSED it works !

    if(subType == I_TIME){ 
                            println("Time request" )  
                            sendCommand(Arduino, nodeId +";255;3;0;1;" + "1496700000\n")  // dummy time value
                        }
    


  • Regarding the time variable question I made some progress :

    var Integer time = now().getMillis()/1000    // I get the millisecondes then divide by 1000 hence the seconds
    println(nodeId +";255;3;0;1;" + time +"\n"    //  print to see the command to send
    

    this works fine I go the time in seconds from 1970. But I need to consider the timezone and the summer time.
    So I added :
    time = time + 7200 and then I get
    [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule 'Arduino sends to Openhab': Could not invoke method: org.eclipse.xtext.xbase.lib.IntegerExtensions.operator_plus(int,int) on instance: null

    wow !!! for a simple add any clue ?

    well I decided to add the 7200 that way : var Integer time = now().getMillis()/1000 +7200
    and it works. very very strange. so now the code is :

    var Integer time = now().getMillis()/1000 + 7200    //convert the millis & add the offset for time zone and summer time
    println(nodeId +";255;3;0;1;" + time +"\n"    //  print to see the command to send
    

    The major problem is still the death loop with the
    sendCommand(Arduino, nodeId +";255;3;0;1;" + time+"\n")

    have you noticed this? seems there is a loopback in the serialbinding. Configurable maybe ?
    I will try to get some doc on this binding. At least the code could give an idea. I will look for it.



  • @Shasha,
    Can you share your rules? I can't send command from openhab to Node, can't control relays
    it's so difficult



  • @kimnguu204 have you managed to control your relays and also to get their status?


Log in to reply
 

Suggested Topics

55
Online

11.4k
Users

11.1k
Topics

112.6k
Posts