SRT323: battery level is different with dzvents and API JSON

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
benp
Posts: 52
Joined: Saturday 21 May 2016 20:12
Target OS: NAS (Synology & others)
Domoticz version: V4.10717
Location: France
Contact:

SRT323: battery level is different with dzvents and API JSON

Post by benp »

I use the following script to monitor the srt323 thermostat battery level:
Script1:

Code: Select all

return {
      on = {
      timer = {'every minute'}
	},   
    execute = function(domoticz, dummy)        
        local thermostat = domoticz.devices('SRT323')
        print('pile=' .. thermostat.batteryLevel)
        domoticz.devices('Pile Thermostat').updatePercentage(thermostat.batteryLevel)        
    end
}
This give the following graph:
last-year.png
last-year.png (83.92 KiB) Viewed 546 times
Today: my battery level is 53% with domoticz.devices('SRT323').batteryLevel

With the API JSON:

Code: Select all

http://192.168.0.4:8080/json.htm?type=devices&rid=96
I have the following line:
BatteryLevel 17
Confirmed with the Email notification:
Battery Low: SRT323 (Level: 17 %)

Is my coding of the above script wrong or is this a dzvent bug?

Here is another dzvent script (my old script) with no .batterylevel usage:
Script2:

Code: Select all

return {
	on = {
      timer = {'every minute'},
      httpResponses = {'thermostat' }
	}, 
    execute = function(domoticz, item)
        if (item.isTimer) then
            print('http envoi thermostat')
            domoticz.openURL({
                url = 'http://192.168.0.4:8080/json.htm?type=devices&rid=96',
                callback = 'thermostat'
             })
        end
        if (item.isHTTPResponse and item.ok) then
            local pile =item.json.result[1]['BatteryLevel']
            print('http response thermostat: ' .. pile)
        end
    end
}
Note:
If you are interest in my SRT323 parameter to have an idea of the battery life time:
1. Temperature sensor reading:enabled
2. Temperature Scale: Celcius
3. Delta T: Temperature change: 5 (=0.5°C)
2000. Wake-up Interval: (Seconds) 500
But the SRT323 battery life time depends on the number of switching too: in my case: no switching during summer=less battery usage.

Note 2 (edit):
17% is 1.22V for on battery
96% is 1.58V for one battery
Last edited by benp on Saturday 14 December 2019 20:30, edited 2 times in total.
Domoticz V2024.7
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: SRT323: battery level is different with dzvents and API JSON

Post by waaren »

benp wrote: Saturday 14 December 2019 10:40 Today: my battery level is 53% with domoticz.devices('SRT323').batteryLevel
With the API JSON:

Code: Select all

http://192.168.0.4:8080/json.htm?type=devices&rid=96
BatteryLevel 17
Is my coding of the above script wrong or is this a dzVents bug?
Both scripts seem to be ok. Domoticz does send the same data to dzVents as what is shows when called by the API.
If I compare the dzVents batteryLevel from all my battery enabled devices to what I get back from the API and to what I see on the GUI, the max delta = 1%
What do you see in the log from the print statement ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
benp
Posts: 52
Joined: Saturday 21 May 2016 20:12
Target OS: NAS (Synology & others)
Domoticz version: V4.10717
Location: France
Contact:

Re: SRT323: battery level is different with dzvents and API JSON

Post by benp »

What do you see in the log from the print statement ?
print=17% and 17% in setup/devices.

Since my last post, I did the following:
1- I start script 1 and script 2, script 1 failed to 17%
2 -I replaced my batteries and stopped script 2.
API JSON and setup/devices gives 96%
script 1 (domoticz.devices('SRT323').batteryLevel) still gives 17%
3-I start script 1 and script 2: still the same:
script 2, API JSON and setup/devices gives 96%
script 1 (domoticz.devices('SRT323').batteryLevel) still gives 17%
4-I reboot the raspberry: right values with script 1
script 2, API JSON and setup/devices gives 96%
script 1 (domoticz.devices('SRT323').batteryLevel) still gives 96%

Note script 2 is now for easier monitoring:

Code: Select all

return {
	on = {
      --timer = {'every hour'},
      timer = {'every minute'},
      httpResponses = {'thermostat' }
	},   --data = {
         --flagVeil = { initial = true }, --true si pas de notification envoyee
    --},
    execute = function(domoticz, item)
        if (item.isTimer) then
            print('http envoi thermostat')
            domoticz.openURL({
                url = 'http://192.168.0.4:8080/json.htm?type=devices&rid=96',
                callback = 'thermostat'
             })
        end
        if (item.isHTTPResponse and item.ok) then
            --local json = domoticz.utils.fromJSON(item.data)
            local pile =item.json.result[1]['BatteryLevel']
            print('http response thermostat: ' .. pile)
            domoticz.devices('Pile thermostat2').updatePercentage(pile)
        end
    end
}
Domoticz V2024.7
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: SRT323: battery level is different with dzvents and API JSON

Post by waaren »

benp wrote: Saturday 14 December 2019 10:40 Today: my battery level is 53% with domoticz.devices('SRT323').batteryLevel
With the API JSON: BatteryLevel 17
Is my coding of the above script wrong or is this a dzvent bug?
I rembered that I met this before.... I wrote a workaround script a couple of months ago.
I short: The batteryLevel of devices is send from domoticz to the event-system (including Lua, Blockly and dzVents) only when the Event-system is started.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
benp
Posts: 52
Joined: Saturday 21 May 2016 20:12
Target OS: NAS (Synology & others)
Domoticz version: V4.10717
Location: France
Contact:

Re: SRT323: battery level is different with dzvents and API JSON

Post by benp »

A workaround, if you need accurate and up to date data for your batteryLevel, could be
I don't understand everything in your script. Is 255 means "not update value"?

My JSON API script2 returns 255 instead of the right value from time to time.
Here is the log:
last-3-days-bd.png
last-3-days-bd.png (33.3 KiB) Viewed 497 times
you can force it by stop of the eventSystem in setings followed by a start.
How can you do this(stop/start eventSystem)?
Domoticz V2024.7
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: SRT323: battery level is different with dzvents and API JSON

Post by waaren »

benp wrote: Sunday 15 December 2019 10:58 I don't understand everything in your script. Is 255 means "not update value"?
255 means that the device has no value for battery level. Batterylevels are reported from 0-100
how can you do this(stop/start eventSystem)?
[Setup][Settings][Other]
disable EventSystem (Lua/Blockly/Scripts): and dzVents:
[Apply settings]

[Setup][Settings][Other]
enable EventSystem (Lua/Blockly/Scripts): and dzVents:
[Apply settings]
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest