Page 1 of 2
Error on batterylevel of added device [SOLVED]
Posted: Wednesday 17 March 2021 10:34
by EddyG
System info:
Version: 2020.2 (build 13058)
Build Hash: 066f3f261-modified
Compile Date: 2021-03-08 16:27:50
dzVents Version: 3.1.5
Python Version: 3.7.3 (default, Jul 25 2020, 13:03:44) [GCC 8.3.0]
This scripts runs for many years now and runs as it should be.
Code: Select all
local BATTERY_THRESHOLD = 10
return {
active = true,
-- active = false,
on = {
-- timer = { 'every hour' }
-- timer = { 'every minute' }
timer = { 'at 08:09' }
},
execute = function(domoticz)
local message = ''
-- first filter on low battery level
local lowOnBat = domoticz.devices().filter(function(device)
local level = device.batteryLevel -- level is 0-100
return (level ~= nil and -- not all devices have this attribute
level <= BATTERY_THRESHOLD and level ~= 1 and level ~= 0 )
end)
-- then loop over the results
lowOnBat.forEach(function(lowDevice)
message = message .. 'Device ' ..
lowDevice.name .. ' is low on batteries (' .. tostring(lowDevice.batteryLevel) .. '), '
end)
if (message ~= '') then
domoticz.notify('Low battery warning', message, domoticz.PRIORITY_NORMAL)
domoticz.log('Low battery warning: ' .. message, domoticz.LOG_ERROR)
end
end
}
I added a new zigbee device
https://www.zigbee2mqtt.io/devices/TS00 ... uya-ts0044 and that is working well too, no errors.
In the domoticz database on all 3 devices of this switch and in the the zigbee2mqtt logging the battery percentage is 100 (%)
It's a new added device with a NEW battery.
So no error there too.
But now (only on the switch device itself) I get this error message every day.
Code: Select all
2021-03-17 10:21:00.739 Error: dzVents: Error: (3.1.5) Low battery warning: Device Zigbee - Wallmote (action) is low on batteries (-1485883288),
What is going wrong?
Re: Error on batterylevel of added device
Posted: Wednesday 17 March 2021 11:15
by waaren
EddyG wrote: ↑Wednesday 17 March 2021 10:34
But now (only on the switch device itself) I get this error message every day.
Code: Select all
2021-03-17 10:21:00.739 Error: dzVents: Error: (3.1.5) Low battery warning: Device Zigbee - Wallmote (action) is low on batteries (-1485883288),
It seems that dzVents does receive a wrong value from the event system. What do you see for this device in
<domoticz dir>/scripts/dzVents/domoticzData.lua if you set the dzVents wide loglevel to debug (everything) on the setting page?
To prevent the error form going to your log you could change line
Code: Select all
level <= BATTERY_THRESHOLD and level ~= 1 and level ~= 0 )
Code: Select all
level <= BATTERY_THRESHOLD and level > 1 )
But that does not solve the problem and I don't know what batteryLevel will be passed from the eventSystem to domoticz when the battery level will drop below 100%
Re: Error on batterylevel of added device
Posted: Wednesday 17 March 2021 11:28
by EddyG
This in that file:
Code: Select all
[229] = {
["switchType"] = "Selector";
["rawData"] = {
[1] = "0";
};
["signalLevel"] = -1485883360;
["description"] = "";
["name"] = "Zigbee - Wallmote (action)";
["deviceID"] = "";
["baseType"] = "device";
["image"] = "";
["deviceType"] = "Light/Switch";
["timedOut"] = false;
["lastLevel"] = 110;
["protected"] = false;
["changed"] = false;
["batteryLevel"] = -1485883288;
["iconNumber"] = 104;
["data"] = {
["usedByCamera"] = false;
["protected"] = false;
["unit"] = 233;
["hardwareType"] = "Zigbee2MQTT";
["icon"] = "Light";
["customImage"] = 9;
["hardwareTypeValue"] = 94;
["hardwareName"] = "Zigbee";
["levelActions"] = "";
["Image"] = "Generic";
["_nValue"] = 0;
["levelOffHidden"] = false;
["hardwareID"] = 1953088;
["levelNames"] = "Off|1_single|1_double|1_hold|2_single|2_double|2_hold|3_single|3_double|3_hold|4_single|4$
["_state"] = "Off";
["maxDimLevel"] = 100;
["levelVal"] = 0;
};
["subType"] = "Selector Switch";
["switchTypeValue"] = 18;
["lastUpdate"] = "2021-03-15 17:16:10";
["id"] = 1291;
};
The same ["batteryLevel"] = -1485883288; is there. And signallevel also has a strange value.
This comes in zigbee2mqtt when I press a button.
Code: Select all
info 2021-03-17 11:27:18: MQTT publish: topic 'zigbee2mqtt/Wallmote', payload '{"battery":100,"last_seen":"2021-03-17T11:27:18+01:00","linkquality":99}'
info 2021-03-17 11:27:19: MQTT publish: topic 'zigbee2mqtt/Wallmote', payload '{"action":"1_single","battery":100,"last_seen":"2021-03-17T11:27:19+01:00","linkquality":99}'
info 2021-03-17 11:27:19: MQTT publish: topic 'zigbee2mqtt/Wallmote', payload '{"action":"","battery":100,"last_seen":"2021-03-17T11:27:19+01:00","linkquality":99}'
info 2021-03-17 11:27:19: MQTT publish: topic 'zigbee2mqtt/Wallmote/action', payload '1_single'
I also set the zigbee2mqt plugin to debug.
Nothing strange in the logging about the battery of that device.
Just noticed that when I set the logging of the plugin back to 'False' Domoticz crashed, but that is probably unrelated.
Re: Error on batterylevel of added device
Posted: Wednesday 17 March 2021 13:41
by waaren
EddyG wrote: ↑Wednesday 17 March 2021 11:28
The same ["batteryLevel"] = -1485883288; is there. And signallevel also has a strange value.
Can you please execute below script and share the outcome?
Code: Select all
--[[
dzVents scripts to dump some attributes known to dzVents and the values in the database from a given device.
Requires dzVents >= 3.1.0 and sqlite3 installed on domoticz server
if you don't have sqlite3 yet on your system install it with sudo apt install sqlite3
]]--
-- enter your settings below this line
local myDevice = 3236 -- device idx number
local sqlite = '/usr/local/bin/sqlite3' -- find your sqlite3 location with "which sqlite3" and change here accordingl
local runAt = '13:39' -- change to the time you want to dump the attributes of the device
--- No changes required below this line
local scriptVar = 'dumpAttributes'
return
{
on =
{
timer =
{
'at '.. runAt ,
},
shellCommandResponses =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function(dz, item)
local myDevice = dz.devices(myDevice) -- your device idx
local function osCommand(cmd)
dz.executeShellCommand(
{
command = cmd,
callback = scriptVar,
timeout = 15,
})
end
local function dumpAttributes(dv)
dz.log(dv.idx .. ': ' .. dv.name .. ': attribute -> value',dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': -- dzVents',dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': type, subType -> ' .. dv.deviceType .. ', '.. tostring(dv.deviceSubType),dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': switchTypeValue -> ' .. dv.switchTypeValue ,dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': adapters -> ' .. dz.utils._.str(dv._adapters),dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': rawData -> ' .. dz.utils._.str(dv.rawData),dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': hwType -> ' .. dv.hardwareType .. ', ' .. dv.hardwareTypeValue,dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': levelNames -> ' .. dz.utils._.str(dv.levelNames),dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': modes -> ' .. dz.utils._.str(dv.modes),dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': batteryLevel -> ' .. dz.utils._.str(dv.batteryLevel),dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': signal -> ' .. dz.utils._.str(dv.signalLevel),dz.LOG_FORCE)
end
local function dumpDeviceStatus(sqlResult, dv)
sqlResult = dz.utils.stringSplit(sqlResult,'\n')
local header = dz.utils.stringSplit(sqlResult[1],'|')
local values = dz.utils.stringSplit(sqlResult[2],'|')
dz.log(dv.idx .. ': ' .. dv.name .. ': field -> value',dz.LOG_FORCE)
dz.log(dv.idx .. ': ' .. dv.name .. ': -- database',dz.LOG_FORCE)
for index, attribute in ipairs(header) do
dz.log(dv.idx .. ': ' .. dv.name .. ': ' .. dz.utils.rightPad(( attribute or '') ,15) .. ' -> ' .. ( values[index] or 'nil') ,dz.LOG_FORCE)
end
end
if item.isTimer or item.isDevice then
osCommand('sudo ' .. sqlite .. ' ' .. '-header domoticz.db "select * from deviceStatus where id = ' .. myDevice.idx .. '"')
elseif item.ok then
dumpDeviceStatus(item.data, myDevice)
dumpAttributes(myDevice)
dz.log('',dz.LOG_FORCE)
else
dz.log('Problem with os command', dz.LOG_ERROR)
dz.log(item, dz.LOG_DEBUG)
end
end
}
Re: Error on batterylevel of added device
Posted: Wednesday 17 March 2021 13:58
by EddyG
Enclosed the output. I could not see anything special.
Re: Error on batterylevel of added device
Posted: Wednesday 17 March 2021 15:52
by waaren
EddyG wrote: ↑Wednesday 17 March 2021 13:58
Enclosed the output. I could not see anything special.
I used this data to create the exact same device with all attributes in my test / development database and used your script but cannot reproduce the issue. The only difference I can think of is the build number.
I am build 13084.
Re: Error on batterylevel of added device
Posted: Wednesday 17 March 2021 16:01
by EddyG
I am on build 13058. I will change to 13084 and check again.
I used to script to check the database and found out that everything is OK and only got 1 duplicate. So database is fine.
I am on 13084 now and problem is gone. Go figure.
Re: Error on batterylevel of added device
Posted: Thursday 18 March 2021 9:27
by EddyG
What I also did is using all the files of build 13084 but the executable of build 13058.
Result: NO errors. More mystery.
Re: Error on batterylevel of added device
Posted: Thursday 18 March 2021 12:08
by waaren
EddyG wrote: ↑Thursday 18 March 2021 9:27
What I also did is using all the files of build 13084 but the executable of build 13058.
Result: NO errors. More mystery.
If you can reproduce the error when using build 13058 (binary and files), I would be interested to see the changes between these two sets of files.
Code: Select all
sudo diff <base directory 13058> <base directory 13084>
Re: Error on batterylevel of added device
Posted: Thursday 18 March 2021 12:52
by EddyG
That is the funny part: nothing differs, below the output (I did not include the domocookie.txt part)
So it is only in the executable.
Code: Select all
Common subdirectories: /home/pi/domoticz/Config and /media/RPiSys/save/domoticz-beta/Config
Binary files /home/pi/domoticz/domoticz and /media/RPiSys/save/domoticz-beta/domoticz differ
Binary files /home/pi/domoticz/domoticz.db and /media/RPiSys/save/domoticz-beta/domoticz.db differ
Binary files /home/pi/domoticz/domoticz.db-shm and /media/RPiSys/save/domoticz-beta/domoticz.db-shm differ
Binary files /home/pi/domoticz/domoticz.db-wal and /media/RPiSys/save/domoticz-beta/domoticz.db-wal differ
Common subdirectories: /home/pi/domoticz/dzVents and /media/RPiSys/save/domoticz-beta/dzVents
diff /home/pi/domoticz/History.txt /media/RPiSys/save/domoticz-beta/History.txt
1c1
< Version 2020.xxxxx (xxxxx)
---
> Version 2020.xxxxx (xxxx)
32c32
< - Updated: dzVents; version 3.1.6 ( https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting )
---
> - Updated: dzVents; version 3.1.5 ( https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting )
Common subdirectories: /home/pi/domoticz/plugins and /media/RPiSys/save/domoticz-beta/plugins
Common subdirectories: /home/pi/domoticz/scripts and /media/RPiSys/save/domoticz-beta/scripts
Common subdirectories: /home/pi/domoticz/www and /media/RPiSys/save/domoticz-beta/www
So I suppose that Domoticz might had a memory problem that caused the issue.
I should have restarted Domoticz in the 13058 build to see if the problem disappeared.
Re: Error on batterylevel of added device
Posted: Thursday 18 March 2021 13:11
by waaren
EddyG wrote: ↑Thursday 18 March 2021 12:52
That is the funny part: nothing differs, below the output (I did not include the domocookie.txt part)
So it is only in the executable.
If I check the files changed between these version using git diff, I see more files (left out the source files). Are you sure you copy the dzVents, Config, www and plugin folders when updating / downgrading ?
Code: Select all
git diff --name-only 066f3f261 28e6925de
- Spoiler: show
Code: Select all
Config/eurotronic/eur_spiritz.xml
Config/fibaro/fgwds221.xml
Config/manufacturer_specific.xml
Config/zooz/zen23v3.xml
Config/zooz/zen24v2.xml
Config/zooz/zen34.xml
plugins/AwoxSMP/plugin.py
plugins/examples/BaseTemplate.py
plugins/examples/DenonMarantz.py
plugins/examples/Dlink DSP-W215.py
plugins/examples/HTTP Listener.py
dzVents/runtime/Device.lua
dzVents/runtime/Time.lua
dzVents/runtime/Utils.lua
plugins/AwoxSMP/plugin.py
plugins/examples/BaseTemplate.py
plugins/examples/DenonMarantz.py
plugins/examples/Dlink DSP-W215.py
plugins/examples/HTTP Listener.py
plugins/examples/HTTP.py
plugins/examples/Kodi.py
plugins/examples/MQTT Publish.py
plugins/examples/MQTT Subscribe.py
plugins/examples/Mutli-Threaded.py
plugins/examples/Pinger.py
plugins/examples/RAVEn.py
plugins/examples/UDP Discovery.py
Re: Error on batterylevel of added device
Posted: Thursday 18 March 2021 14:22
by EddyG
Found out that I had to use the -r options with diff , because otherwise it does not compare the sub-directories.
Now I got a file of 428 Kb. I have to find out how to downsize the output.
Even a diff on the dzVents subdirectory is 95 Kb in size.
Enclosed my changed filename list.
I saw that in Time.lua a lot changed.
B.t.w. I always update with an changed updatebeta file. The only change is to save the complete Domoticz dir to a save place.
Re: Error on batterylevel of added device
Posted: Friday 19 March 2021 19:29
by EddyG
waaren wrote: ↑Wednesday 17 March 2021 15:52
I used this data to create the exact same device with all attributes in my test / development database and used your script but cannot reproduce the issue.
It ain't over yet. Today I got this message.
Code: Select all
2021-03-19 08:09:00.370 Error: dzVents: Error: (3.1.6) Low battery warning: Device Keukenkast spotjes slave OLD is low on batteries (-1350579280),
It is an inactive RFXCOM (KlikAanKlikUit) device, which has a battery but as far as I know does not send battery status/percentage.
In the database is 255 on battery, in the Domoticz Gui is just a dash.
But the same script gave the above error.
To make it even more complex that device has a 'lastseen" of 2021-03-18 09:54:34 There is nothing in the log from yesterday that triggered that device at that time.
It is not a real problem, but where is the battery trigger come from? And where does the -1350579280 come from?
Re: Error on batterylevel of added device
Posted: Friday 19 March 2021 19:51
by waaren
EddyG wrote: ↑Friday 19 March 2021 19:29
It is not a real problem, but where is the battery trigger come from? And where does the -1350579280 come from?
As far as I understand the script will just report what it gets from the domoticz event system and the event system reports what is in the database.
To debug this further you could consider to add an
Code: Select all
os.execute('cp domoticz.db domoticz.db_debug')
in the script to make a copy of the database every time the batteryLevel is below 0.
That will allow you to inspect the database in a state very close after the time of the message.
Re: Error on batterylevel of added device
Posted: Saturday 20 March 2021 11:11
by EddyG
Same value of 255 present in that saved database.
I put this in the script.
Code: Select all
if level ~= nil then
print(device.name .. " - " .. level)
end
All devices went well except the first device, and that's also the device with the strange value.
Code: Select all
2021-03-20 10:57:00.451 Status: dzVents: Info: ------ Start external script: check battery levels.lua:, trigger: "at 10
:57"
2021-03-20 10:57:00.472 Status: dzVents: Keukenkast spotjes slave OLD - -1350579280
2021-03-20 10:57:00.488 Status: dzVents: Slave Internal Temperature - 100
2021-03-20 10:57:00.494 Status: dzVents: Woonkamer - 100
I quite sure that the loop is over the idx of active devices. "Slave Internal Temperature" is the first device with battery value on it and active.
So there is something going wrong with the first (random?) device, which does not have a battery value on in other than 255 and is
NOT active.
Printed levels of the battery value corresponds with the mouseover in the GUI. So there is no shifting.
Re: Error on batterylevel of added device
Posted: Saturday 20 March 2021 11:45
by waaren
EddyG wrote: ↑Saturday 20 March 2021 11:11
Same value of 255 present in that saved database.
I cannot see anything strange in the code ( mainworker.cpp , EventSystem.cpp and dzVents.cpp) that could influence the batteryLevel passed to dzVents. So if you want to pursuit this you probably need to create an issue on github.
In the mean time I will patch dzVents/runtime/device-adapters/generic_device.lua to filter out values outside the 0-100 range.
Re: Error on batterylevel of added device
Posted: Saturday 20 March 2021 11:49
by EddyG
I think the problem is not so much as the batteryLevel passed between EventSystem and dzVents, but more that there is an extra First device added to the loop. I will look over the code too in a few days.
Re: Error on batterylevel of added device
Posted: Saturday 20 March 2021 12:17
by waaren
EddyG wrote: ↑Saturday 20 March 2021 11:49
I think the problem is not so much as the batteryLevel passed between EventSystem and dzVents, but more that there is an extra First device added to the loop. I will look over the code too in a few days.
Do you see this extra device in <domoticz dir>/scripts/dzVents/domoticzData.lua ?
I double checked but your script does not add any devices to the filter- or foreach loops.
Re: Error on batterylevel of added device
Posted: Saturday 20 March 2021 12:22
by EddyG
No the device "Keukenkast spotjes slave OLD" is NOT in <domoticz dir>/scripts/dzVents/domoticzData.lua present.
Re: Error on batterylevel of added device
Posted: Saturday 20 March 2021 13:01
by waaren
EddyG wrote: ↑Saturday 20 March 2021 12:22
No the device "Keukenkast spotjes slave OLD" is NOT in <domoticz dir>/scripts/dzVents/domoticzData.lua present.
This is becoming a bit spooky. All dzVents knows about domoticz devices is received via this table.