Battery status does not show in Domoticz



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


  • Mod

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


  • Mod

    you could try setting VMAX to 4150 or 4200


  • Mod

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



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


  • Mod

    look in domoticz log and see if value is actually received



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


  • Hardware Contributor

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


  • Mod

    @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



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


  • Mod

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



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


  • Hardware Contributor

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



  • 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


  • Hardware Contributor

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



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


Log in to reply
 

Suggested Topics

  • 5
  • 8
  • 5
  • 2
  • 4
  • 1

14
Online

11.4k
Users

11.1k
Topics

112.7k
Posts