Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Controllers
  3. OpenHAB
  4. OpenHab Tests

OpenHab Tests

Scheduled Pinned Locked Moved OpenHAB
6 Posts 2 Posters 2.4k Views 4 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SoloamS Offline
    SoloamS Offline
    Soloam
    Hardware Contributor
    wrote on last edited by
    #1

    Hello, I mounted a OpenHab machine in a test environment (so I can test my scenarios before going into production). In my system I have OpenHab up and running and MQTT running and working! I made a small button to test the MQTT and it worked:

    Switch mySwitch {mqtt=">[mybroker:/myhouse/office/light:command:ON:1],>[mybroker:/myhouse/office/light:command:OFF:0]"}
    

    I'm using MQTT.fx to capture the MQTT requests, and when i toggle the button on I get "/myhouse/office/light 1" and when I toggle it off "/myhouse/office/light 0". So far so good.

    The problem is when I push a notification, OpenHab does not capture the request because the switch is set to "Outbound (>)". If I set it to "Inbound (<)" and I push a request I can see the button changing, but now if I press the button no request is generated.

    How can I solve this? I made a change to the code to become:

    Switch mySwitch {mqtt=">[mybroker:/myhouse/office/lightin:command:ON:1],>[mybroker:/myhouse/office/lightin:command:OFF:0],<[mybroker:/myhouse/office/lightout:command:ON:1],<[mybroker:/myhouse/office/lightout:command:OFF:0]"}
    

    This worked, I push the button and a request is generated, I push a notification and the button changes, but I don't know if this is the best solution. (side note, I used "lightin" and "lightout" because if I set the same name in the vars I would get a infinite loop).

    Thank you all!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbj
      wrote on last edited by
      #2

      You may find it useful to take a look at the definitions Openhab MQTT bindings: https://github.com/openhab/openhab/wiki/MQTT-Binding.

      The format for inbound and outbound messages are different. In your incoming definitions there is a transformation of "ON" or "OFF" and there is a regex filter of "1" or "0" so the question is if these definitions can be used for anything (incoming is "direction, broker, topic, type, transformation, regexfilter"

      It is a bit difficult to understand what you mean by "The problem is when I push a notification", from where do you push something, in what format and what shall it be used for? Type for Openhab messages which can be bound to an item is either a state change or a command´,

      1 Reply Last reply
      0
      • SoloamS Offline
        SoloamS Offline
        Soloam
        Hardware Contributor
        wrote on last edited by
        #3

        Hello I have replaced the code with

        Switch node2_sw2  "sw2 send + recieve example"  (node2,all)      {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:ON:1],>[mysensor:MyMQTT/21/2/V_LIGHT:command:OFF:0],<[mysensor:MyMQTT/21/2/V_LIGHT:command:MAP(1on0off.map)]"}
        

        But the problem persists, the map function keeps sending the same request over and over again, If I make a click in a few seconds my mqtt client is full of requests, over 500 with the same message. Wasn't it supposed to send only one message for click?

        M 1 Reply Last reply
        0
        • SoloamS Soloam

          Hello I have replaced the code with

          Switch node2_sw2  "sw2 send + recieve example"  (node2,all)      {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:ON:1],>[mysensor:MyMQTT/21/2/V_LIGHT:command:OFF:0],<[mysensor:MyMQTT/21/2/V_LIGHT:command:MAP(1on0off.map)]"}
          

          But the problem persists, the map function keeps sending the same request over and over again, If I make a click in a few seconds my mqtt client is full of requests, over 500 with the same message. Wasn't it supposed to send only one message for click?

          M Offline
          M Offline
          mbj
          wrote on last edited by
          #4

          @soloam Your binding actually is:

          Switch node2_sw2 "sw2 send + recieve example" (node2,all) {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:ON:1]}
          Switch node2_sw2 "sw2 send + recieve example" (node2,all) {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:OFF:0]}
          Switch node2_sw2 "sw2 send + recieve example" (node2,all) {mqtt="<[mysensor:MyMQTT/21/2/V_LIGHT:command:MAP(1on0off.map)]"}

          Not that it matters for your problem but the first two I think can be replaced with:

          Switch node2_sw2 "sw2 send + recieve example" (node2,all) {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:*:default]}

          This is what I think happens: When you toggle the switch in Openhab to ON this is placed on the bus and sent as a MQTT message. The third definition binds exactly the same item to an inbound command so then Openhab reads it executes this command which is put on bus and the is read again by the incoming binding and so on. Effectively you have created a loop by adding the 3rd binding to the first two.

          One solution is to use two switches, one for incoming commands and one for outgoing, like this:

          Switch node2_sw2-1 "sw2 send example" (node2,all) {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:*:default]}
          Switch node2_sw2-2 "sw2 recieve example" (node2,all) {mqtt="<[mysensor:MyMQTT/21/2/V_LIGHT:command:default]}

          Then you use the first one to trigger outbound messages and the second one to read incoming. If you want to see the current state of the lamp (the first switch) in openhab you can use a rule to set that according to changes made by any incoming message.

          I do not know if this is the way but I think it will work.

          1 Reply Last reply
          0
          • SoloamS Offline
            SoloamS Offline
            Soloam
            Hardware Contributor
            wrote on last edited by
            #5

            Found the solution tanks to watou user in OpenHab Forum.

            Switch node2_sw2  "sw2 send + recieve example"  (node2,all)	  {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:OFF:0],>[mysensor:MyMQTT/21/2/V_LIGHT:command:ON:1],<[mysensor:MyMQTT/21/2/V_LIGHT:state:MAP(1on0off.map)]"}
            

            The secret is in the :state: declaration on the MAP!

            Thank you all

            M 1 Reply Last reply
            0
            • SoloamS Soloam

              Found the solution tanks to watou user in OpenHab Forum.

              Switch node2_sw2  "sw2 send + recieve example"  (node2,all)	  {mqtt=">[mysensor:MyMQTT/21/2/V_LIGHT:command:OFF:0],>[mysensor:MyMQTT/21/2/V_LIGHT:command:ON:1],<[mysensor:MyMQTT/21/2/V_LIGHT:state:MAP(1on0off.map)]"}
              

              The secret is in the :state: declaration on the MAP!

              Thank you all

              M Offline
              M Offline
              mbj
              wrote on last edited by
              #6

              @soloam Yes, the state makes the difference of course. Because you had used command for all definitions I assumed that your intention was to also send in a command from outside of Openhab to control the light.
              Glad you found a solution.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              31

              Online

              11.7k

              Users

              11.2k

              Topics

              113.1k

              Posts


              Copyright 2025 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • MySensors
              • OpenHardware.io
              • Categories
              • Recent
              • Tags
              • Popular