MQTT and batterylevel
-
Maybe I did not read your code good enough but I could not see any definition of the message type sendBatteryLevel (see an example for the definition of the temperature message in your code "MyMessage msg(0,V_TEMP);" )
-
Unfortunately I am a beginner with all this but I have been successful getting messages over to Openhab via the MQTT binding.
I can guess that the "sendBatteryLevel" example from the API pages is tailored for a Vera controller or similar but is not at all understood by Openhab. I have come across something similar when other sensors send commands directed to the controller itself.
So my assumption was that if you should send something across that Openhab understands you could test creating a message like your example msgvolt and then send the info with something like gw.send(msgvolt.set(batteryV)) or gw.send(msgvolt.set(batteryV,1)) and pick this up with an item in Openhab.
The messages type V_VAR1 and onwards can be used for custom values so I think you can use one of these to send the battery level percentage. Only way to find out is to experiment :-)
-
Unfortunately I am a beginner with all this but I have been successful getting messages over to Openhab via the MQTT binding.
I can guess that the "sendBatteryLevel" example from the API pages is tailored for a Vera controller or similar but is not at all understood by Openhab. I have come across something similar when other sensors send commands directed to the controller itself.
So my assumption was that if you should send something across that Openhab understands you could test creating a message like your example msgvolt and then send the info with something like gw.send(msgvolt.set(batteryV)) or gw.send(msgvolt.set(batteryV,1)) and pick this up with an item in Openhab.
The messages type V_VAR1 and onwards can be used for custom values so I think you can use one of these to send the battery level percentage. Only way to find out is to experiment :-)
-
Big thanks @mbj
I'm more of a beginner than you. Trust me. :-)I'll do some experiments using you pointers.
-
@mbj saved my day!!
publish: MyMQTT/21/0/V_TEMP 23.5 0;0;3;0;9;send: 0-0-21-21 s=0,c=1,t=0,pt=0,l=5,st=ok:23.5r 0;0;3;0;9;read: 21-21-0 s=1,c=1,t=24,pt=2,l=2:87 publish: MyMQTT/21/1/V_VAR1 87And you called yourself a beginner? ;-)
-
If anything, let me know! Dunno if I can be of any help, but i could try :-)
Odd thing happend though, When the Mini is connected to the FTDI the serial monitor says "Check Wires", but on battery it sends everything correct?
Well, that's another issue to look at later... -
Big thanks @mbj
I'm more of a beginner than you. Trust me. :-)I'll do some experiments using you pointers.
-
... probably gw.sendBatteryLevel(percent); helps.
-
@gadu Can you post your working battery level send sketch for openhab? I would really appreciate it. I'm facing the same issue. Thanks!
First these two rows before setup..
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int oldBatteryPcnt = 0;and in the loop i have these rows...
// get the battery Voltage int sensorValue = analogRead(BATTERY_SENSE_PIN); //Serial.println(sensorValue); // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // 3.44/1023 = Volts per bit = 0.003363075 float batteryV = sensorValue * 0.003363075; int batteryPcnt = sensorValue / 10; Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); if (oldBatteryPcnt != batteryPcnt) { // Power up radio after sleep gw.sendBatteryLevel(batteryPcnt); oldBatteryPcnt = batteryPcnt;in OpenHab items i have this row...
Number node2_batt "Battery [%.1f %%]" <energy> (node2,All) {mqtt="<[MySensor:MyMQTT/21/1/V_VAR1:state:default]"}hope this helps....
-
First these two rows before setup..
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int oldBatteryPcnt = 0;and in the loop i have these rows...
// get the battery Voltage int sensorValue = analogRead(BATTERY_SENSE_PIN); //Serial.println(sensorValue); // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // 3.44/1023 = Volts per bit = 0.003363075 float batteryV = sensorValue * 0.003363075; int batteryPcnt = sensorValue / 10; Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); if (oldBatteryPcnt != batteryPcnt) { // Power up radio after sleep gw.sendBatteryLevel(batteryPcnt); oldBatteryPcnt = batteryPcnt;in OpenHab items i have this row...
Number node2_batt "Battery [%.1f %%]" <energy> (node2,All) {mqtt="<[MySensor:MyMQTT/21/1/V_VAR1:state:default]"}hope this helps....
-
First these two rows before setup..
int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point int oldBatteryPcnt = 0;and in the loop i have these rows...
// get the battery Voltage int sensorValue = analogRead(BATTERY_SENSE_PIN); //Serial.println(sensorValue); // 1M, 470K divider across battery and using internal ADC ref of 1.1V // Sense point is bypassed with 0.1 uF cap to reduce noise at that point // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // 3.44/1023 = Volts per bit = 0.003363075 float batteryV = sensorValue * 0.003363075; int batteryPcnt = sensorValue / 10; Serial.print("Battery Voltage: "); Serial.print(batteryV); Serial.println(" V"); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); if (oldBatteryPcnt != batteryPcnt) { // Power up radio after sleep gw.sendBatteryLevel(batteryPcnt); oldBatteryPcnt = batteryPcnt;in OpenHab items i have this row...
Number node2_batt "Battery [%.1f %%]" <energy> (node2,All) {mqtt="<[MySensor:MyMQTT/21/1/V_VAR1:state:default]"}hope this helps....