Battery status updates only when contact changed

Subforum for the 'MySensors' project.
http://www.mysensors.org/
Post Reply
SweetPants
Posts: 1772
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V3.8924
Location: The Netherlands
Contact:

Battery status updates only when contact changed

Post by SweetPants » Sunday 23 July 2017 10:44

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.
Ubuntu 16.04.3 LTS on Intel NUC, MySensors 2.2.1, Pro Mini 3.3 8M RFM69, ESP8266 (SDK2.1.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

Lemme
Posts: 33
Joined: Sunday 31 January 2016 14:50
Target OS: Raspberry Pi
Domoticz version: Dev
Location: DK
Contact:

Re: Battery status updates only when contact changed

Post by Lemme » Wednesday 02 August 2017 21:24

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
}

SweetPants
Posts: 1772
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V3.8924
Location: The Netherlands
Contact:

Re: Battery status updates only when contact changed

Post by SweetPants » Wednesday 02 August 2017 21:33

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.
Ubuntu 16.04.3 LTS on Intel NUC, MySensors 2.2.1, Pro Mini 3.3 8M RFM69, ESP8266 (SDK2.1.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest