"last seen" value not being updated with latest Domoticz

Please use template to report bugs and problems. Post here your questions when not sure where else to post
Only for bugs in the Domoticz application! other problems go in different subforums!
Forum rules
Before posting here, make sure you are on the latest Beta or Stable version.
If you have problems related to the web gui, clear your browser cache + appcache first.

Use the following template when posting here:

Version: xxxx
Platform: xxxx
Plugin/Hardware: xxxx
Description:
.....

If you are having problems with scripts/blockly, always post the script (in a spoiler or code tag) or screenshots of your blockly

If you are replying, please do not quote images/code from the first post
Post Reply
ileneken3
Posts: 6
Joined: Wednesday 09 August 2017 0:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

"last seen" value not being updated with latest Domoticz

Post by ileneken3 » Wednesday 09 August 2017 1:05

Version: 3.1853
Platform: Raspberry Pi
Plugin/Hardware: Mysensors
Description: After upgrading to the latest stable, I no longer get the "last seen" value updated from MySensors nodes (which call either SendHeartbeat() or send a value which is the same as the existing). If the value sent changes, the "last seen" is updated. This seemed to work fine before. I am on MySensors version 2.2.

Thanks

tozzke
Posts: 123
Joined: Friday 02 January 2015 10:22
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: "last seen" value not being updated with latest Domoticz

Post by tozzke » Wednesday 09 August 2017 1:40

ileneken3 wrote:Version: 3.1853
Platform: Raspberry Pi
Plugin/Hardware: Mysensors
Description: After upgrading to the latest stable, I no longer get the "last seen" value updated from MySensors nodes (which call either SendHeartbeat() or send a value which is the same as the existing). If the value sent changes, the "last seen" is updated. This seemed to work fine before. I am on MySensors version 2.2.

Thanks
I think this is the same problem I'm having
When used in a lua script, it'll change AFTER the script is completely finished. This means that for example this wiki isn't working properly anymore (well... it is working... but it's calculating with the previous lastseen, not the current/last which triggered this script in the first place).

Code: Select all

function timedifference(timestamp)
  y, m, d, H, M, S = timestamp:match("(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)")
  difference = os.difftime(os.time(), os.time{year=y, month=m, day=d, hour=H, min=M, sec=S})
  return difference
end
s = otherdevices_lastupdate['mydevice']
if(otherdevices['mydevice']=='On' and timedifference(s) > 600) then
    commandArray['mydevice']='Off'
end
So if 'mydevice' was last switched off more than 600 seconds ago and you switch it on which triggers this if-rule, it calculates with the lastseen time it switched off in stead of on, which means it'll trigger instantly and turn it off again. :|

I hope they turn it back the way it was

User avatar
gizmocuz
Posts: 8526
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi
Domoticz version: beta
Location: Top of the world
Contact:

Re: "last seen" value not being updated with latest Domoticz

Post by gizmocuz » Wednesday 09 August 2017 9:28

ileneken3 wrote:Version: 3.1853
Platform: Raspberry Pi
Plugin/Hardware: Mysensors
Description: After upgrading to the latest stable, I no longer get the "last seen" value updated from MySensors nodes (which call either SendHeartbeat() or send a value which is the same as the existing). If the value sent changes, the "last seen" is updated. This seemed to work fine before. I am on MySensors version 2.2.

Thanks
Strange, looking in the MySensorsBase.cpp class (void MySensorsBase::UpdateNodeHeartbeat), it should still work
Could you refresh the gui (web page) and see if it is updated, maybe the refresh routing in the web gui is not updating the last-seen but internally it is

Else, are you able to debug here? the "UpdateNodeHeartbeat" calls "UpdateSwitchLastUpdate" and this changes the database value of "LastUpdate"


@tozzke, i think this is a different issue than a scripting issue
Quality outlives Quantity!

ileneken3
Posts: 6
Joined: Wednesday 09 August 2017 0:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: "last seen" value not being updated with latest Domoticz

Post by ileneken3 » Wednesday 09 August 2017 13:10

It is definitely not a browser cache issue. I have refreshed many times, and I've tried it from different browsers on different' OS's.

I would be happy to debug, but I need some pointers in the right direction. I think I'm already at the highest debug level - so we're talking re-compiling with debug statements? Using a debugger?

jvandenbroek
Posts: 134
Joined: Wednesday 12 March 2014 17:37
Target OS: Raspberry Pi
Domoticz version: beta
Location: The Netherlands
Contact:

Re: "last seen" value not being updated with latest Domoticz

Post by jvandenbroek » Wednesday 09 August 2017 14:00

tozzke wrote:
Wednesday 09 August 2017 1:40
I think this is the same problem I'm having
When used in a lua script, it'll change AFTER the script is completely finished. This means that for example this wiki isn't working properly anymore (well... it is working... but it's calculating with the previous lastseen, not the current/last which triggered this script in the first place).

Code: Select all

function timedifference(timestamp)
  y, m, d, H, M, S = timestamp:match("(%d+)-(%d+)-(%d+) (%d+):(%d+):(%d+)")
  difference = os.difftime(os.time(), os.time{year=y, month=m, day=d, hour=H, min=M, sec=S})
  return difference
end
s = otherdevices_lastupdate['mydevice']
if(otherdevices['mydevice']=='On' and timedifference(s) > 600) then
    commandArray['mydevice']='Off'
end
So if 'mydevice' was last switched off more than 600 seconds ago and you switch it on which triggers this if-rule, it calculates with the lastseen time it switched off in stead of on, which means it'll trigger instantly and turn it off again. :|

I hope they turn it back the way it was
Offtopic, but as I tried to explain to you in the other topic, you can just add

Code: Select all

not devicechanged['devicename'] 
and all be fine. Will update the wiki.

ileneken3
Posts: 6
Joined: Wednesday 09 August 2017 0:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: "last seen" value not being updated with latest Domoticz

Post by ileneken3 » Saturday 12 August 2017 0:35

I put a debug statement in:

void MySensorsBase::UpdateSwitchLastUpdate(const unsigned char Idx, const int SubUnit)
{
char szIdx[10];
sprintf(szIdx, "%X%02X%02X%02X", 0, 0, 0, Idx);
std::vector<std::vector<std::string> > result;
// LLEMARINEL : #1312 Changed pTypeLighting2 to pTypeGeneralSwitch
result = m_sql.safe_query("SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit==%d) AND (Type==%d) AND (Subtype==%d)", m_HwdID, szIdx, SubUnit, int(pTypeGeneralSwitch), int(sSwitchTypeAC));
if (result.size() < 1) {
_log.Log(LOG_ERROR, "MY DEBUG STATEMENT: MySensorssBase::UpdateSwitchLastUpdate() returning early from : SELECT ID FROM DeviceStatus WHERE (HardwareID==%d) AND (DeviceID=='%q') AND (Unit==%d) AND (Type==%d) AND (Subtype==%d)", m_HwdID, szIdx, SubUnit, int(pTypeGeneralSwitch), int(sSwitchTypeAC));

return; //not found!
}

And it can be seen that the SQL query fails and the update never happens. Here is some output from a sensor that is sending a heartbeat every 20 seconds (or so):

2017-08-11 17:29:45.286 Error: MY DEBUG STATEMENT: MySensorssBase::UpdateSwitchLastUpdate() returning early from : SELECT ID FROM DeviceStatus WHERE (HardwareID==4) AND (DeviceID=='%') AND (Unit==1872751020) AND (Type==38) AND (Subtype==244)
2017-08-11 17:30:09.290 Error: MY DEBUG STATEMENT: MySensorssBase::UpdateSwitchLastUpdate() returning early from : SELECT ID FROM DeviceStatus WHERE (HardwareID==4) AND (DeviceID=='%') AND (Unit==1872751020) AND (Type==38) AND (Subtype==244)
2017-08-11 17:30:32.294 Error: MY DEBUG STATEMENT: MySensorssBase::UpdateSwitchLastUpdate() returning early from : SELECT ID FROM DeviceStatus WHERE (HardwareID==4) AND (DeviceID=='%') AND (Unit==1872751020) AND (Type==38) AND (Subtype==244)


Could someone explain why the query is failing?
I did undo the change #1312, but it didn't help.

Thanks

User avatar
Westcott
Posts: 547
Joined: Tuesday 09 December 2014 18:04
Target OS: Raspberry Pi
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: "last seen" value not being updated with latest Domoticz

Post by Westcott » Saturday 12 August 2017 0:59

Aren't SQL equals tests just a single '=' ?
Zwave - Sigma Z+ stick, Fibaro 2x FGSD002, FGMS001
Horstmann - 2x HRT4, 2x C-stat-11, 4x ASR-ZW, TKB 2x TZ56, 2x TZ68E
Max-EQ Cube, Valve, Neo 2x door
RFXtrx433E, RFlink - 1byone driveway, doorbell, Oregon and BangGood temp
Wifi - YeeLight RGB, 3x ESP8266

ileneken3
Posts: 6
Joined: Wednesday 09 August 2017 0:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: "last seen" value not being updated with latest Domoticz

Post by ileneken3 » Saturday 12 August 2017 4:40

Looking around the code, sometimes single = is used, sometimes double =. I assume that means that either are OK.

ileneken3
Posts: 6
Joined: Wednesday 09 August 2017 0:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: "last seen" value not being updated with latest Domoticz

Post by ileneken3 » Saturday 12 August 2017 22:08

It seems like there is some sort of mismatch between 7 digit and 8 digit indexes stored in the database.
I changed:

sprintf(szIdx, "%X%02X%02X%02X", 0, 0, 0, Idx);

to:

sprintf(szIdx, "%0X%02X%02X%02X", 0, 0, 0, Idx);

and then the last seen time of the heartbeat was seen again. But I don't know what the correct solution is, as there is a lot of similar code, and this doesn't fix it for all nodes.

velkrosmaak
Posts: 14
Joined: Friday 15 April 2016 23:45
Target OS: Linux
Domoticz version:
Contact:

Re: "last seen" value not being updated with latest Domoticz

Post by velkrosmaak » Sunday 13 August 2017 4:08

I have a mysensors PIR, LDR and temperature node, and recently the PIR has stopped working. I'm seeing this in the logs:

Code: Select all

2017-08-13 03:04:31.648 Error: EventSystem: in PIR timeout: [string "--..."]:29: attempt to index global 'timestamp' (a nil value)
Could this be related? I am using mysensors 1.5.1 on the gateway and sensor - I know I need to upgrade. Not sure if this happened since the recent Domoticz update, if so - is that the problem? 1.5.1 is no longer supported?

ileneken3
Posts: 6
Joined: Wednesday 09 August 2017 0:55
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: "last seen" value not being updated with latest Domoticz

Post by ileneken3 » Tuesday 15 August 2017 3:55

I don't think it's related. I was on the latest Mysensors, and the problems started when I updated to the latest Domoticz.

After removing and re-adding nodes (to make sure they are 8 digits), the "last seen" is now being updated again.

But now I don't get any notifications! :(

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests