dzvents after update to version 4.97  [SOLVED]

Moderator: leecollings

Post Reply
pgas37
Posts: 99
Joined: Wednesday 06 December 2017 19:44
Target OS: -
Domoticz version:
Contact:

dzvents after update to version 4.97

Post by pgas37 »

Domoticz ver 4.97 on Raspberrypi

The dzvents-script below (ventilator-switch based on a humidity-sensor) worked fine under domoticz-version 3.87. After an update to version 4,97 this script and some others (also based on humidity) do not work anymore. In domoticz version 4.97 the versionnumber of dzvents is not visible anymore.
Th script has a test-mode, but also the test-mode does not work anymore! :cry:
Probably something small, but i cannot find the solution.

Can anybody help?

Thanks

Paul

Code: Select all

return {
	active = true,
    
    on = { 
        timer = { 'every 30 minutes' }
        },
    
    data = {
		HumidityBefore = { initial = 50 }
           },
    

    execute = function(domoticz)
       local debug = true
        
        function debug_print(MyLine)
            if debug then print(MyLine) end
        end
--------------
   
    
    local   Vent = domoticz.devices('VentSchakelaarSL1-')                         -
            SENSOR_NAME = 'Zolder TH_ch2'
            TEST_MODE_HUMVAR = 'testHumidity' .. SENSOR_NAME
            vochtpercentage = 60
            PRINT_MODE = true
            Temp = domoticz.devices('').temperature
    
        --local Humidity = domoticz.devices('Zolder TH_ch2').humidity
        --print(' hum =================================   :' ..Humidity)
        

    if (tonumber(uservariables[TEST_MODE_HUMVAR]) > 0) then
            current = tonumber(uservariables[TEST_MODE_HUMVAR])
            if PRINT_MODE == true then
            print('Current Humidity Test Mode: ' .. current)
            end
        else
            current = domoticz.devices('Zolder TH_ch2').humidity
            if PRINT_MODE == true then
            print('Current Humidity: ' ..SENSOR_NAME  .. current)
            end
        end  
        
        
       if (current == 0 or current == nil) then
            print("dzVents: Zolder Humidity: current is 0 or nil. Skipping this reading")			
        else
            print('Current Humidity: ' ..current)
            print('hum before: ' ..domoticz.data.HumidityBefore)
            if ( current >= vochtpercentage) then
                debug_print ("dzventz: Zolder Humidity > dan: " ..vochtpercentage)
                debug_print ("dzVents: Humidity:  "  .. tostring(current)  .. "  domoticz.data.HumidityBefore: " .. tostring(domoticz.data.HumidityBefore ))    
                local StartNeeded = ( ( current > vochtpercentage )  and ( Vent.state == 'Off' )  )  
                
                if StartNeeded then
                    print ("dzVents: Zolder Humidity:  Fan off ==>> Switching fan on for 50 minutes")
                    Vent.switchOn() 
                    domoticz.notify('vocht% >= 60(script VV-on_off): ', 'Vent. aan 50min: vocht%: ' .. current .. '  Temperatuur: ' ..Temp, domoticz.PRIORITY_LOW)
                    Vent.switchOff().afterMin(50)
                end
                
                 
                domoticz.data.HumidityBefore = current   --Humidity
			end
        end
	end
}
SweetPants

Re: dzvents after update to version 4.97

Post by SweetPants »

Does setup->about not show the dz_Vents version? It does on my installation.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents after update to version 4.97

Post by waaren »

pgas37 wrote: Wednesday 22 August 2018 15:27 Domoticz ver 4.97 on Raspberrypi

The dzvents-script below (ventilator-switch based on a humidity-sensor) worked fine under domoticz-version 3.87. After an update to version 4,97 this script and some others (also based on humidity) do not work anymore. In domoticz version 4.97 the versionnumber of dzvents is not visible anymore.
Th script has a test-mode, but also the test-mode does not work anymore! :cry:
Are you sure this script worked in other versions ?
Do you see anything in the log ?

The two lines below will give errors

Code: Select all

   local   Vent = domoticz.devices('VentSchakelaarSL1-')                         -   ??? This single - will cause  unexpected symbol error
    Temp = domoticz.devices('').temperature                               ???? This empty string will cause a problem with the device-adapter
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pgas37
Posts: 99
Joined: Wednesday 06 December 2017 19:44
Target OS: -
Domoticz version:
Contact:

Re: dzvents after update to version 4.97

Post by pgas37 »

I found the versionnumber: dzvents 2.4.6 and
Indeed between the ' ' a sensor was mentioned so no errors occured (Temp = domoticz.devices('Zolder TH_ch2').temperature)
The single - in Local, Vent = domoticz.devices('VentSchakelaarSL1-') did not give any problem and
I am sure the script worked!

Could it be a cache problem? How to flush cache(s) in Domoticz?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents after update to version 4.97

Post by waaren »

pgas37 wrote: Thursday 23 August 2018 14:34 I found the versionnumber: dzvents 2.4.6 and
Indeed between the ' ' a sensor was mentioned so no errors occured (Temp = domoticz.devices('Zolder TH_ch2').temperature)
The single - in Local, Vent = domoticz.devices('VentSchakelaarSL1-') did not give any problem and
I am sure the script worked!

Could it be a cache problem? How to flush cache(s) in Domoticz?
I was not referring to the - between the quotes but to a single - probably left behind after removing a comment on the same line. Lua will not accept such a single - in the middle of your script and therefore dzVents cannot continue with the execution of this script.
Cache can only be a problem in the gui not with execution of any script.
What is in the log ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pgas37
Posts: 99
Joined: Wednesday 06 December 2017 19:44
Target OS: -
Domoticz version:
Contact:

Re: dzvents after update to version 4.97

Post by pgas37 »

I found out that the script works again if I remove the 'test'-part of the script:

=== removed

if (tonumber(uservariables[TEST_MODE_HUMVAR]) > 0) then
current = tonumber(uservariables[TEST_MODE_HUMVAR])
if PRINT_MODE == true then
print('Current Humidity Test Mode: ' .. current)
end
else
current = domoticz.devices('Zolder TH_ch2').humidity
if PRINT_MODE == true then
print('Current Humidity: ' ..SENSOR_NAME .. current)
end
end
=======
For some reason the user-variable "TEST_MODE_HUMVAR' (type variable = integer) causes the trouble.
A nil value error.
Any suggestion?

Thanks
Paul


Log-file
2018-08-23 15:29:00.540 Status: dzVents: Info: ========================================= Vocht meting Zolder test
2018-08-23 15:29:00.561 Status: dzVents: Info: === Vocht meting Zolder test Sensor: Zolder TH_ch2
2018-08-23 15:29:00.561 Status: dzVents: Info: === Vocht meting Zolder test TEMPHUMVAR: testHumidity Zolder TH_ch2
2018-08-23 15:29:00.561 Status: dzVents: Info: === Vocht meting Zolder test Vocht% ingesteld : 60
2018-08-23 15:29:00.561 Status: dzVents: Info: === Vocht meting Zolder test. TEMP-actueel : 25.39999961853
2018-08-23 15:29:00.561 Status: dzVents: Info: === Vocht meting Zolder test. Vocht_actueel : 62
2018-08-23 15:29:00.562 Status: dzVents: Error (2.4.6): An error occured when calling event handler VochtVentdV-on_off test
2018-08-23 15:29:00.562 Status: dzVents: Error (2.4.6): ...ts/dzVents/generated_scripts/VochtVentdV-on_off test.lua:44: attempt to index global 'uservariables' (a nil value)
2018-08-23 15:29:00.562 Status: dzVents: Info: ------ Finished VochtVentdV-on_off test
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents after update to version 4.97

Post by waaren »

pgas37 wrote: Thursday 23 August 2018 15:39 I found out that the script works again if I remove the 'test'-part of the script:

=== removed

if (tonumber(uservariables[TEST_MODE_HUMVAR]) > 0) then
current = tonumber(uservariables[TEST_MODE_HUMVAR])

=======
For some reason the user-variable "TEST_MODE_HUMVAR' (type variable = integer) causes the trouble.
Change uservariables to domoticz.uservariables
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pgas37
Posts: 99
Joined: Wednesday 06 December 2017 19:44
Target OS: -
Domoticz version:
Contact:

Re: dzvents after update to version 4.97

Post by pgas37 »

I changed the uservariable.
The error (nil-value) is solved, but as long as the test-mode part is within the script, the script stops further execution. So all log-message before the test-mode part are visible, after the test-mode part the script seems dead.
Remove the test-mode part and the scripts works fine.

So what is de diffrence for this part of the script under this dzvents(2.4.6) in comparision with the version before the update?

thanks for your help.
regards
Paul



uservar.jpeg
uservar.jpeg (44.84 KiB) Viewed 6165 times

Code: Select all

eturn {
	active = true,
    
    on = { 
        timer = {'every minute'}                                           --'every 30 minutes' }
        },
    
    data = {
		HumidityBefore = { initial = 51 }
           },
    

    execute = function(domoticz)
       local debug = true
        
        function debug_print(MyLine)
            if debug then print(MyLine) end
        end
--------------
    domoticz.log(' ========================================= Vocht meting Zolder test')
    
    local   Vent = domoticz.devices('VentSchakelaarSL1-')                             --('Schakelaar zolder (elro Ch D1)')                        --('ChntpB2')                   --
            SENSOR_NAME = 'Zolder TH_ch2'
            TEST_MODE_HUMVAR = 'testHumidity ' .. SENSOR_NAME
            vochtpercentage = 60
            PRINT_MODE = true
            Temp = domoticz.devices('Zolder TH_ch2').temperature
            current = domoticz.devices('Zolder TH_ch2').humidity
           
        --local Humidity = domoticz.devices('Digoo_ch1').humidity
        --print(' hum   :' ..Humidity)
        
        if PRINT_MODE == true then
            print('locals===============================================')
        domoticz.log('=== Vocht meting Zolder test  Sensor: ' ..SENSOR_NAME)
        domoticz.log('=== Vocht meting Zolder test TEMPHUMVAR: ' ..TEST_MODE_HUMVAR)
        domoticz.log('=== Vocht meting Zolder test  Vocht% ingesteld : ' ..vochtpercentage)
        domoticz.log('=== Vocht meting Zolder test. TEMP-actueel :  ' ..Temp)
        domoticz.log('=== Vocht meting Zolder test. Vocht_actueel :  ' ..current)
       end
--==========================test mode===========================
    if (tonumber(domoticz.uservariables[TEST_MODE_HUMVAR]) > 0) then
         current = tonumber(domoticz.uservariables[TEST_MODE_HUMVAR])
        if PRINT_MODE == true then
        print('Current Humidity Test Mode: ' .. current)
        end
      else
        current = domoticz.devices('Zolder TH_ch2').humidity                                                
      if PRINT_MODE == true then
         print('Current Humidity: ' ..SENSOR_NAME  .. current)
        end
    end 
 --========================einde test mode ============================       
        
        current = domoticz.devices('Zolder TH_ch2').humidity    
        print('Current Humidity ==== 1 : ' ..SENSOR_NAME  .. current)
       
               if (current == 0 or current == nil) then
            print("dzVents: Zolder Humidity: current is 0 or nil. Skipping this reading")			
        else
            print('=====Current Humidity ====2 : ' ..current)
            print('=====hum before: ' ..domoticz.data.HumidityBefore)
            if ( current >= vochtpercentage) then
                debug_print ("dzventz: Zolder Humidity > dan: " ..vochtpercentage)
                debug_print ("dzVents: Humidity:  "  .. tostring(current)  .. "  domoticz.data.HumidityBefore: " .. tostring(domoticz.data.HumidityBefore ))    
                local StartNeeded = ( ( current > vochtpercentage )  and ( Vent.state == 'Off' )  )  
                
                if StartNeeded then
                    print ("dzVents: Zolder Humidity:  Fan off ==>> Switching fan on for 50 minutes")
                    Vent.switchOn() 
                    domoticz.notify('vocht% >= 60(script VV-on_off): ', 'Vent. aan 50min: vocht%: ' .. current .. '  Temperatuur: ' ..Temp, domoticz.PRIORITY_LOW)
                    Vent.switchOff().afterMin(50) 
                end
                
                 
                domoticz.data.HumidityBefore = current   --Humidity
                print('=== HumidityBefore -einde script- : ' ..current)
			end
        end
	end
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents after update to version 4.97

Post by waaren »

pgas37 wrote: Thursday 23 August 2018 19:33 I changed the uservariable.
So what is de diffrence for this part of the script under this dzvents(2.4.6) in comparision with the version before the update?

Don't know of any relevant differences but if you look at logfile you will see where the script fail.
the dzVents syntax to get the value of a domoticz uservar is domoticz.variables("name of uservar").value

maybe my simplified ventilator activation script can help you.

Code: Select all

 -- Bathroom humidity.lua
 
return {
    on = { timer = { 'every minute' }},
    
    data = { humidityBefore = { history = true, maxItems = 10 }},

--    logging =   {   level   =   domoticz.LOG_DEBUG,
--                    marker  =   "Bathroom humidity" },    

    execute = function(dz)
        local humidity          = dz.devices("Badkamer (Zwave)").humidity
        local vent              = dz.devices('Centrale afzuiging')
        if dz.data.humidityBefore.getOldest() == nil then
          dz.data.humidityBefore.add(99)
        end  
        local humidityBefore    = dz.data.humidityBefore.getOldest().data 		-- value from 10 minutes ago
        
        if humidity == nil or humidity == 0 then
            dz.log("current is 0 or nil. Skipping this reading",dz.LOG_ERROR)            
            return
        end
        
        dz.log(humidity  .. "  HumidityBefore: " .. humidityBefore,dz.LOG_DEBUG)    
                
        if  humidity ~= humidityBefore  then
            if humidity > 65 and humidity > ( humidityBefore + 3)  and vent.state == 'Off' then
                dz.log("Fan off ==>> Switching fan on for 20 minutes",dz.LOG_FORCE)
                vent.switchOn().repeatAfterSec(10,2) -- Repeat command 2 times (after 10 and 20 seconds)
                vent.switchOff().afterMin(20).repeatAfterSec(10,2)                    
            end
        end
        dz.data.humidityBefore.add(humidity)
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pgas37
Posts: 99
Joined: Wednesday 06 December 2017 19:44
Target OS: -
Domoticz version:
Contact:

Re: dzvents after update to version 4.97

Post by pgas37 »

Oke,

I will try your script, but it does not solve the “test-part” problem in the script with the user-variable that didn’t exits before!
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzvents after update to version 4.97

Post by dannybloe »

Accessing a user variable in dzVents is done like this:

Code: Select all

domoticz.variables('myUserVar').value
No need to convert it so number if the variable is defined as such in the GUI.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
pgas37
Posts: 99
Joined: Wednesday 06 December 2017 19:44
Target OS: -
Domoticz version:
Contact:

Re: dzvents after update to version 4.97

Post by pgas37 »

I understand “ no need to convert it”( the tonumber(xx)) , but i do not understand te rest of your sentence.....
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: dzvents after update to version 4.97  [SOLVED]

Post by dannybloe »

The type of the variable is defined in domoticz when you created the uservariable. So if it is a number or integer type it will be the same in dzVents.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
pgas37
Posts: 99
Joined: Wednesday 06 December 2017 19:44
Target OS: -
Domoticz version:
Contact:

Re: dzvents after update to version 4.97

Post by pgas37 »

Thx
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest