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. Pulse Power Meter with OpenHAB?

Pulse Power Meter with OpenHAB?

Scheduled Pinned Locked Moved OpenHAB
7 Posts 5 Posters 4.9k Views 7 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.
  • T Offline
    T Offline
    TommySharp
    wrote on last edited by
    #1

    Does anyone have the pulse power meter working with OpenHAB?
    As far as I can tell it's not really possible because the sketch is firt looking for a response from the gateway about the KwH used to date or something like that.....

    bklB 1 Reply Last reply
    0
    • mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #2

      (Moved from General discussion to the OpenHAB category)

      1 Reply Last reply
      0
      • T TommySharp

        Does anyone have the pulse power meter working with OpenHAB?
        As far as I can tell it's not really possible because the sketch is firt looking for a response from the gateway about the KwH used to date or something like that.....

        bklB Offline
        bklB Offline
        bkl
        wrote on last edited by
        #3

        @TommySharp

        Hi

        I have it working, using my own binding.

        It is not impossible to read the state of an item in openhab, the difficult part is getting it initialized, and restored when you restart openhab.

        First. You need to define an item (you properly already have that done)
        Second. You need to configure a persistence to restart the value on startup, by adding restoreOnStartup
        Third. You need to initialize the item. The can be done by stating openhab in console mode, and type the command "openhab send <item> <command>", where <command> is is the value you want to set.

        Hope that helps

        1 Reply Last reply
        0
        • J Offline
          J Offline
          joseraj
          wrote on last edited by
          #4

          Hi,

          The default sketch sends a request message :

            // Fetch last known pulse count value from gw
            gw.request(CHILD_ID, V_VAR1);
          

          I'm not able to make Openhab answer gw.request so I have used a rule:

          // This rule Send pulse count on request
          rule "Send On Request"
           when
           Item MyEnergy_Pulse_REQ received update
           then
             var Number Pc = MyEnergy_Pulse_count.state as DecimalType
             postUpdate(MyEnergy_Pulse_Restore, Pc)
          end
          

          I have defined the items:

          • Item to store the pulse counts. This is the info of interest for us.
          Number MyEnergy_Pulse_count
          
          • Auxiliary Item to receive the request (I don’t remember why I used a String type, but it works)
          String MyEnergy_Pulse_REQ
          
          • Auxiliary Item to restore the value to the node
          Number MyEnergy_Pulse_Restore
          

          How to setup the Items depends on the binding you use (I use MQTT)

          On the Node sketch I've used at the beginning:

          MyMessage pcReqMsg(CHILD_ID,V_VAR2);
          

          and on "void setup()" and void loop() replaced

          gw.request(CHILD_ID, V_VAR1);
          

          with

            gw.send(pcReqMsg.set("REQ"));
          

          REQ can be any text, as the rule only takes count of the update, not the value.

          How it works:
          Node sends "REQ" to Openhab as V_VAR2
          The rule detects the update (not a change) on Item MyEnergy_Pulse_REQ
          The rule returns the last value on Item MyEnergy_Pulse_count trough MyEnergy_Pulse_Restore on V_VAR1

          If someone can tell us how to make gw.request work with Openhab, ill be happy to remove this rule from the controller.

          M 1 Reply Last reply
          0
          • J joseraj

            Hi,

            The default sketch sends a request message :

              // Fetch last known pulse count value from gw
              gw.request(CHILD_ID, V_VAR1);
            

            I'm not able to make Openhab answer gw.request so I have used a rule:

            // This rule Send pulse count on request
            rule "Send On Request"
             when
             Item MyEnergy_Pulse_REQ received update
             then
               var Number Pc = MyEnergy_Pulse_count.state as DecimalType
               postUpdate(MyEnergy_Pulse_Restore, Pc)
            end
            

            I have defined the items:

            • Item to store the pulse counts. This is the info of interest for us.
            Number MyEnergy_Pulse_count
            
            • Auxiliary Item to receive the request (I don’t remember why I used a String type, but it works)
            String MyEnergy_Pulse_REQ
            
            • Auxiliary Item to restore the value to the node
            Number MyEnergy_Pulse_Restore
            

            How to setup the Items depends on the binding you use (I use MQTT)

            On the Node sketch I've used at the beginning:

            MyMessage pcReqMsg(CHILD_ID,V_VAR2);
            

            and on "void setup()" and void loop() replaced

            gw.request(CHILD_ID, V_VAR1);
            

            with

              gw.send(pcReqMsg.set("REQ"));
            

            REQ can be any text, as the rule only takes count of the update, not the value.

            How it works:
            Node sends "REQ" to Openhab as V_VAR2
            The rule detects the update (not a change) on Item MyEnergy_Pulse_REQ
            The rule returns the last value on Item MyEnergy_Pulse_count trough MyEnergy_Pulse_Restore on V_VAR1

            If someone can tell us how to make gw.request work with Openhab, ill be happy to remove this rule from the controller.

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

            @joseraj I thought I could eliminate using the V_VAR2 startup because of the new MQTT format from the development branch gateways has the MySensors command type included. In theory this might work as a replacement for the V_VAR2 message and the sketch could be used without modifications.

            Could not make it work though because the gw.request message is sent without payload which Openhab just discards with an error message.

            So it looks like the start up when using Openhab will need the extra message and the rule.

            If you are interested there is some more info here http://forum.mysensors.org/topic/825/need-help-with-pulse-counter-for-power-meter/11

            1 Reply Last reply
            0
            • J Offline
              J Offline
              joseraj
              wrote on last edited by
              #6

              @mbj Thank you for testing.
              If Openhab discards the request without payload there is nothing to do on the gateway side.
              I don't know if other controllers deal with this. If others like Domoticz work without the V_VAR2 method then the work should be done on MQTT binding.
              Anyway the solution above still work for me.

              @TommySharp Have you tried the solution above?
              Just remember this rule works with "Pulse counts", you have to use the right "PULSE_FACTOR" on the controller to get the KWH.

              Provably you'll find another problem (only the first time):
              If the Item were you store the pulse count on Openhab (or any other controller) hasn't been initialized with some value, the controller shouldn't return any value. (just because it has none)
              When I did this sensor I solved sending a value with my cell through MyMQTT (android). This way you can keep sync the value on the controller and the value of the counter.
              In Openhab it can be initialized with a rule as explained here.

              M 1 Reply Last reply
              0
              • J joseraj

                @mbj Thank you for testing.
                If Openhab discards the request without payload there is nothing to do on the gateway side.
                I don't know if other controllers deal with this. If others like Domoticz work without the V_VAR2 method then the work should be done on MQTT binding.
                Anyway the solution above still work for me.

                @TommySharp Have you tried the solution above?
                Just remember this rule works with "Pulse counts", you have to use the right "PULSE_FACTOR" on the controller to get the KWH.

                Provably you'll find another problem (only the first time):
                If the Item were you store the pulse count on Openhab (or any other controller) hasn't been initialized with some value, the controller shouldn't return any value. (just because it has none)
                When I did this sensor I solved sending a value with my cell through MyMQTT (android). This way you can keep sync the value on the controller and the value of the counter.
                In Openhab it can be initialized with a rule as explained here.

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

                @joseraj Yes, the V_VAR2 solution works well. I have used it for a long time. Of course it is possible to modify the sketch so that no request for a start value is made and always start at 0. But I like the idea of getting a start value from the controller when it is needed to restart the node.

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


                18

                Online

                11.7k

                Users

                11.2k

                Topics

                113.0k

                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