Battery status update on web interface

Moderator: leecollings

Post Reply
Lemme
Posts: 45
Joined: Sunday 31 January 2016 13:50
Target OS: Windows
Domoticz version: Dev
Location: DK
Contact:

Battery status update on web interface

Post 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
User avatar
gizmocuz
Posts: 2552
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Battery status update on web interface

Post by gizmocuz »

Have a look in the sensebender sketch how you can send the battery level as a sensor
Quality outlives Quantity!
Lemme
Posts: 45
Joined: Sunday 31 January 2016 13:50
Target OS: Windows
Domoticz version: Dev
Location: DK
Contact:

Re: Battery status update on web interface

Post by Lemme »

OK - I will use that as a work-around.
But are there any plans of implementing the feature I mention?
User avatar
gizmocuz
Posts: 2552
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Battery status update on web interface

Post 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)
Quality outlives Quantity!
Lemme
Posts: 45
Joined: Sunday 31 January 2016 13:50
Target OS: Windows
Domoticz version: Dev
Location: DK
Contact:

Re: Battery status update on web interface

Post by Lemme »

Are we talking about the same thing here... :-)

This is the battery level that I am referring to:
battery.jpg
battery.jpg (73.59 KiB) Viewed 3210 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
User avatar
gizmocuz
Posts: 2552
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Battery status update on web interface

Post 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
Quality outlives Quantity!
Lemme
Posts: 45
Joined: Sunday 31 January 2016 13:50
Target OS: Windows
Domoticz version: Dev
Location: DK
Contact:

Re: Battery status update on web interface

Post 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.
User avatar
gizmocuz
Posts: 2552
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Battery status update on web interface

Post 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)
Quality outlives Quantity!
Lemme
Posts: 45
Joined: Sunday 31 January 2016 13:50
Target OS: Windows
Domoticz version: Dev
Location: DK
Contact:

Re: Battery status update on web interface

Post 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.
Lemme
Posts: 45
Joined: Sunday 31 January 2016 13:50
Target OS: Windows
Domoticz version: Dev
Location: DK
Contact:

Re: Battery status update on web interface

Post 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.
User avatar
gizmocuz
Posts: 2552
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Battery status update on web interface

Post 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)
Quality outlives Quantity!
Lemme
Posts: 45
Joined: Sunday 31 January 2016 13:50
Target OS: Windows
Domoticz version: Dev
Location: DK
Contact:

Re: Battery status update on web interface

Post 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
alexsh1
Posts: 169
Joined: Wednesday 30 September 2015 11:50
Target OS: Raspberry Pi / ODroid
Domoticz version: v3.8975
Location: United Kingdom
Contact:

Re: Battery status update on web interface

Post 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

Lemme
Posts: 45
Joined: Sunday 31 January 2016 13:50
Target OS: Windows
Domoticz version: Dev
Location: DK
Contact:

Re: Battery status update on web interface

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest