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. Domoticz
  4. Battery status does not show in Domoticz

Battery status does not show in Domoticz

Scheduled Pinned Locked Moved Domoticz
16 Posts 6 Posters 4.7k Views 5 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.
  • edsteveE Offline
    edsteveE Offline
    edsteve
    wrote on last edited by
    #1

    Hi,

    i was on the way building a relay node with battery status report. The Node sends the data as you can see from the serial monitor:

    Incoming change for sensor:1, New status: 1
    TSP:MSG:READ 0-0-5 s=1,c=1,t=2,pt=0,l=1,sg=0:0
    Incoming change for sensor:1, New status: 0
    Battery voltage: 4137 mV
    Battery percent: 104 %
    TSP:MSG:SEND 5-5-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=ok:104
    TSP:SANCHK:OK
    

    But it does not show in Domoticz:
    0_1499628978651_Capture.PNG

    This is my sensor sketch:

    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_NRF24
    //#define MY_RADIO_RFM69
    
    // Enable repeater functionality for this node
    #define MY_REPEATER_FEATURE
    
    #include <MySensors.h>
    
    #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
    #define NUMBER_OF_RELAYS 1 // Total number of attached relays
    #define RELAY_ON 1  // GPIO value to write to turn on attached relay
    #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
    
    #define BATTERY_REPORT_CYCLE 2
    #define VMIN 3200           // Min Battery level
    #define VMAX 4100           // Max Battery level
    
    int batteryReportCounter = BATTERY_REPORT_CYCLE - 1;
    
    void before()
    {
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
            // Then set relay pins in output mode
            pinMode(pin, OUTPUT);
            // Set relay to last known state (using eeprom storage)
            digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
        }
    }
    
    void setup()
    {
    }
    
    void presentation()
    {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Relay", "1.0");
    
        for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
            // Register all sensors to gw (they will be created as child devices)
            present(sensor, S_BINARY);
        }
    }
    
    
    void loop()
    {
    }
    
    void receive(const MyMessage &message)
    {
        // We only expect one type of message from controller. But we better check anyway.
        if (message.type==V_STATUS) {
            // Change relay state
            digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
            // Store state in eeprom
            saveState(message.sensor, message.getBool());
            // Write some debug info
            Serial.print("Incoming change for sensor:");
            Serial.print(message.sensor);
            Serial.print(", New status: ");
            Serial.println(message.getBool());
        }
        
        batteryReportCounter ++;
        bool forceTransmit = true;
       // Check battery
       if (batteryReportCounter >= BATTERY_REPORT_CYCLE) {
        long batteryVolt = readVcc();
        Serial.print("Battery voltage: "); Serial.print(batteryVolt); Serial.println(" mV");
        uint8_t batteryPcnt = constrain(map(batteryVolt,VMIN,VMAX,0,100),0,255);   
        Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");
        sendBatteryLevel(batteryPcnt);
        batteryReportCounter = 0;
       }
    }
    
    long readVcc() {
      // set the reference to Vcc and the measurement to the internal 1.1V reference
      ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
      delay(2); // Wait for Vref to settle
      ADCSRA |= _BV(ADSC); // Start conversion
      while (bit_is_set(ADCSRA,ADSC)); // measuring
      uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
      uint8_t high = ADCH; // unlocks both
      long result = (high<<8) | low;
      result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
      return result; // Vcc in millivolts
    }
    

    Can't figure it out :(
    Hope someone can point me in the right direction.

    YveauxY 1 Reply Last reply
    0
    • edsteveE edsteve

      Hi,

      i was on the way building a relay node with battery status report. The Node sends the data as you can see from the serial monitor:

      Incoming change for sensor:1, New status: 1
      TSP:MSG:READ 0-0-5 s=1,c=1,t=2,pt=0,l=1,sg=0:0
      Incoming change for sensor:1, New status: 0
      Battery voltage: 4137 mV
      Battery percent: 104 %
      TSP:MSG:SEND 5-5-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,ft=0,st=ok:104
      TSP:SANCHK:OK
      

      But it does not show in Domoticz:
      0_1499628978651_Capture.PNG

      This is my sensor sketch:

      // Enable debug prints to serial monitor
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      // Enable repeater functionality for this node
      #define MY_REPEATER_FEATURE
      
      #include <MySensors.h>
      
      #define RELAY_1  3  // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
      #define NUMBER_OF_RELAYS 1 // Total number of attached relays
      #define RELAY_ON 1  // GPIO value to write to turn on attached relay
      #define RELAY_OFF 0 // GPIO value to write to turn off attached relay
      
      #define BATTERY_REPORT_CYCLE 2
      #define VMIN 3200           // Min Battery level
      #define VMAX 4100           // Max Battery level
      
      int batteryReportCounter = BATTERY_REPORT_CYCLE - 1;
      
      void before()
      {
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
              // Then set relay pins in output mode
              pinMode(pin, OUTPUT);
              // Set relay to last known state (using eeprom storage)
              digitalWrite(pin, loadState(sensor)?RELAY_ON:RELAY_OFF);
          }
      }
      
      void setup()
      {
      }
      
      void presentation()
      {
          // Send the sketch version information to the gateway and Controller
          sendSketchInfo("Relay", "1.0");
      
          for (int sensor=1, pin=RELAY_1; sensor<=NUMBER_OF_RELAYS; sensor++, pin++) {
              // Register all sensors to gw (they will be created as child devices)
              present(sensor, S_BINARY);
          }
      }
      
      
      void loop()
      {
      }
      
      void receive(const MyMessage &message)
      {
          // We only expect one type of message from controller. But we better check anyway.
          if (message.type==V_STATUS) {
              // Change relay state
              digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
              // Store state in eeprom
              saveState(message.sensor, message.getBool());
              // Write some debug info
              Serial.print("Incoming change for sensor:");
              Serial.print(message.sensor);
              Serial.print(", New status: ");
              Serial.println(message.getBool());
          }
          
          batteryReportCounter ++;
          bool forceTransmit = true;
         // Check battery
         if (batteryReportCounter >= BATTERY_REPORT_CYCLE) {
          long batteryVolt = readVcc();
          Serial.print("Battery voltage: "); Serial.print(batteryVolt); Serial.println(" mV");
          uint8_t batteryPcnt = constrain(map(batteryVolt,VMIN,VMAX,0,100),0,255);   
          Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");
          sendBatteryLevel(batteryPcnt);
          batteryReportCounter = 0;
         }
      }
      
      long readVcc() {
        // set the reference to Vcc and the measurement to the internal 1.1V reference
        ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
        delay(2); // Wait for Vref to settle
        ADCSRA |= _BV(ADSC); // Start conversion
        while (bit_is_set(ADCSRA,ADSC)); // measuring
        uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH  
        uint8_t high = ADCH; // unlocks both
        long result = (high<<8) | low;
        result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
        return result; // Vcc in millivolts
      }
      

      Can't figure it out :(
      Hope someone can point me in the right direction.

      YveauxY Offline
      YveauxY Offline
      Yveaux
      Mod
      wrote on last edited by
      #2

      @edsteve maybe because you're reporting an out of range percentage value?

      http://yveaux.blogspot.nl

      1 Reply Last reply
      0
      • gohanG Offline
        gohanG Offline
        gohan
        Mod
        wrote on last edited by
        #3

        you could try setting VMAX to 4150 or 4200

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

          Domoticz (v3.6179) shows 133% for one of my sensors so it can handle out of range.

          1 Reply Last reply
          1
          • edsteveE Offline
            edsteveE Offline
            edsteve
            wrote on last edited by
            #5

            Thanks for replies.
            Yes it can handle out of range. My weather sensor works just fine with 120% :-)

            Where would you start digging for the reason? A log file I can check?

            1 Reply Last reply
            0
            • gohanG Offline
              gohanG Offline
              gohan
              Mod
              wrote on last edited by
              #6

              look in domoticz log and see if value is actually received

              1 Reply Last reply
              0
              • edsteveE Offline
                edsteveE Offline
                edsteve
                wrote on last edited by
                #7

                That's another question i have since a while now:
                How can i change the domoticz log to more debugging details? Hard to find that information. I can't find any values in the standard-log.

                sundberg84S gohanG 2 Replies Last reply
                0
                • edsteveE edsteve

                  That's another question i have since a while now:
                  How can i change the domoticz log to more debugging details? Hard to find that information. I can't find any values in the standard-log.

                  sundberg84S Offline
                  sundberg84S Offline
                  sundberg84
                  Hardware Contributor
                  wrote on last edited by sundberg84
                  #8

                  @edsteve - I dont know if there is an easy way but the hard one is to compile the code youself for Domoticz and insert any output/debug you want...

                  Controller: Proxmox VM - Home Assistant
                  MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                  MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                  RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                  1 Reply Last reply
                  0
                  • edsteveE edsteve

                    That's another question i have since a while now:
                    How can i change the domoticz log to more debugging details? Hard to find that information. I can't find any values in the standard-log.

                    gohanG Offline
                    gohanG Offline
                    gohan
                    Mod
                    wrote on last edited by
                    #9

                    @edsteve

                    From Domoticz forum > if you edit /etc/init.d/domoticz.sh you can do this:

                    DAEMON_ARGS="-daemon -www 8080 -log /home/pi/log/domoticz.log -loglevel 0"

                    Just don't forget to put back the original config as the log file would grow quite a lot

                    1 Reply Last reply
                    2
                    • edsteveE Offline
                      edsteveE Offline
                      edsteve
                      wrote on last edited by edsteve
                      #10

                      @gohan
                      I also have that info from the domoticz forum and i tried it. Tailing the new log file... still no more details. I give up...
                      Maaaybe... when i have motivation again i will try to read about @sunberg84 solution. But i am just not a linux expert.

                      Grml... never like it to live with an unsolved problem. But thx for the effort everyone.

                      Here is the link to the domoticz forum about the logging problem

                      1 Reply Last reply
                      1
                      • gohanG Offline
                        gohanG Offline
                        gohan
                        Mod
                        wrote on last edited by
                        #11

                        try changing the node ID to a number you never used.

                        1 Reply Last reply
                        0
                        • markjgabbM Offline
                          markjgabbM Offline
                          markjgabb
                          wrote on last edited by
                          #12

                          @edsteve according to domoticz api data battery is measured in a rang of 0-225? wouldnt percentage send cause issueS?

                          sundberg84S 1 Reply Last reply
                          0
                          • markjgabbM markjgabb

                            @edsteve according to domoticz api data battery is measured in a rang of 0-225? wouldnt percentage send cause issueS?

                            sundberg84S Offline
                            sundberg84S Offline
                            sundberg84
                            Hardware Contributor
                            wrote on last edited by
                            #13

                            @markjgabb - I always recalculate the battery into % which is shown great in DOmoticz. I guess you can go up to 225 but if you like but thats not a problem if you convert it to %

                            Controller: Proxmox VM - Home Assistant
                            MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                            MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                            RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                            1 Reply Last reply
                            0
                            • markjgabbM Offline
                              markjgabbM Offline
                              markjgabb
                              wrote on last edited by
                              #14

                              fair enough...i havent done battery sensors before...i was just looking at the API earlier where it pointed out sending in that range so thought it might be in that sort of area obviously domoticz is smart enough to realize its been passed the percentage anyway

                              sundberg84S 1 Reply Last reply
                              0
                              • markjgabbM markjgabb

                                fair enough...i havent done battery sensors before...i was just looking at the API earlier where it pointed out sending in that range so thought it might be in that sort of area obviously domoticz is smart enough to realize its been passed the percentage anyway

                                sundberg84S Offline
                                sundberg84S Offline
                                sundberg84
                                Hardware Contributor
                                wrote on last edited by
                                #15

                                @markjgabb - could be Domticz can recalculate... dont know to be honest. I have always sent 0-100. Let me know if you find anything more clever :)

                                Controller: Proxmox VM - Home Assistant
                                MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                                MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                                RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                                1 Reply Last reply
                                0
                                • edsteveE Offline
                                  edsteveE Offline
                                  edsteve
                                  wrote on last edited by
                                  #16

                                  Sorry guys. Not at home lately. I will report if and what solved my problem when i am back.

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


                                  23

                                  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