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?
Last edited by acaonweb on Tuesday 21 May 2019 21:10, edited 1 time in total.
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 ?
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
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.
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
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!!!!
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)
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
}