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. Development
  3. MQTT and batterylevel

MQTT and batterylevel

Scheduled Pinned Locked Moved Development
17 Posts 6 Posters 6.7k Views 2 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.
  • M mbj

    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 :-)

    gaduG Offline
    gaduG Offline
    gadu
    wrote on last edited by
    #8

    Big thanks @mbj
    I'm more of a beginner than you. Trust me. :-)

    I'll do some experiments using you pointers.

    gaduG K 2 Replies Last reply
    0
    • gaduG gadu

      Big thanks @mbj
      I'm more of a beginner than you. Trust me. :-)

      I'll do some experiments using you pointers.

      gaduG Offline
      gaduG Offline
      gadu
      wrote on last edited by
      #9

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

      And you called yourself a beginner? ;-)

      M 1 Reply Last reply
      0
      • gaduG gadu

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

        And you called yourself a beginner? ;-)

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

        @gadu Glad to be of any help, your turn next :-)

        1 Reply Last reply
        0
        • gaduG Offline
          gaduG Offline
          gadu
          wrote on last edited by
          #11

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

          1 Reply Last reply
          0
          • gaduG gadu

            Big thanks @mbj
            I'm more of a beginner than you. Trust me. :-)

            I'll do some experiments using you pointers.

            K Offline
            K Offline
            kunall
            wrote on last edited by
            #12

            @gadu Can you post your working battery level send sketch for openhab? I would really appreciate it. I'm facing the same issue. Thanks!

            gaduG 1 Reply Last reply
            0
            • HeinzH Offline
              HeinzH Offline
              Heinz
              Hero Member
              wrote on last edited by
              #13

              ... probably gw.sendBatteryLevel(percent); helps.

              1 Reply Last reply
              0
              • K kunall

                @gadu Can you post your working battery level send sketch for openhab? I would really appreciate it. I'm facing the same issue. Thanks!

                gaduG Offline
                gaduG Offline
                gadu
                wrote on last edited by
                #14

                @kunall

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

                K 2 Replies Last reply
                0
                • gaduG gadu

                  @kunall

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

                  K Offline
                  K Offline
                  kunall
                  wrote on last edited by
                  #15

                  Thanks alot @gadu . I will give this a try and get back to you! :+1:

                  1 Reply Last reply
                  0
                  • gaduG gadu

                    @kunall

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

                    K Offline
                    K Offline
                    kunall
                    wrote on last edited by kunall
                    #16

                    @gadu How did you implement V_Var1 ? and assign it to child ID 1 ?

                    Like this? if so, what did you use for gw.present(CHILD_ID, S_XXX) ?

                    #define CHILD_ID 1
                    myMessage msg(CHILD_ID, V_VAR1);
                    
                    1 Reply Last reply
                    0
                    • siodS Offline
                      siodS Offline
                      siod
                      wrote on last edited by
                      #17

                      @gadu
                      where is the imprtoant MQTT code of your sketch? Would be so kind and share it with us?

                      Thanks in advance!!

                      still learning...

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


                      11

                      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