Page 1 of 1
Battery status updates only when contact changed
Posted: Sunday 23 July 2017 10:44
by SweetPants
Hi, I have made some battery powered MySensors door/window sensors and noticed that battery status is only updated when there is a contact change. My sensor node also periodically (once a day) sends battery status to the MySensors gateway, i see the message arrive, but Domoticz is not updated. For a window sensor this might become problematic if the (in my case LiPo) battery becomes critical you don't know until the window is opened/closed.
Re: Battery status updates only when contact changed
Posted: Wednesday 02 August 2017 21:24
by Lemme
Hi
I had the same problem. My solution was to create an voltage sensor.
Br
Lemme
Create sensor:
MyMessage msg2(CHILD_ID_1, V_VOLTAGE);
present(CHILD_ID_1, S_MULTIMETER);
Send the value:
float batteryPcnt = readVcc();
send(msg2.set(batteryPcnt, 3));
And the function:
float readVcc() {
// Read 1.1V reference against AVcc
// set the reference to Vcc and the measurement to the internal 1.1V reference
#if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
ADMUX = _BV(MUX5) | _BV(MUX0);
#elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
ADMUX = _BV(MUX3) | _BV(MUX2);
#else
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
#endif
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
float battery = result / 1000.0;
return battery; // Vcc in volts
}
Re: Battery status updates only when contact changed
Posted: Wednesday 02 August 2017 21:33
by SweetPants
Thanks for the 'workaround', but the 'switch/contact' already has a Domoticz battery status that can be updated, it only happens with a contact change while i think it should always be updated no matter what the contact status is. With 15+ door/window sensors, you get a lot of devices extra. I'm trying to understand how this works in the code, but without some more knowledge how MySensors/domoticz works internally, it's difficult.