help with dzventsscript

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

Moderator: leecollings

Post Reply
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

help with dzventsscript

Post by pvklink »

Hi, i tried to read temperaturesensor based on weatherunderground. Got it almost working.
I get an error on variable prevwaarde, it seems to have no value?
- I added a initial value of 100 in the data section and
- i checked if this global variable is empty and set it to 100
Both dont seemed to work...

Code: Select all

2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor device = Zuiderparklaan
2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor id to update = 826
2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor grenswaarde = 2
2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor huidige waarde= 2.4000000953674
2018-11-21 09:37:15.671 Status: dzVents: Error (2.4.8): An error occured when calling event handler test2
2018-11-21 09:37:15.671 Status: dzVents: Error (2.4.8): .../pi/domoticz/scripts/dzVents/generated_scripts/test2.lua:33: attempt to index global 'domoticz' (a nil value)

Code: Select all

-- soon more sensor temp device will be added to this script
local TMP_DEVICES = {
    ['Zuiderparklaan'] = 'Zuiderparklaan',                      -- Adjust to your needs. Between every line you need to add a ",".
}

local USAGE_tmpnorm = {
    ['Zuiderparklaan'] = 2,                                     -- Adjust to your needs. Between every line you need to add a ",".
}

return {
    on = { devices = TMP_DEVICES },
    
    logging = { level   = domoticz.LOG_DEBUG ,                  -- Uncomment to override the dzVents global logging setting
                marker  = actOnIdleDevices 
              },
    data = {
          prevhistwaarde = { history = true, maxItems = 10, initial=100 }
            },
        
    execute = function(dz, device)
 
    local name          = device.name
    local norm          = USAGE_tmpnorm[TMP_DEVICES[name]]
    local huidwaarde    = device.temperature    

    --function round2(num, numDecimalPlaces)
        --return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
    -- end

    if dz.data.prevhistwaarde[name] == nil then 
        dz.log("00 Sensor info         = Geen vorige waarde opgehaald")
        local prevwaarde    = 100
    else
        local prevwaarde    = dz.data.prevhistwaarde[name]
    end

    dz.log("00 Sensor device        = " .. name)
    dz.log("00 Sensor grenswaarde   = " .. norm)
    dz.log("00 Sensor huidige waarde= " .. tostring(huidwaarde))
    dz.log("00 Sensor vorige waarde = " .. tostring(prevwaarde))    
    dz.log("---------------------------------------")

    if huidwaarde == nil then
        dz.log("01 Sensor info         = Geen waarde opgehaald")
    else
        if (huidwaarde - prevwaarde == 0 ) then
            dz.log("02 Sensor info         = Oude en nieuwe sensorwaarden zijn gelijk")
        else    
            dz.log("03 Sensor info         = Nieuwe sensorwaarde...")
        	domoticz.devices('temperatuur').updateTemperature(huidwaarde)
            domoticz.data.prevhistwaarde.add(huidwaarde)
        end
    end
end
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: help with dzventsscript

Post by waaren »

pvklink wrote: Wednesday 21 November 2018 17:09 Hi, i tried to read temperaturesensor based on weatherunderground. Got it almost working.
I get an error on variable prevwaarde, it seems to have no value?
- I added a initial value of 100 in the data section and
- i checked if this global variable is empty and set it to 100

Code: Select all

2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor device = Zuiderparklaan
2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor id to update = 826
2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor grenswaarde = 2
2018-11-21 09:37:15.671 Status: dzVents: Info: 00 Sensor huidige waarde= 2.4000000953674
2018-11-21 09:37:15.671 Status: dzVents: Error (2.4.8): An error occured when calling event handler test2
2018-11-21 09:37:15.671 Status: dzVents: Error (2.4.8): .../pi/domoticz/scripts/dzVents/generated_scripts/test2.lua:33: attempt to index global 'domoticz' (a nil value)
 

Code: Select all

33        local prevwaarde    = dz.data.prevhistwaarde[name]
 
prevhistwaarde is not defined as a global variable but as a historical persistent variable
Line 33 is not according to the syntaxis for historical persistent data
Can you try with

Code: Select all

        local prevwaarde    = dz.data.prevhistwaarde.getLatest() or 0
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: help with dzventsscript

Post by pvklink »

Ok, Script performs better.
Get the following error

Code: Select all

4:33.083 Status: dzVents: Info: ------ Start internal script: DZ_testmettemperatuur: Device: "Zuiderparklaan (weather underground rijswijk)", Index: 680
2018-11-21 20:54:33.084 Status: dzVents: Info: 00 Sensor device = Zuiderparklaan
2018-11-21 20:54:33.084 Status: dzVents: Info: 00 Sensor grenswaarde = 2
2018-11-21 20:54:33.084 Status: dzVents: Info: 00 Sensor huidige waarde= 4.2
2018-11-21 20:54:33.085 Status: dzVents: Info: 00 Sensor vorige waarde = table: 0x6378df70
2018-11-21 20:54:33.085 Status: dzVents: Info: ---------------------------------------
2018-11-21 20:54:33.085 Status: dzVents: Error (2.4.8): An error occured when calling event handler DZ_testmettemperatuur
2018-11-21 20:54:33.085 Status: dzVents: Error (2.4.8): ...ipts/dzVents/generated_scripts/DZ_testmettemperatuur.lua:54: attempt to perform arithmetic on local 'prevwaarde' (a table value)
2018-11-21 20:54:33.085 Status: dzVents: Info: ------ Finished DZ_testmettemperatuur

I made some adjustsments, this is the current script. feel free to change, i am not a programmer, trying hard to get it to work :oops:
1) dz.log("00 Sensor vorige waarde = " .. tostring(prevwaarde)) --> gives a strange format
2) prevhistwaarde = { history = true, maxItems = 10, initial = 100 } -->default no 100 in the historic_data,
3) how to reset the historic data when starting the script the first time
4) how can i check the values in the historic data so i can log historic temp values
5) if prevwaarde == nil then
dz.log("00 Sensor info = Geen vorige waarde opgehaald")
local prevwaarde = 100
end does not seems to work

Code: Select all

-- wordt de vervanger van dz_buitentemperatuur
-- https://github.com/dannybloe/dzVents#historical-variables-api
-- script uses a temp sensor Zuiderparklaan which uses Weather Underground with pws:ITHEHAGU40

local TMP_DEVICES = {
    ['Zuiderparklaan'] = 'Zuiderparklaan',                      -- Adjust to your needs. Between every line you need to add a ",".
}

local USAGE_tmpnorm = {
    ['Zuiderparklaan'] = 2,                                     -- Adjust to your needs. Between every line you need to add a ",".
}

return {
    on = { devices = TMP_DEVICES },
    
    logging = { level   = domoticz.LOG_DEBUG ,                  -- Uncomment to override the dzVents global logging setting
                marker  = actOnIdleDevices 
              },
    data = {
          prevhistwaarde = { history = true, maxItems = 10, initial = 100 }
            },
        
    execute = function(dz, device)
 
    function round2(num, numDecimalPlaces)
        return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
    end

    local name          = device.name
    local norm          = USAGE_tmpnorm[TMP_DEVICES[name]]
    local huidwaarde    = round2(device.temperature,1)
--    local prevwaarde    = dz.data.prevhistwaarde.getLatest()    round function does not work on table data, this variable is useless.. how to convert to a number round2 function does not work here
    local prevwaarde    = dz.data.prevhistwaarde.getLatest()
    
    if prevwaarde == nil then 
        dz.log("00 Sensor info         = Geen vorige waarde opgehaald")
        local prevwaarde    = 100
    end

    dz.log("00 Sensor device        = " .. name)
    dz.log("00 Sensor grenswaarde   = " .. norm)
    dz.log("00 Sensor huidige waarde= " .. tostring(huidwaarde))
    dz.log("00 Sensor vorige waarde = " .. tostring(prevwaarde))    
    --dz.log("00 History data         = " .. tostring(dz.data.prevhistwaarde))
    dz.log("---------------------------------------")

    if huidwaarde == nil then
        dz.log("01 Sensor info         = Geen waarde opgehaald")
    else    
        if prevwaarde == nil then 
            dz.log("02 Sensor info         = Nieuwe sensorwaarde...")
            dz.devices('Temperatuur').updateTemperature(huidwaarde)
            dz.data.prevhistwaarde.add(huidwaarde)
        else
            if (huidwaarde - prevwaarde == 0 ) then
                dz.log("03 Sensor info         = Oude en nieuwe sensorwaarden zijn gelijk")
            elseif (huidwaarde - prevwaarde > 0 ) then
                dz.log("04 Sensor info         = Temperatuur stijgt")
	            dz.devices('Temperatuur').updateTemperature(huidwaarde)
                dz.data.prevhistwaarde.add(huidwaarde)
            else
                dz.log("05 Sensor info         = Temperatuur daalt")
	            dz.devices('Temperatuur').updateTemperature(huidwaarde)
                dz.data.prevhistwaarde.add(huidwaarde)
            end
        end
    end
end
}
datafile

Code: Select all

-- Persistent Data
local multiRefObjects = {

} -- multiRefObjects
local obj1 = {
	["prevhistwaarde"] = {
		[1] = {
			["data"] = 4.9000000953674;
			["time"] = "2018-11-21 17:54:26.851";
		};
	};
}
return obj1
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: help with dzventsscript

Post by waaren »

pvklink wrote: Wednesday 21 November 2018 18:28 I made some adjustsments, this is the current script. feel free to change
1) dz.log("00 Sensor vorige waarde = " .. tostring(prevwaarde)) --> gives a strange format
2) prevhistwaarde = { history = true, maxItems = 10, initial = 100 } -->default no 100 in the historic_data,
3) how to reset the historic data when starting the script the first time
4) how can i check the values in the historic data so i can log historic temp values
5) if prevwaarde == nil then
dz.log("00 Sensor info = Geen vorige waarde opgehaald")
local prevwaarde = 100
end does not seems to work
Something like this ?

Code: Select all

--[[ wordt de vervanger van dz_buitentemperatuur
      https://github.com/dannybloe/dzVents#historical-variables-api <<<<< This is quite old ; better use 

      https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting#Accessing_values_in_historical_variables

      script uses a temp sensor Zuiderparklaan which uses Weather Underground with pws:ITHEHAGU40
]] -- 
local TMP_DEVICES =     {
                            ['Zuiderparklaan'] = 'Zuiderparklaan',  -- Adjust to your needs. Between every line you need to add a ",".
                        }

local USAGE_tmpnorm =   {
                            ['Zuiderparklaan'] = 2,                 -- Adjust to your needs. Between every line you need to add a ",".
                        }

return {
    on      =   {   devices = TMP_DEVICES },
                
    logging =   { 
                    level   = domoticz.LOG_DEBUG ,                  -- Uncomment to override the dzVents global logging setting
                    marker  = "Temperatuur trend" 
                },
              
    data    =   {
                    prevhistwaarde = { history = true, maxItems = 10 }
                },
        
    execute = function(dz, device)
    
        if dz.data.prevhistwaarde.getOldest() == nil then  -- Check if history is already filled (initial does not work with history persistent data
          dz.data.prevhistwaarde.add(100)
        end
 
        local name          = device.name
        local norm          = USAGE_tmpnorm[TMP_DEVICES[name]]
        local huidwaarde    = dz.utils.round(device.temperature,1)
        local prevwaarde    = dz.utils.round(dz.data.prevhistwaarde.getLatest().data,1)   
        
        
        dz.log("00 Sensor device        = " .. name)
        dz.log("00 Sensor grenswaarde   = " .. norm)
        dz.log("00 Sensor huidige waarde= " .. huidwaarde)
        dz.log("00 Sensor vorige waarde = " .. prevwaarde)    
        dz.log(dz.data.prevhistwaarde.size )    
        
        for i = dz.data.prevhistwaarde.size,1,-1 do 
            item = dz.data.prevhistwaarde.get(i)
            dz.log("00 History data van " .. item.time.rawDate .. " " .. item.time.rawTime .. 
                                    " = " .. item.data .. " graden")
        end
        dz.log("---------------------------------------")

        if huidwaarde == nil then
            dz.log("01 Sensor info         = Geen waarde opgehaald")
        else    
            if huidwaarde == prevwaarde then
                dz.log("03 Sensor info         = Oude en nieuwe sensorwaarden zijn gelijk")
                return
            end    
            if huidwaarde > prevwaarde then
                dz.log("04 Sensor info         = Temperatuur stijgt")
            elseif huidwaarde < prevwaarde then 
                dz.log("05 Sensor info         = Temperatuur daalt")
            end
            dz.devices('Temperatuur2').updateTemperature(huidwaarde)
            dz.data.prevhistwaarde.add(huidwaarde)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: help with dzventsscript

Post by pvklink »

you are amazing!
I (you, sorry) made this script for my 85 years old father in law how lives on a houseboat. In the winter his watersuply freezes. So we bought an electric wire to warm it. We connect the wire to a smart switch/sensor. A made two lua scripts for him, one to check the temp, one to activate the switch with some rules so that the switch does not goes on or off to much. I want to get rid of LUA....because dzvents is much smarter i think...
If temp is below 4 switch must go on for x hours, but if the temp is above 4 it must go off if the timeperiod x hours is over...

[logging]
19:35:50.776 (weather underground rijswijk) General/Visibility (Zuiderparklaan-Zicht)
2018-11-22 19:35:50.779 (weather underground rijswijk) General/Solar Radiation (Zuiderparklaan6)
2018-11-22 19:35:50.845 Status: dzVents: Info: Temperatuur trend: ------ Start internal script: DZ_testmettemperatuur: Device: "Zuiderparklaan (weather underground rijswijk)", Index: 680
2018-11-22 19:35:50.846 Status: dzVents: Info: Temperatuur trend: 00 Sensor device = Zuiderparklaan
2018-11-22 19:35:50.846 Status: dzVents: Info: Temperatuur trend: 00 Sensor grenswaarde = 4
2018-11-22 19:35:50.846 Status: dzVents: Info: Temperatuur trend: 00 Sensor huidige waarde= 4.6
2018-11-22 19:35:50.846 Status: dzVents: Info: Temperatuur trend: 00 Sensor vorige waarde = 4.9
2018-11-22 19:35:50.846 Status: dzVents: Info: Temperatuur trend: 1
2018-11-22 19:35:50.846 Status: dzVents: Info: Temperatuur trend: 00 History data van 2018-11-21 18:54:26 = 4.9000000953674 graden
2018-11-22 19:35:50.846 Status: dzVents: Info: Temperatuur trend: ---------------------------------------
2018-11-22 19:35:50.846 Status: dzVents: Info: Temperatuur trend: 05 Sensor info = Temperatuur daalt
2018-11-22 19:35:50.848 Status: dzVents: Debug: Temperatuur trend: Processing device-adapter for Temperatuur: Temperature device adapter
2018-11-22 19:35:50.850 Status: dzVents: Info: Temperatuur trend: ------ Finished DZ_testmettemperatuur

[old lua script_1] the new temperature dzvents script will replace this one/

Code: Select all

--Script To Parse WeatherUnderground Multi-Value Sensor, Additionally using PWS: system from WU with a new output format
--This script assumes the output (which can be viewed in events show current state button) is like this 19.5;79;3;1019;3 (temp;humidity;null;pressure;null)
--more details at this wiki http://www.domoticz.com/wiki/Virtual_weather_devices
--
--The following need updated for your environment get the 'Idx' or 'Name' off the Device tab. By default only the Temp is 'uncommented or enabled' in this script.
--
local sensorwu = 'Barometer' --name of the sensor that gets created when you add the WU device (and that contains multiple values like temperature, humidity, barometer etc)
local idxt = 394 --idx of the virtual temperature sensor you need to change this to your own Device IDx
--local idxh = 999 --idx of the virtual humidity sensor you need to change this to your own Device IDx
--local idxp = 999 --idx of the virtual pressure sensor you need to change this to your own Device IDx
--

commandArray = {}

if devicechanged[sensorwu] then
        sWeatherTemp, sWeatherHumidity, sWeatherPressure = otherdevices_svalues[sensorwu]:match("([^;]+);([^;]+);([^;]+);([^;]+)")
        sWeatherTemp = tonumber(sWeatherTemp)

        commandArray[1] = {['UpdateDevice'] = idxt .. '|0|' .. sWeatherTemp}

    if sWeatherTemp > 3 then
        print ('Temperatuur groter dan 3, warmtelint uit')
        commandArray['warmtelint']='Off' 
    else
        print ('Temperatuur <= dan 3, warmtelint aan')
        commandArray['warmtelint']='On' 
    end
    print("waarde sensor: "..tostring(sWeatherTemp)..'xx')
end

return commandArray
[old lua script_2] For this script i made a new dzvents script

Code: Select all

local switchlint = 'warmtelint'             -- schakelaar die bij onderschreiding temperatuur aangezet wordt
local switchverbruik = 'Verbruikwarmtelint'             -- schakelaar die bij onderschreiding temperatuur aangezet wordt
local curwatlimit = 1                       -- minimale onderwaarde temperatuur
local wacht=2000

function round2(num, numDecimalPlaces)
  return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
end

commandArray = {}

    curwat = otherdevices_svalues["Verbruikwarmtelint"]
    print ('07a Stroomlintverbruik heeft waarde' .. tonumber(curwat) .. '/')
    curwat=0
if devicechanged[switchlint] == 'On' then

    i = 1
    while i  <= wacht do
        ping_success=os.execute('ping -c1 -w 1 192.168.20.1')
        print ('teller:'..tostring(i)..'') 
	    i = i + 1
    end
    
    curwat = otherdevices_svalues["Verbruikwarmtelint"]
  
    if tonumber(curwat) > tonumber(curwatlimit) then            -- lint gebruikt stroom, dus werkt
        print ('07 Stroomlint werkt. Verbruikt ' .. curwat)
    else
        print ('07 Stroomlint werkt niet. Verbruikt ' .. curwat)
    end
end

return commandArray
I made a new dzventz script for the switch as well...

Code: Select all

return {
    	active = true,
    on = {
        timer = {'every 60 minutes'}                                             -- dit mag wel een uur worden
        },

execute = function(domoticz)
    local scriptnaam = 'Verbruikwarmtelint'                                     -- naam script voor de foutmelding
    local switchlint = 'fibaro'                                             -- schakelaar die bij onderschreiding temperatuur aangezet wordt
    local switchverbruik = 'Verbruikfibaro'                                 -- sensor die verbruik van de schakelaar meet
    local curwatlimit = 1                                                       -- minimale onderwaarde wattage van het warmtelint (onder deze waarde is hij defect)
    local curwat = tonumber(domoticz.devices(switchverbruik).WhActual)          -- wattage van het apparaat dat aan de switch is gekoppeld, het feitelijke warmtelint

    if domoticz.devices(switchlint).state == 'On' then
        if tonumber(curwat) > tonumber(curwatlimit) then                        -- lint gebruikt stroom, meer dan de normwaarde, dus werkt
            domoticz.log('PRG: ' ..scriptnaam ..': stroomlint werkt, verbruikt: ' .. curwat .. ' Watt')    
        else                                                                    -- lint onder de normale verbruikswaarde (nog n PUSHNOTIFICATIE maken
            domoticz.log('PRG: ' ..scriptnaam ..': stroomlint werkt niet, of thermo staat aan! meet geen stroom!' .. curwat .. ' Watt')
        end
    end
end
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: help with dzventsscript

Post by waaren »

pvklink wrote: Thursday 22 November 2018 19:20 I made this script for my 85 years old father in law how lives on a houseboat. In the winter his watersuply freezes. So we bought an electric wire to warm it. We connect the wire to a smart switch/sensor. A made two lua scripts for him, one to check the temp, one to activate the switch with some rules so that the switch does not goes on or off to much. I want to get rid of LUA....because dzvents is much smarter i think...
If temp is below 4 switch must go on for x hours, but if the temp is above 4 it must go off if the timeperiod x hours is over...
That sounds like a very good reason to use domoticz. Glad I could point you in the direction of a working script. Feel free to ask for clarification or help when needed !
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: help with dzventsscript

Post by pvklink »

And this is the result.
I used a dummyswitch sonoff1 to simulate a switch with a thermostatic heating device
the USAGE_durtimer isnt used. I use an average temperature:
local gemwaarden = dz.utils.round(dz.data.prevhistwaarde.avgSince('00:15:00'),1)

Code: Select all

-[[ wordt de vervanger van dz_buitentemperatuur aanzetten van lint en een timer om aan uit te voorkomen..
      https://github.com/dannybloe/dzVents#historical-variables-api <<<<< This is quite old ; better use 
      https://www.domoticz.com/wiki/DzVents:_next_generation_LUA_scripting#Accessing_values_in_historical_variables
      script uses a temp sensor Zuiderparklaan which uses Weather Underground with pws:ITHEHAGU40
]] -- 
local USAGE_SENSORS =     {
    ['Zuiderparklaan-Diversen'] = 'Zuiderparklaan-Diversen',  -- Adjust to your needs. Between every line you need to add a ",".
                        }

local USAGE_SWITCHES = {
    ['Zuiderparklaan-Diversen'] = 'Sonoff1',                     -- Name of device that switch kw_1 On/ Off 
                        } 

local USAGE_norm =   {
    ['Zuiderparklaan-Diversen'] = 4,                 -- Adjust to your needs. Between every line you need to add a ",".
                        }

local USAGE_DurTimer = {
    ['Zuiderparklaan-Diversen'] = 20,                   -- 
                        }

local USAGE_SwitchOnOff = {
    ['Zuiderparklaan-Diversen'] = 'Yes',                -- Adjust to your needs. Between every line you need to add a ",".
                        }

local USAGE_Notify = {
    ['Zuiderparklaan-Diversen'] = 'Yes',
                    }

local USAGE_Pushoverreceivers = {
    ['Zuiderparklaan-Diversen'] = 'xxx',
                                }

local USAGE_Pushoversound = {
    ['Zuiderparklaan-Diversen'] = 'bike',
                            }

return {
    on      =   {   devices = USAGE_SENSORS },
                
    logging =   { 
                    level   = domoticz.LOG_DEBUG ,                  -- Uncomment to override the dzVents global logging setting
                    marker  = "Temperatuur trend" 
                },
              
    data    =   {
                    prevhistwaarde = { history = true,  maxHours = 1 },
                    sendnotification = {initial = {}}, 
                },
        
    execute = function(dz, device)
        
        if dz.data.prevhistwaarde.getOldest() == nil then  -- Check if history is already filled (initial does not work with history persistent data
          dz.data.prevhistwaarde.add(100)
        end

        local name          = device.name
        local name2         = USAGE_SWITCHES[name]
        local switch        = dz.devices(USAGE_SWITCHES[name])
 
        local onoff         = USAGE_SwitchOnOff[USAGE_SENSORS[name]]
        local notify        = USAGE_Notify[USAGE_SENSORS[name]]
        local receivers     = USAGE_Pushoverreceivers[USAGE_SENSORS[name]]
        local sound         = USAGE_Pushoversound[USAGE_SENSORS[name]]

        local norm          = USAGE_norm[USAGE_SENSORS[name]]
        local DurTimer      = USAGE_DurTimer[USAGE_SENSORS[name]]
        local huidwaarde    = dz.utils.round(device.temperature,1)
        local prevwaarde    = dz.utils.round(dz.data.prevhistwaarde.getLatest().data,1)   
        local gemwaarden    = dz.utils.round(dz.data.prevhistwaarde.avgSince('00:15:00'),1)
        local avgwaarde     = dz.utils.round(dz.data.prevhistwaarde.avg(),1)
        local minwaarde     = dz.utils.round(dz.data.prevhistwaarde.min(),1)
        local maxwaarde     = dz.utils.round(dz.data.prevhistwaarde.max(),1)

        if dz.data.sendnotification[name] == nil then 
            dz.data.sendnotification[name] = false       -- eerste waarde teller op false gezet  -- geen notify gedaan
        end

        if huidwaarde == nil then
            dz.log("01 Sensor info         = Geen waarde opgehaald")
        end

        for i = dz.data.prevhistwaarde.size,1,-1 do 
            item = dz.data.prevhistwaarde.get(i)
            dz.log("00 History data van " .. item.time.rawDate .. " " .. item.time.rawTime .. 
                                    " = " .. item.data .. " graden")
        end
        dz.log("---------------------------------------")
        dz.log("00 Sensor device        = " .. name)
        dz.log("00 Sensor switch device = " .. name2)
        dz.log("00 Sensor onoff         = " .. onoff)
        dz.log("00 Sensor notify        = " .. notify)
        dz.log("00 Sensor receivers     = " .. receivers)
        dz.log("00 Sensor sound         = " .. sound)
        dz.log("-------------------------------------------------")
        dz.log("00 Sensor grenswaarde   = " .. norm)
        dz.log("00 Sensor notif. norm   = " .. DurTimer)
        dz.log("-------------------------------------------------")
        dz.log("00 Sensor huidige waarde= " .. huidwaarde)
        dz.log("00 Sensor vorige waarde = " .. prevwaarde)    
        dz.log("00 Sensor gemid. 5min   = " .. gemwaarden)
        dz.log("00 Sensor gemid. hist   = " .. avgwaarde)
        dz.log("00 Sensor minimum waarde= " .. minwaarde)
        dz.log("00 Sensor maximum waarde= " .. maxwaarde)
        dz.log("00 Status notificatie   = " .. tostring(dz.data.sendnotification[name]))
        dz.log("-------------------------------------------------")

    if  gemwaarden > norm then 
        dz.log("01 Sensor info         = Huidig gemiddelde temperatuur (".. gemwaarden ..") is boven de norm(".. norm .. "), device: " .. name ..  "")

        if switch.state == 'On' and onoff == 'Yes' then
                    switch.switchOff().checkFirst().silent() 
        end
        dz.data.sendnotification[name] = false

    else  
        dz.log("02 Sensor info         = Huidig gemiddelde temperatuur (".. gemwaarden ..") is onder of gelijk aan de norm(".. norm .. "), device: " .. name ..  "")
        if switch.state == 'Off' and onoff == 'Yes' then
            switch.switchOn().checkFirst().silent() 
        end
        if notify == 'Yes' and (dz.data.sendnotification[name] == false) then
            dz.notify('03 Sensor info         = Huidig gemiddelde temperatuur ('.. gemwaarden .. ') van device:' .. name2 .. ' is lange tijd('.. tostring(DurTimer) .. '), onder de norm('.. norm .. ')',
            name,PRIORITY_NORMAL,sound,receivers,dz.NSS_PUSHOVER)
            dz.data.sendnotification[name] = true       -- eerste waarde teller op 0 gezet  -- registreren dat notificatie is gedaan
        end
    end

    dz.data.prevhistwaarde.add(huidwaarde)
    --dz.devices('Temperatuur').updateTemperature(huidwaarde)

end
}
I also have a script for checking the thermodevice is realy working my measuring its usage....
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest