how to check positive numbers in dzvents-script

Easy to use, 100% Lua-based event scripting framework.
Post Reply
pgas37
Posts: 47
Joined: Wednesday 06 December 2017 20:44
Target OS: -
Domoticz version:
Contact:

how to check positive numbers in dzvents-script

Post by pgas37 » Tuesday 09 January 2018 17:05

Domoticz v 3.8153
Raspberrypi v3

Hallo.

in a dzvents-script i want to check a rise in temperature >3:
if (current) >= vochtpercentage or (delta_5 >= 3) then... ". In this case a rise as well as a drop of temperature with 3 will trigger the THEN

a "+"-sign is not accepted. the same for ():
if (current) >= vochtpercentage or (delta_5 >= +3) then..
if (current) >= vochtpercentage or (delta_5 >= (+3)) then..

I cannot find the right answer.

Please help
thanks
Paul

User avatar
emme
Posts: 798
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: how to check positive numbers in dzvents-script

Post by emme » Tuesday 09 January 2018 17:37

maybe
math.abs(delta_5) >= 3 ?

so you will trigger a +3 difference as well as a -3 difference
That's one small step for a programmer, one giant leap for me!
- - - - -
Raspberry Pi3 + AeonStick G5 + RFXCOMM433 + iRTrans Server + NodeJS
There's no stress in the mess!!

User avatar
waaren
Posts: 469
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: how to check positive numbers in dzvents-script

Post by waaren » Tuesday 09 January 2018 19:00

Hi Paul,

to help a bigger snippit of your code is needed.

As far as I understand from this line and your description, delta_5 is positive integer or float and therefore it cannot be used for this purpose on its own.
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

pgas37
Posts: 47
Joined: Wednesday 06 December 2017 20:44
Target OS: -
Domoticz version:
Contact:

Re: how to check positive numbers in dzvents-script

Post by pgas37 » Tuesday 09 January 2018 22:00

Emme,
-3 is what i do not want only a positive rise.

Waaren,

I include two parts of the code. The delta_5 is a difference in temperature (degrees) in a 5-minute interval.
Every 5 minutes the current temperature ("current") becomes humidityTmin5 and
the former Tmin5 becomes the Tmin10.
If the rise in temperature in 5 minutes is more then 3degree a fan is activated.
The code sees no difference between +3 and -3, so if the temperature drops more than 3degrees in 5 minutes the fan is also activated. I do
not want that to happen.

hope you can help
regards
Paul

==========
--delta =
delta_10 = (current - humidityTmin10)
if PRINT_MODE == true then
print ('Stijging/daling laatste 10 min: ' ..delta_10) --stijging/daling laatste 10 minuten
end
delta_5 = (humidityTmin5 - humidityTmin10) --stijging/daling laatste 5 min
if PRINT_MODE == true then
print ('Stijging/daling laatste 5 min. ' ..delta_5)
end
===================
-- fan (de)activeren
if (current) >= vochtpercentage or (delta_5 >= 3) then
domoticz.devices(vent_schakelaar).switchOn()
if Off_timer == 2 then
domoticz.notify('ventilator aan (>61%)', ' vochtpercentage en delta_t5 : ' ..current ..delta_5, domoticz.PRIORITY_LOW)
end
===================

pgas37
Posts: 47
Joined: Wednesday 06 December 2017 20:44
Target OS: -
Domoticz version:
Contact:

Re: how to check positive numbers in dzvents-script

Post by pgas37 » Tuesday 09 January 2018 22:02

mistake:
read temperature = humidity

paul

User avatar
waaren
Posts: 469
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: how to check positive numbers in dzvents-script

Post by waaren » Wednesday 10 January 2018 2:17

Hi Paul,

are you sure that the fan is triggered by the (delta_5 >= 3) part of the expression and not by the (current) >= vochtpercentage part ?

Code: Select all


print ("1.   true  expected: " .. tostring ( 4 >= 3) )
print ("2.   true  expected: " .. tostring ( 3 >= 3) )
print ("3.   false expected: " .. tostring ( 2 >= 3) )
print ("4.   false expected: " .. tostring ( 0 >= 3) )
print ("5.   false expected: " .. tostring ( -1 >= 3) )
print ("6.   false expected: " .. tostring ( -3 >= 3) )
print ("7.   false expected: " .. tostring ( -4 >= 3) )
print ("8.   false expected: " .. tostring ( -4.5 >= 3) )
print ("9.   true  expected: " .. tostring (  4.5 >= 3) )

give:

2018-01-10 01:00:47.190  dzVents: 1.   true  expected: true
2018-01-10 01:00:47.190  dzVents: 2.   true  expected: true
2018-01-10 01:00:47.190  dzVents: 3.   false expected: false
2018-01-10 01:00:47.191  dzVents: 4.   false expected: false
2018-01-10 01:00:47.191  dzVents: 5.   false expected: false
2018-01-10 01:00:47.192  dzVents: 6.   false expected: false
2018-01-10 01:00:47.192  dzVents: 7.   false expected: false
2018-01-10 01:00:47.192  dzVents: 8.   false expected: false
2018-01-10 01:00:47.192  dzVents: 9.   true  expected: true

I simplified the script that I original copied from https://www.domoticz.com/wiki/Humidity_control because this is all I need to get my bathroom dry after a shower :D

Code: Select all


 --[[ ************************************************************************************
*** Filename         : /opt/domoticz/scripts/dzVents/scripts/Bathroom humidity.lua
*** Initial Date     : 14 january 2017                                                   
*** Initial Designer : xxxxxxxx  
*** Use of this file : dzVents script (LUA) to check if ventilator needs to start in bathroom
*** Active on system : Domoticz   
*****************************************************************************************
***           Modification History List                         
***           -------------------------                     
*** modified by      : xxxxxxxxxx    date: 14/09/2017                                 
*** modified         : Modified for dzvents 2.2 syntax, +debug +location
***
*** modified by      : xxxxxxxxxx    date: 5/11/2017
*** modified         : Introduced repeatAfterSec to avoid missed signals to 4.33 Mhz switch
***
************************************************************************************** ]]-- 
return {
	active = true,
    
    on = { 
        timer = { 'every minute' }
        },
    
    data = {
		HumidityBefore = { initial = 65 }
           },
    

    execute = function(domoticz)
       local debug = false
        
        function debug_print(MyLine)
            if debug then print(MyLine) end
        end
        

        
        local Humidity = domoticz.devices("Badkamer (Zwave)").humidity
        local Vent = domoticz.devices('Centrale afzuiging')
        
        if ( Humidity == 0 or Humidity == nil) then
            print("dzVents: Bathroom Humidity: current is 0 or nil. Skipping this reading")			
        else
            
            if ( Humidity ~= domoticz.data.HumidityBefore ) then
                debug_print ("dzVents: Bathroom Humidity: " .. tostring(Humidity)  .. "  domoticz.data.HumidityBefore: " .. tostring(domoticz.data.HumidityBefore ))    
                local StartNeeded = ( ( Humidity > domoticz.data.HumidityBefore + 3 )  and ( Vent.state == 'Off' ) )  
                
                if StartNeeded then
                    print ("dzVents: Bathroom Humidity:  Fan off ==>> Switching fan on for 20 minutes")
                    Vent.switchOn().repeatAfterSec(10,5) -- Repeat command 5 times (after 10,20,30,40 and 50 seconds)
                    Vent.switchOff().afterMin(20).repeatAfterSec(10,5)					
                end
                domoticz.data.HumidityBefore = Humidity
			end
        end
	end
}



Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

pgas37
Posts: 47
Joined: Wednesday 06 December 2017 20:44
Target OS: -
Domoticz version:
Contact:

Re: how to check positive numbers in dzvents-script

Post by pgas37 » Wednesday 10 January 2018 16:34

I know for sure. I tested it with:
"if (delta_5 >= 3) then
domoticz.devices(vent_schakelaar).switchOn()" and the fan switched on.

I will go into your script, but i still need an answer how to exclude a drop in humidity

regards
Paul

pgas37
Posts: 47
Joined: Wednesday 06 December 2017 20:44
Target OS: -
Domoticz version:
Contact:

Re: how to check positive numbers in dzvents-script

Post by pgas37 » Wednesday 10 January 2018 17:46

I tried your script. Local Humidity en Vent changed.
Fan started....
an error in line 53 (switch-on of the Fan) : 2018-01-10 16:14:00.198 Error: dzVents: Error: ...cz/scripts/dzVents/generated_scripts/VochtVentVtest3.lua:53: attempt to call field 'repeatAfterSec' (a nil value)/

because of that probably the switch-off after 20 minutes did not work either. Suggestions?

I use dzventz 2.2.00 and domoticz 3.8153.

regards
Paul

User avatar
waaren
Posts: 469
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: how to check positive numbers in dzvents-script

Post by waaren » Wednesday 10 January 2018 18:21

@Paul,

I am really puzzled by this. Could you please insert the function

Code: Select all

  
function ValueAndTypeCheck(Var2Check)
    print("---------------")
    print("Var2Check value:  " .. tostring(Var2Check) )
    Var2Check_Type = type(Var2Check)
    print("Var2Check type:   " .. Var2Check_Type )
    if Var2Check_Type ~= "string" then
        print (tostring(Var2Check) .. " >= 3 is " .. tostring((Var2Check >= 3)))
        if Var2Check > 0 then 
            print ("Var2Check is positive")
        elseif Var2Check < 0 then 
            print ("Var2Check is negative")
        else 
            print ("Var2Check is zero")
        end
    else
        print("no further checks possible on Var2Check")
    end    
    print("---------------")
end

somewhere in the beginning of your code and call it with ValueAndTypeCheck(delta_5) just before your existing code "if (delta_5 >= 3) then" ?
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

User avatar
waaren
Posts: 469
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: how to check positive numbers in dzvents-script

Post by waaren » Wednesday 10 January 2018 18:32

@Paul,

my fault: repeatAfterSec is only available starting dzVents version 2.3
you must remove the .repeatAfterSec(10,5) part for dzVents version 2.2
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

pgas37
Posts: 47
Joined: Wednesday 06 December 2017 20:44
Target OS: -
Domoticz version:
Contact:

Re: how to check positive numbers in dzvents-script

Post by pgas37 » Wednesday 10 January 2018 19:02

How can i download v 2.3 in domoticz?

pgas37
Posts: 47
Joined: Wednesday 06 December 2017 20:44
Target OS: -
Domoticz version:
Contact:

Re: how to check positive numbers in dzvents-script

Post by pgas37 » Wednesday 10 January 2018 23:54

Waaren,


I inserted your code in to the top of the script and
just before "if (delta_5) >3 then..." I inserted "ValueAndTypeCheck(delta_5)".


a part of the log-file (drop 2 degrees) :
2018-01-10 22:39:00.285 dzVents: T-5: Digoo_ch1: 82
2018-01-10 22:39:00.285 dzVents: T-10: Digoo_ch1: 84
2018-01-10 22:39:00.286 dzVents: Stijging/daling laatste 10 min: -4
2018-01-10 22:39:00.286 dzVents: Stijging/daling laatste 5 min. -2
2018-01-10 22:39:00.286 dzVents: ---------------
2018-01-10 22:39:00.286 dzVents: Var2Check value: -2
2018-01-10 22:39:00.286 dzVents: Var2Check type: number
2018-01-10 22:39:00.286 dzVents: -2 >= 3 is false
2018-01-10 22:39:00.286 dzVents: Var2Check is negative
2018-01-10 22:39:00.287 dzVents: ---------------

and
(rise 7 degrees)
2018-01-10 22:53:00.222 dzVents: T-5: Digoo_ch1: 84
2018-01-10 22:53:00.222 dzVents: T-10: Digoo_ch1: 77
2018-01-10 22:53:00.223 dzVents: Stijging/daling laatste 10 min: 7
2018-01-10 22:53:00.223 dzVents: Stijging/daling laatste 5 min. 7
2018-01-10 22:53:00.223 dzVents: ---------------
2018-01-10 22:53:00.223 dzVents: Var2Check value: 7
2018-01-10 22:53:00.223 dzVents: Var2Check type: number
2018-01-10 22:53:00.223 dzVents: 7 >= 3 is true
2018-01-10 22:53:00.224 dzVents: Var2Check is positive
2018-01-10 22:53:00.224 dzVents: ---------------

User avatar
waaren
Posts: 469
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: how to check positive numbers in dzvents-script

Post by waaren » Thursday 11 January 2018 1:14

@Paul,
dzVents 2.3 is part of Domoticz Beta. I don't think you can install it separately on top of domoticz 3.8153
I am running out of ideas why your code reacts unexpected to a negative value. I sent you a PM on how to progress this
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave , dzVents 2.4.n, Amazon echo

dannybloe
Posts: 1405
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

Re: how to check positive numbers in dzvents-script

Post by dannybloe » Thursday 11 January 2018 14:52

Indeed, don't move dzVents runtime files around installs as it is tightly coupled to the Domoticz code. Therefore 2.3.0 can only be used with the current beta and not with stable.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests