Page 1 of 1
Script always loop!
Posted: Saturday 28 May 2022 20:27
by Nefsolive
Hello,
Wen the value is > 100 i recebe loop mensage.
Any help how too stop script loop!
Code: Select all
return {
active = true,
on = {
devices = {'Bonsai',}
},
execute = function(dz, device)
if dz.devices('Bonsai').nValue < 100 then
dz.notify("🔔 Bonsai Rega", 'Ver se o Bonsai Precisa de Rega!', dz.PRIORITY_NORMAL, dz.SOUND_MAGIC, "" , dz.NSS_PUSHOVER)
end
end
}
Thanks
Re: Script always loop!
Posted: Saturday 28 May 2022 20:58
by heggink
Add a print statement at the beginning (before the if) showing the value of bonsai.nvalue. That way, you know when the script gets triggered and with what value.
Why doesn't bonsai (is this a humidity device?) have a native value field instead of nvalue?
Sent from my SM-G980F using Tapatalk
Re: Script always loop!
Posted: Saturday 28 May 2022 21:13
by Nefsolive
Hello heggink,
Thanks for your attention and reply.
Yes, Bonsai is humidity device.
On log Bonsai show me the correct value whit nValue.
And its work! But always recebe loop notify!
Re: Script always loop!
Posted: Saturday 28 May 2022 21:18
by heggink
Change:
if dz.devices('Bonsai').nValue
To
if device.nValue
And add
print(device.nvalue)
Nefore the if
Sent from my SM-G980F using Tapatalk
Re: Script always loop!
Posted: Saturday 28 May 2022 21:23
by Nefsolive
Ty
I change "if device.nValue"
and still looping!
Recebe every 5 seconds notify me again.
Log Info: Handling events for: "Bonsai", value: "80"
Re: Script always loop!
Posted: Saturday 28 May 2022 21:28
by heggink
The script is triggered by device updates from the bonsai device. The print statement shows that the value is 80 which is less than 100 so that is why the script is triggered. The script works exactly as it should.
What are you expecting?
Sent from my SM-G980F using Tapatalk
Re: Script always loop!
Posted: Saturday 28 May 2022 21:32
by Nefsolive
Sorry, maybe I didn't make myself clear!
I just wanted to receive 1 notification when the script checks if the value is below 100 and not multiple notifications in a loop.
Re: Script always loop!
Posted: Saturday 28 May 2022 21:46
by heggink
Ah, then add the data section to your script and add a variable that you use to check if you already sent the message.
Something like message_sent with initial value 0
In your script, you can check for if dz.data.message_sent == 0 then
Send a message...
dz.data.message_sent = 1
The only other thing you also need to do is reset it if the humidity is high enough again:
If device.nvalue > 100 then
dz.data.message_sent = 0
Makes sense? Bit difficult typing on my phone. Look at the dzvents wiki to find how to add an initialise that variable.
Sent from my SM-G980F using Tapatalk
Re: Script always loop!
Posted: Saturday 28 May 2022 21:51
by Nefsolive
Make sense yes!
I need do a verification first.
I go try like you say
Thank for your help heggink.
Re: Script always loop!
Posted: Saturday 28 May 2022 21:52
by heggink
Sure. Let me know if you have any questions.
Herman
Sent from my SM-G980F using Tapatalk
Re: Script always loop!
Posted: Saturday 28 May 2022 22:47
by Nefsolive
Herman,
I did as you said and it's working fine!

Once again, thanks for your help.
Send the Script;
Code: Select all
return {
active = true,
on = {
devices = {'Bonsai',}
},
data = {
message_sent = { initial = 0 }
},
execute = function(dz, device)
if device.nValue < 100 then
if dz.data.message_sent == 0 then
dz.notify("🔔 Bonsai Rega", 'Ver se o Bonsai Precisa de Rega!', dz.PRIORITY_NORMAL, dz.SOUND_MAGIC, "" , dz.NSS_PUSHOVER)
dz.data.message_sent = 1
end
end
if device.nValue > 100 then
dz.data.message_sent = 0
end
end
}
Best regards
Re: Script always loop!
Posted: Saturday 28 May 2022 23:01
by heggink
Excellent!
Sent from my SM-G980F using Tapatalk