Script always loop!

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

Moderator: leecollings

Post Reply
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Script always loop!

Post 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
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Script always loop!

Post 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

Docker in Truenas scale, close to latest beta
DASHTICZ ๐Ÿ™ƒ
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script always loop!

Post 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!
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Script always loop!

Post 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


Docker in Truenas scale, close to latest beta
DASHTICZ ๐Ÿ™ƒ
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script always loop!

Post 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"
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Script always loop!

Post 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

Docker in Truenas scale, close to latest beta
DASHTICZ ๐Ÿ™ƒ
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script always loop!

Post 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.
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Script always loop!

Post 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

Docker in Truenas scale, close to latest beta
DASHTICZ ๐Ÿ™ƒ
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script always loop!

Post by Nefsolive »

Make sense yes!
I need do a verification first.
I go try like you say ;)

Thank for your help heggink.
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Script always loop!

Post by heggink »

Sure. Let me know if you have any questions.
Herman

Sent from my SM-G980F using Tapatalk

Docker in Truenas scale, close to latest beta
DASHTICZ ๐Ÿ™ƒ
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Nefsolive
Posts: 69
Joined: Monday 04 September 2017 17:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Script always loop!

Post 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
User avatar
heggink
Posts: 980
Joined: Tuesday 08 September 2015 21:44
Target OS: Raspberry Pi / ODroid
Domoticz version: 12451
Location: NL
Contact:

Re: Script always loop!

Post by heggink »

Excellent!

Sent from my SM-G980F using Tapatalk

Docker in Truenas scale, close to latest beta
DASHTICZ ๐Ÿ™ƒ
RFXCOM, zwavejs2mqtt, zigbee2mqtt,
P1 meter & solar panel
Google home, Wifi Cams motion detection
Geofence iCloud, Bluetooth & Wifi ping
Harmony hub, Nest, lots more :-)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest