Pulse Power Meter with OpenHAB?
TommySharp last edited by
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.....
(Moved from General discussion to the OpenHAB category)
bkl last edited by
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
joseraj last edited by
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.
- Auxiliary Item to receive the request (I don’t remember why I used a String type, but it works)
- Auxiliary Item to restore the value to the node
How to setup the Items depends on the binding you use (I use MQTT)
On the Node sketch I've used at the beginning:
and on "void setup()" and void loop() replaced
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.
mbj last edited by
@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
joseraj last edited by
@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.
mbj last edited by
@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.