Page 1 of 1
[SOLVED].silent() behaviour
Posted: Tuesday 14 May 2019 8:33
by acaonweb
hi guys,
i would like to undestand the behaviour of this script
Code: Select all
return {
on = {
devices = {
'Leaf Moisture 01','Leaf Moisture 02'
}
},
execute = function(dz, device)
local h1=dz.devices('Leaf Moisture 01').state
local h2=dz.devices('Leaf Moisture 02').state
local newh1=tonumber(h1)
local newh2=tonumber(h2*5.5)
if(newh1>=70) then
newh1=70
end
if(newh2>=70) then
newh2=70
end
dz.log(newh1)
dz.log(newh2)
if(device.name=='Leaf Moisture 01') then
dz.devices('Leaf Moisture 01').updateCustomSensor(newh1).silent()
dz.notify('Hum01','Rescale',dz.PRIORITY_NORMAL,0,'iPhone6S',dz.NSS_PUSHOVER)
end
if(device.name=='Leaf Moisture 02') then
dz.devices('Leaf Moisture 02').updateCustomSensor(newh2).silent()
dz.notify('Hum02','Rescale',dz.PRIORITY_NORMAL,0,'iPhone6S',dz.NSS_PUSHOVER)
end
end
}
}
when the device is triggered, for example 'Leaf Moisture 1' , i get a double notification, although .silent() is on the updateCustomSensor statment.
What's wrong?
Re: .silent() behaviour
Posted: Tuesday 14 May 2019 8:49
by waaren
acaonweb wrote: Tuesday 14 May 2019 8:33
I would like to understand the behaviour of this script
When the device is triggered, for example 'Leaf Moisture 1' , I get a double notification, although .silent() is on the updateCustomSensor statment.
What is the hardware / type / subtype of these devices ?
Can you please show us the log lines ?
Re: .silent() behaviour
Posted: Wednesday 15 May 2019 11:38
by acaonweb
sensors are dummy, subtype custom sensors, linked to an esp8266 with espeasy and mqtt.
For the log i have to wait when the sensors trig the script, because if i force it for example adding a button in the device section, the script works fine
Re: .silent() behaviour
Posted: Wednesday 15 May 2019 12:02
by waaren
acaonweb wrote: Wednesday 15 May 2019 11:38
... because if i force it for example adding a button in the device section, the script works fine
That's why I asked for the log, as I expect that domoticz receive two updates from the espeasy / mqtt and therefore the script will be triggered twice.
Re: .silent() behaviour
Posted: Wednesday 15 May 2019 12:51
by acaonweb
ok, i'll send log asap

Re: .silent() behaviour
Posted: Wednesday 15 May 2019 13:12
by acaonweb
Code: Select all
2019-05-15 13:10:17.552 MQTT: Topic: domoticz/in, Message: {"idx":147,"RSSI":7,"nvalue":0,"svalue":"50.1"}
2019-05-15 13:10:17.707 Status: dzVents: Info: Handling events for: "Leaf Moisture 01", value: "50.1"
2019-05-15 13:10:17.707 Status: dzVents: Info: Rescale: : ------ Start internal script: dz_sensor_rescale: Device: "Leaf Moisture 01 (Dummy)", Index: 147
2019-05-15 13:10:17.709 Status: dzVents: Debug: Rescale: : Processing device-adapter for Leaf Moisture 02: Custom sensor device adapter
2019-05-15 13:10:17.709 Status: dzVents: Info: Rescale: : 50.1
2019-05-15 13:10:17.709 Status: dzVents: Info: Rescale: : 70
2019-05-15 13:10:17.709 Status: dzVents: Info: Rescale: : ------ Finished dz_sensor_rescale
2019-05-15 13:10:17.709 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-05-15 13:10:17.750 Status: Notification: Hum01
2019-05-15 13:10:18.715 Notification sent (pushover) => Success
2019-05-15 13:10:22.409 MQTT: Topic: domoticz/in, Message: {"idx":147,"RSSI":8,"nvalue":0,"svalue":"39.7"}
2019-05-15 13:10:22.567 Status: dzVents: Info: Handling events for: "Leaf Moisture 01", value: "39.7"
2019-05-15 13:10:22.567 Status: dzVents: Info: Rescale: : ------ Start internal script: dz_sensor_rescale: Device: "Leaf Moisture 01 (Dummy)", Index: 147
2019-05-15 13:10:22.568 Status: dzVents: Debug: Rescale: : Processing device-adapter for Leaf Moisture 02: Custom sensor device adapter
2019-05-15 13:10:22.568 Status: dzVents: Info: Rescale: : 39.7
2019-05-15 13:10:22.568 Status: dzVents: Info: Rescale: : 70
2019-05-15 13:10:22.568 Status: dzVents: Info: Rescale: : ------ Finished dz_sensor_rescale
2019-05-15 13:10:22.569 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2019-05-15 13:10:22.603 Status: Notification: Hum01
2019-05-15 13:10:23.538 Notification sent (pushover) => Success
Re: .silent() behaviour
Posted: Wednesday 15 May 2019 13:14
by acaonweb
it seems i have two mqtt update... so it's probably something on easyesp side?
Re: .silent() behaviour
Posted: Wednesday 15 May 2019 15:54
by waaren
acaonweb wrote: Wednesday 15 May 2019 13:14
it seems i have two mqtt update... so it's probably something on easyesp side?
It seems that the espEasy is sending two MQTT messages. The second one 5 seconds after the other. But with 11 degrees difference. Is that what you expect or could it be that one value is temperature and the second one moisture (or vice versa)?
For another user I coded a dzVents work around that could help you to prevent a second notification. Check
here
Re: .silent() behaviour
Posted: Thursday 16 May 2019 16:09
by acaonweb
Thanks, i think i've undestood.
my sensor is in deep sleep mode and wakes up every 4000 seconds to preserve batteries. It stays up 7 seconds
Probably the samples frequency is every 5 seconds (i think is a default in the device settings) so, one sample at start, one after 5 seconds and the fall to sleep again.
I'll youse your script to send a notificatione once

Thanx a lot!!!!
Re: .silent() behaviour
Posted: Thursday 16 May 2019 16:12
by acaonweb
i can't find in wiki lastUsed statement... how it works?
Re: .silent() behaviour
Posted: Thursday 16 May 2019 17:19
by waaren
acaonweb wrote: Thursday 16 May 2019 16:12
i can't find in wiki lastUsed statement... how it works?
lastUsed is a table that is created and kept as a file by dzVents. It gets populated with the device id as key and the lastTime the script executed your code as value (in seconds since 1/1/1970)
Can you check if this does work for you ?
Code: Select all
return {
on = { devices =
{ 'Leaf Moisture 01',
'Leaf Moisture 02'
}
},
data = { lastUsed = { initial = {}}},
execute = function(dz, device)
local function shouldScriptStop(id, minTimeBetweenExecution)
if dz.data.lastUsed[id] then
return ( tonumber(dz.data.lastUsed[id]) > ( dz.time.dDate - minTimeBetweenExecution ) )
end
end
-- Check if script should continue
if shouldScriptStop(device.id, 10) then -- 10 is the amount of seconds that script need to ignore repeated calls per device. Change to the value you need
dz.log("Script will not continue",dz.LOG_FORCE )
return
else
dz.data.lastUsed[device.idx] = dz.time.dDate
end
local h1=dz.devices('Leaf Moisture 01').state
local h2=dz.devices('Leaf Moisture 02').state
local newh1=tonumber(h1)
local newh2=tonumber(h2*5.5)
if(newh1>=70) then
newh1=70
end
if(newh2>=70) then
newh2=70
end
dz.log(newh1)
dz.log(newh2)
if(device.name=='Leaf Moisture 01') then
dz.devices('Leaf Moisture 01').updateCustomSensor(newh1).silent()
dz.notify('Hum01','Rescale',dz.PRIORITY_NORMAL,0,'iPhone6S',dz.NSS_PUSHOVER)
end
if(device.name=='Leaf Moisture 02') then
dz.devices('Leaf Moisture 02').updateCustomSensor(newh2).silent()
dz.notify('Hum02','Rescale',dz.PRIORITY_NORMAL,0,'iPhone6S',dz.NSS_PUSHOVER)
end
end
}
Re: .silent() behaviour
Posted: Friday 17 May 2019 8:19
by acaonweb
wow!!!
I'll have a look asap

let me update on my domoticz