[SOLVED].silent() behaviour

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

Moderator: leecollings

Post Reply
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

[SOLVED].silent() behaviour

Post 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?
Last edited by acaonweb on Tuesday 21 May 2019 21:10, edited 1 time in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: .silent() behaviour

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: .silent() behaviour

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: .silent() behaviour

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: .silent() behaviour

Post by acaonweb »

ok, i'll send log asap :)
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: .silent() behaviour

Post 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
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: .silent() behaviour

Post by acaonweb »

it seems i have two mqtt update... so it's probably something on easyesp side?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: .silent() behaviour

Post 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
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: .silent() behaviour

Post 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!!!!
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: .silent() behaviour

Post by acaonweb »

i can't find in wiki lastUsed statement... how it works?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: .silent() behaviour

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
acaonweb
Posts: 92
Joined: Thursday 23 March 2017 14:18
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: .silent() behaviour

Post by acaonweb »

wow!!!
I'll have a look asap :)
let me update on my domoticz
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest