Page 1 of 1
Battery status update on web interface
Posted: Saturday 02 July 2016 11:27
by Lemme
Hi
I have battery powered nodes acting as security door sensors. These sensors can be untouched for weeks or months.
But every 24 hours, I send a battery update to Domoticz - 'sendBatteryLevel()'. Unfortunally, this updated battery status are not updated on Domoticz web interface. The battery status on the web interface are only opdated when the door sensor gets activated. That means essentially that I have to go around the house and activate each sensor to get the battery status updated on the web interface.
Is there a way to force at battery update to the web interface?
Or - would you gizmocuz please implement this feature?
Br
Lemme
Re: Battery status update on web interface
Posted: Saturday 02 July 2016 11:53
by gizmocuz
Have a look in the sensebender sketch how you can send the battery level as a sensor
Re: Battery status update on web interface
Posted: Saturday 02 July 2016 12:23
by Lemme
OK - I will use that as a work-around.
But are there any plans of implementing the feature I mention?
Re: Battery status update on web interface
Posted: Saturday 02 July 2016 12:27
by gizmocuz
That will mean a lot of extra sensors, and this way you can decide yourself what you want to log
(And it is very easy)
Re: Battery status update on web interface
Posted: Saturday 02 July 2016 12:51
by Lemme
Are we talking about the same thing here...
This is the battery level that I am referring to:

- battery.jpg (73.59 KiB) Viewed 3212 times
It seems that the battery level are just another value to the already existing sensor. I do not want to log anything, just have the possibility to update the value using sendBatteryLevel(). And to check once in a while that the battery level are still good.
But mabye that is not as easy from a code perspective? It just sounds strange that it would need a lot of extra sensors.
Best regards - and thanks for this wonderfull software!
Lemme
Re: Battery status update on web interface
Posted: Saturday 02 July 2016 12:55
by gizmocuz
Then no, i was talking about the ability to 'log' battery level as for example you can have a percentage/temperature sensor
I think i know the issue, when i receive a battery update, this is hold internally, until also the 'child' is received (like a switch/temp), then... i update the status in domoticz, together with the previously received battery level
Re: Battery status update on web interface
Posted: Saturday 02 July 2016 13:40
by Lemme
Yes - this is exactly what happens. The battery update are only updated on the web interface when also the 'child' is revieved. But in real life, this is actually not a good idea. With my suggestion, the use of the battery level will be more usefull for usecases as Smoke Detectors and like. These are activated very rarely. But there is a need for ongoing monitoring the battery.
Re: Battery status update on web interface
Posted: Saturday 02 July 2016 14:28
by gizmocuz
True, but good smoke detectors and door sensors (professional) send a keep-alive, and thats already working
So why dont you send the current switch state each xx minutes ? (like each 10 or 12)
Re: Battery status update on web interface
Posted: Saturday 02 July 2016 15:09
by Lemme
Good point. I could send the battery level first, and then the current state of the senor. I will do that to solve the issue.
But I still think that sending sendBatteryLevel() should take care of it all. It would be the most clean and intuitive solution.
Regarding the 'keep-alive' function - this is only implemented in the development version of MySensors. It is not part of the stable version 1.5.4. I am back at 1.5.4 as I have issues creating nodes in a consistent manner with the development version.
Re: Battery status update on web interface
Posted: Saturday 02 July 2016 15:28
by Lemme
Just tested it - the solution you suggest does not work.
The battery status are only updated when the sensor changes state. But the switch does not change state. And therefore Domoticz are not showing the update.
Re: Battery status update on web interface
Posted: Sunday 03 July 2016 8:36
by gizmocuz
If you can program/compile try changing the function "MySensorsBase::UpdateNodeBatteryLevel" to
Code: Select all
void MySensorsBase::UpdateNodeBatteryLevel(const int nodeID, const int Level)
{
std::map<int, _tMySensorNode>::iterator ittNode = m_nodes.find(nodeID);
if (ittNode == m_nodes.end())
return; //Not found
_tMySensorNode *pNode = &ittNode->second;
std::vector<_tMySensorChild>::iterator itt;
for (itt = pNode->m_childs.begin(); itt != pNode->m_childs.end(); ++itt)
{
itt->hasBattery = true;
itt->batValue = Level;
std::map<_eSetType, _tMySensorValue>::const_iterator itt2;
for (itt2 = itt->values.begin(); itt2 != itt->values.end(); ++itt2)
{
if (itt2->second.bValidValue)
{
_eSetType vType = itt2->first;
SendSensor2Domoticz(pNode, &(*itt), vType);
}
}
}
}
This should update all affecting sensors battery status, but!, indeed, also have a look at "MySensorsBase::UpdateSwitch"
remove:
Code: Select all
std::vector<std::vector<std::string> > result;
result = m_sql.safe_query("SELECT Name,nValue,sValue FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit==%d) AND (Type==%d) AND (Subtype==%d)", m_HwdID, szIdx, SubUnit, int(pTypeLighting2), int(sTypeAC));
if (!result.empty())
{
if ((vType != V_TRIPPED) || (!bOn))
{
//check if we have a change, if not do not update it
int nvalue = atoi(result[0][1].c_str());
if ((!bOn) && (nvalue == 0))
return;
if ((bOn && (nvalue != 0)))
{
//Check Level
int slevel = atoi(result[0][2].c_str());
if (slevel == level)
return;
}
}
}
this will not check if the switch state is the same as the previous one
But you can also change your sketch.
First send the battery level, then send the state of the new switch
if you set the switch to 'On' from Domoticz -> Your Sensor
When your sensor receives it, Send the battery level first, then send the new switch state (On)
Re: Battery status update on web interface
Posted: Sunday 03 July 2016 12:20
by Lemme
Thanks for looking into this and providing a fix. The truth is, I am not on the same skill level like you. I could change the source code, but I do not know how to compile it on the raspberry. So I am kind of stuck here. For now I will have to use your 'Sensebender' solution as a work-around.
But sometime in the future, if possible, I suggest that the sendBatteryLevel() function are implemented as intented. Just update the battery level - nothing more, nothing less.
Shameless as i am, I made a little donation hoping this issue might get some priority, for the benefit of all users.
Br
Lemme
Re: Battery status update on web interface
Posted: Monday 04 July 2016 4:36
by alexsh1
I use the following code in order to display battery voltage in % (for MySensors v1.5):
Code: Select all
void loop()
{
#define MIN_V 2700
#define MAX_V 3200
int batteryPcnt = min(map(readVcc(), MIN_V, MAX_V, 0, 100), 100); // Convert voltage to percentage
gw.sendBatteryLevel(batteryPcnt); // Send battery percentage to gateway
}
long 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
return result; // Vcc in millivolts
}
1
Fat Fly 6 days ago
Re: Battery status update on web interface
Posted: Monday 04 July 2016 9:34
by Lemme
Hi alexsh1
I do too - that is not the problem. The problem is as described in the top post:
'I have battery powered nodes acting as security door sensors. These sensors can be untouched for weeks or months.
But every 24 hours, I send a battery update to Domoticz - 'sendBatteryLevel()'. Unfortunally, this updated battery status are not updated on Domoticz web interface. The battery status on the web interface are only opdated when the door sensor gets activated. That means essentially that I have to go around the house and activate each sensor to get the battery status updated on the web interface.'
Br
Lemme