Pulse Power Meter with OpenHAB?



  • 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.....


  • Mod

    (Moved from General discussion to the OpenHAB category)



  • @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



  • 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.



  • @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



  • @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.



  • @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.


 

198
Online

8.5k
Users

9.4k
Topics

98.7k
Posts