dzVents: MaxMin Temp and Humidity  [Solved]

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

Moderator: leecollings

User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by waaren »

zavjah wrote: Saturday 15 August 2020 21:26 I'd like to combine this with a second script I have for rain level:
I would keep these script separate because they handle different type of sensors.
Can you check this one?

Code: Select all

local RainLevelTest = 'getRainLevel'

return
{
    on=
    {
        timer =
        {
            'every Minute',
        },
        httpResponses =
        {
            RainLevelTest,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG, --LOG_DEBUG, LOG_ERROR, LOG_INFO
        marker =    RainLevelTest,
    },

    execute = function(dz, item)

        local rainDevice = dz.devices('Regen') -- name enclosed in quotes or number without quotes

        local regenMaenge = 8       -- Wieviel mm Regen braucht es, damti ich NICHT gieße?
        local regenZeitraum = 240     -- Hours vom Zeitpunkt des Skript lauf aus, also heute!

        local function getGraphData(dv, hours)
            if item.isDevice or item.isTimer then
                local period = 'day'
                if hours > 24 then
                    period = 'month'
                    if hours % 24 ~= 0 then
                        dz.log('Script can only calculate for multiples of 24 or < 24' )
                    end
                end
                dz.openURL(
                    { url =  dz.settings['Domoticz url'] .. '/json.htm?type=graph&sensor=rain&idx=' .. dv.idx .. '&range=' .. period, --&range=day oder &range=month
                     callback = RainLevelTest,
                    })
            end
        end

        local function getmmRain(rt, hours)
            local startDate = dz.time.addHours(-1 * math.floor(hours)).rawDateTime
            local mm = 0
            for index, record in ipairs(rt) do
                if record.d > startDate then
                    dz.log(record,dz.LOG_DEBUG)
                    mm = mm + record.mm
                end
            end
            return mm
        end

        -- Main
        if item.isDevice or item.isTimer then
           getGraphData(rainDevice, regenZeitraum)
        elseif item.ok and item.isJSON then
            dz.log('Regenmenge in den letzten ' .. (regenZeitraum) .. ' h: ' .. getmmRain(item.json.result, regenZeitraum) .. ' mm')
        else
            dz.log('Keine valide Antwort von domoticz ',dz.LOG_ERROR)
            dz.log(item,dz.LOG_ERROR)
        end
    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
zavjah
Posts: 36
Joined: Tuesday 13 August 2019 10:20
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: dzVents: MaxMin Temp and Humidity

Post by zavjah »

Hi waaren,

thx for your replay. It seems to me that your modified script does pretty much the same as mine, which in deed is based on one of yours from this forum :-).

Back to my initial question: I need the Information about the max temperature yesterday and the rain level within the last 24h in my main script for watering my garden. if I understood you correctly you suggest to have:
1. Script for Rain level
2. Script for max temperature
3. Script for watering that calls the their two and get the necessary Information.

I assume 1 and 2 should be kind of independant functions. Correct? If yes, then my questions are:
a) how do they should like and
b) how am I to call them from my main script (3)

thx,
zavjah
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by waaren »

zavjah wrote: Sunday 16 August 2020 21:23 It seems to me that your modified script does pretty much the same as mine, which in deed is based on one of yours from this forum :-).
Your script ignore the date/time of the records. It adds all values from the json return without checking if it should be part of the sum.
if I understood you correctly you suggest to have:
1. Script for Rain level
2. Script for max temperature
yes
3. Script for watering that calls the their two and get the necessary Information.
Not quite. It should not call the scripts

You now only report the values to the domoticz log but it is more common that you use these values to update a virtual sensor or a uservariable. The main script for watering can then retrieve the values from the uservariables or the virtual sensors and apply it' s logic to decide what needs to be done.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
zavjah
Posts: 36
Joined: Tuesday 13 August 2019 10:20
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: dzVents: MaxMin Temp and Humidity

Post by zavjah »

Hi wareen,

I've done following:

1. Created global_data.lua via domoticz scripting GUIO with following content:

Code: Select all

    return {
        helpers = {},
        data = {
          MaxTempGestern = { initial = false },
          RegenGestern = { initial = false }
        }
    }
2. Then, to add values to the variables I have my scripts and provide values like this

Code: Select all

...

        -- Main
        if item.ok and item.isJSON then
            extremes = getExtremes(item.json.result)
            dz.globalData.MaxTempGestern = extremes.high.temperature
        end
..

Code: Select all

...
        if item.ok and item.isJSON then
            dz.log('Regenmenge in den letzten 24h: ' .. getmm(item.json.result) .. 'mm')    
            dz.globalData.RegenGestern = getmm(item.json.result)
        else
            dz.log('Keine valide Antwort von domoticz ',dz.LOG_ERROR)    
            dz.log(item,dz.LOG_ERROR)    
        end
...
3. When I try to read those variables in my main script I get some error about nill values. Did I forget something?

thx,
Zavjah
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by waaren »

zavjah wrote: Monday 17 August 2020 15:31 3. When I try to read those variables in my main script I get some error about nill values. Did I forget something?
The code you show here looks OK.
Please share your main script and loglines. That might help in locating the issue.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
zavjah
Posts: 36
Joined: Tuesday 13 August 2019 10:20
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: dzVents: MaxMin Temp and Humidity

Post by zavjah »

Hello waaren,

this is my global_data.lua

Code: Select all

    return {
        helpers = {},
        data = {
          MaxTempGestern = { initial = false },
          RegenGestern = { initial = false }
        }
    }
This is globalData_MaxTempGestern.dzvent, that provides the value for MaxTempGestern:

Code: Select all

local MaxTemperature = 'getMaxTemp'

return {on = {timer           =   {'every Minute'},                       -- Your preferred time
              httpResponses   =   { MaxTemperature }
              },

    execute = function(dz, item)
        local tempDevice = dz.devices('Außen')
        local extremes = {}

        if item.isDevice or item.isTimer then
            dz.openURL({    url = 'http://192.168.178.23:8080/json.htm?type=graph&sensor=temp&range=day&idx=' .. tempDevice.idx  .. '&range=day',
                            method = "GET",
                            callback = MaxTemperature })
            return
        end

        local function getExtremes(rt)
            extremes.high               = {}
            extremes.high.temperature   = -256

            for key in ipairs(rt) do
                if tonumber(rt[key].te) > extremes.high.temperature then
                    extremes.high.temperature = tonumber(rt[key].te)
                end
            end
            return extremes
        end

        -- Main
        if item.ok and item.isJSON then
            extremes = getExtremes(item.json.result)
            dz.globalData.MaxTempGestern = extremes.high.temperature
        end
    end
}
The globalData_RegenGestern supplies the value for MaxTempGestern:

Code: Select all

local RainLevelTest = 'getRainLevel'

return {on= {
            timer = {'every Minute'},
            httpResponses = {RainLevelTest,},
            },

    execute = function(dz, item)
        local rainDevice = dz.devices('Regen') -- name enclosed in quotes or number without quotes
        local regenZeitraum = 2     -- Tage vom Zeitpunkt des Skript lauf aus, also heute!

        if item.isDevice or item.isTimer then
            dz.openURL(
                {url = 'http://192.168.178.23:8080/json.htm?type=graph&sensor=rain&idx=' .. rainDevice.idx .. '&range=day', --&range=day oder &range=week oder &range=month
                 callback = RainLevelTest,
                })
            return
        end
        
        local function getmm(rt)
            local startDate = (dz.time.addMinutes(-1 * regenZeitraum * 24 * 60)).rawDate
            local mm = 0
            for index, record in ipairs(rt) do
                mm = mm + record.mm
            end
            return mm
        end

-- Main
        if item.ok and item.isJSON then
            dz.globalData.RegenGestern = getmm(item.json.result)
        else
            dz.log('Keine valide Antwort von domoticz ',dz.LOG_ERROR)    
            dz.log(item,dz.LOG_ERROR)    
        end
    end
}
The main script, just for test, should report the values into the log:

Code: Select all

return {
	on = {timer = {'at 12:11'}
	},

	execute = function(dz, timer)
        dz.log('Info aus Variablen: Regenmenge: ' .. dz.globalData.RegenGestern .. ' || MaxTemp: ' .. dz.globalData.MaxTempGestern)
	end
}
Does this makes sense?

Cheers,
zavjah
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by waaren »

zavjah wrote: Monday 17 August 2020 16:12 Does this makes sense?
Yes it does (apart from the earlier comment I posted that you ignore and data / time selection) but kind of hard to debug without log :D so if it does not work as expected you might need to add some log statements and will need to look at the log to see what happens.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
zavjah
Posts: 36
Joined: Tuesday 13 August 2019 10:20
Target OS: Raspberry Pi / ODroid
Domoticz version:

Re: dzVents: MaxMin Temp and Humidity  [Solved]

Post by zavjah »

Hello waaren

I've turned on the DEBUG logging, but couldn't find any error. I put the values in global variables and when I print them out of the script that sets them it works. But I cannot retrieve them from another script.

So I decided to switch to virtual sensors and created one for rain and one for temperature and was able to update their values as needed. So it works now, thx.

Cheers,
Zavjah
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by Nautilus »

waaren wrote: Monday 21 January 2019 17:40
AYAMY wrote: Monday 21 January 2019 11:33 The ranges of the calculation are incorrect... The Entreme date is today (21 January ) and yesterday (20 January ) but the high\ low temperatures and high\low humidity are of the 16 January 2019 and 14 January 2019
Adjusted the script to make the range a configurable amount of hours.
Nice work waaren, I was looking for ideas to implement this kind of notifications from our summer cottage and this does the trick very well. I'm new to dzVents and while I checked the wiki I was not able to transform this (yet) to the kind of script that would loop through an array of sensors and combine the max/min values to one message. I tried by chancing the device.id to an array of devices and looping through them in the main section (which I assumed would give me the info I am after as separate messages), but there was clearly something wrong as it ended up in an infinite loop. Could you point me to the right direction, please? :)

Here's my attempt:

Code: Select all

        local S1 = dz.devices('Olohuoneen lämpötila')
        local S2 = dz.devices('Makuuhuoneen lämpötila')
        local S3 = dz.devices('Danielin huoneen lämpötila')
        
        local temphumDevices = {S1,S2,S3}
...
        for i = 1,#temphumDevices do
            temphumDevice=temphumDevices[i]
            if not temphumDevice.isHTTPResponse then
                triggerJSON()
            elseif temphumDevice.ok then                                      -- statusCode == 2xx
                extremes = getExtremes(temphumDevice.json.result)
                notify(getTimeWindow(24))
            else
                logWrite("Could not get (good) data from domoticz. Error (" .. (temphumDevice.statusCode or 999) .. ")"  ,dz.LOG_ERROR)
                logWrite(temphumDevice.data)
            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: MaxMin Temp and Humidity

Post by waaren »

Nautilus wrote: Thursday 08 October 2020 11:43 I was not able to transform this (yet) to the kind of script that would loop through an array of sensors and combine the max/min values to one message.
Do you want a max/min per device or one max and one min for the array of devices?

Please share your complete script as there are more versions "flying around"
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by Nautilus »

waaren wrote: Thursday 08 October 2020 12:19
Nautilus wrote: Thursday 08 October 2020 11:43 I was not able to transform this (yet) to the kind of script that would loop through an array of sensors and combine the max/min values to one message.
Do you want a max/min per device or one max and one min for the array of devices?

Please share your complete script as there are more versions "flying around"
I was thinking that I will configure the exact content once I get a hold of the loop logi. But max/min would be for each divice separately (or prehaps max for each, min for each etc. in one group). The functions were working ok and the script itself with one device. First I thought the probem was the execute = function(dz, item) as this resulted in double notifications from the devices (in random order, though) and then found one looping example where it was just execute = function(dz) - but this then resulted to the infinite loop and I was afraid to test anything after this...:) So hopefully it is just a light push that I'd need to the right direction. In any case, please find below the code I was testing.

Code: Select all

-- getMaxTempHum

local httpResponses = "getMaxTempHum"

return {
    on      =   {
                    timer           =   { "at 7:30"     },                       -- Your preferred time
                    httpResponses   =   { httpResponses }
                },

    logging =   {
                    level           =   domoticz.LOG_ERROR,
                    marker          =   httpResponse
                },

    execute = function(dz)
        -- ****************************** Your settings below this line ***************************************************
        --temphumDevice = dz.devices(14)    -- Replace with ID of Device you want to be notified on
        local S1 = dz.devices('AAA')
        local S2 = dz.devices('BBB')
        local S3 = dz.devices('CCC')

        
        local temphumDevices = {S1,S2,S3}
        -- ****************************** No changes required below this line *********************************************

        local extremes = {}

        local function logWrite(str,level)
            dz.log(tostring(str),level or dz.LOG_DEBUG)
        end

        local function triggerJSON()
            local  URLString   = dz.settings['Domoticz url'] .. "/json.htm?type=graph&sensor=temp&range=day&idx=" .. temphumDevice.id
            dz.openURL({    url = URLString,
                            method = "GET",
                            callback = httpResponses })
        end

        local function convertTime(timeString)               -- based on incoming format yyyy-mm-dd hh:mm
            local year, month, day, hour, minute
            _,_, year, month, day, hour, minute = string.find(timeString, "(%d+)-(%d+)-(%d+) (%d+):(%d+)")
            fmtString = os.date("%A, %d %B %Y (%H:%M)",os.time({year=year, month=month, day=day, hour=hour, minute=minute })):gsub(" 0"," ")
            logWrite(fmtString)
            return fmtString                                 -- outgoing format: ddd d mmmm yyyy (hh:mm)
        end

        local function showResult(str)
            textDevice.updateText(str)
            logWrite(str,dz.LOG_FORCE)
        end

        local function getTimeWindow(hours)
            local to   = os.time(os.date("*t"))
            local from = os.date("%A, %d %B %Y (%H:%M)",to - hours * 3600)
            local to   = os.date("%A, %d %B %Y (%H:%M)",to)
            return to, from
        end

        local function notify(from,now)
            local notificationString =  "\nKorkein lämpötila: " .. extremes.high.temperature .. " C (" .. extremes.high.tTime .. ")\n------------------------------\n"
            notificationString = notificationString .. "Alin läpötila: " .. extremes.low.temperature .. " C (" .. extremes.low.tTime .. ")\n------------------------------\n"
            notificationString = notificationString .. "Korkein kosteus: " .. extremes.high.humidity .. "% (" .. extremes.high.hTime .. ")\n------------------------------\n"
            notificationString = notificationString .. "Matalin kosteus:  " .. extremes.low.humidity .. "% (" .. extremes.low.hTime .. ")\n========================="

            logWrite("\nVaihtelu välillä " .. from .. " ja " .. now .. "\n" .. notificationString,dz.LOG_FORCE)            
            dz.notify("Vaihtelu välillä " .. from .. " ja " .. now, notificationString, dz.PRIORITY_NORMAL, nil,nil, dz.NSS_TELEGRAM)
        end

        local function getExtremes(rt)
            extremes.low                = {}
            extremes.high               = {}
            extremes.low.temperature    = 10000
            extremes.low.humidity       = 100
            extremes.high.humidity      = 0
            extremes.high.temperature   = -256

            for key in ipairs(rt) do
                if tonumber(rt[key].hu) > extremes.high.humidity then
                    logWrite("New max humidity found on " .. convertTime(rt[key].d) .. " ==>> " .. rt[key].hu )
                    extremes.high.humidity = tonumber(rt[key].hu)
                    extremes.high.hTime = rt[key].d
                end
                if tonumber(rt[key].hu) < extremes.low.humidity then
                    logWrite("New min humidity found on " .. convertTime(rt[key].d) .. " ==>> " .. rt[key].hu )
                    extremes.low.humidity = tonumber(rt[key].hu)
                    extremes.low.hTime = rt[key].d
                end
                if tonumber(rt[key].te) > extremes.high.temperature then
                    logWrite("New max temperature found on " .. convertTime(rt[key].d) .. " ==>> " .. rt[key].te )
                    extremes.high.temperature = tonumber(rt[key].te)
                    extremes.high.tTime = rt[key].d
                end
                if tonumber(rt[key].te) < extremes.low.temperature then
                    logWrite("New min temperature found on " .. convertTime(rt[key].d) .. " ==>> " .. rt[key].te )
                    extremes.low.temperature = tonumber(rt[key].te)
                    extremes.low.tTime = rt[key].d
                end
            end
            return extremes
        end


        -- Main
        for i = 1,#temphumDevices do
            temphumDevice=temphumDevices[i]
            if not temphumDevice.isHTTPResponse then
                triggerJSON()
            elseif temphumDevice.ok then                                      -- statusCode == 2xx
                extremes = getExtremes(temphumDevice.json.result)
                notify(getTimeWindow(24))
            else
                logWrite("Could not get (good) data from domoticz. Error (" .. (temphumDevice.statusCode or 999) .. ")"  ,dz.LOG_ERROR)
                logWrite(temphumDevice.data)
            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: MaxMin Temp and Humidity

Post by waaren »

Nautilus wrote: Thursday 08 October 2020 13:55 I was thinking that I will configure the exact content once I get a hold of the loop logi. But max/min would be for each divice separately (or prehaps max for each, min for each etc. in one group). The functions were working ok and the script itself with one device. F

So hopefully it is just a light push that I'd need to the right direction.
Light push below ....

Code: Select all

-- getMaxTempHum

local scriptVar = 'getMaxTempHum'

return
{
    on =
    {
        timer =
        {
            'at 7:30'  -- Your preferred time
        },
        devices =
        {
            'extremeTrigger', -- just for test can be ignored
        },

        httpResponses =
        {
            scriptVar .. '*',
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    data =
    {
        extremes =
        {
            initial =
            {
                {},
            },
        },
    },
    
    execute = function(dz, item)
        -- ****************************** Your settings below this line ***************************************************
        --temphumDevice = dz.devices(14)    -- Replace with ID of Device you want to be notified on

        local temphumDevices =
        {
             'AAA',
             'BBB',
             'CCC',
        }
        
        -- ****************************** No changes required below this line *********************************************

        local extremes = {}

        local function triggerJSON(id, delay)
            local  URLString   = dz.settings['Domoticz url'] .. '/json.htm?type=graph&sensor=temp&range=day&idx=' .. id
            dz.openURL(
            {
                url = URLString,
                callback = scriptVar .. '_' .. id
            }).afterSec(delay)
        end

        local function convertTime(timeString)               -- based on incoming format yyyy-mm-dd hh:mm
            local year, month, day, hour, minute
            _,_, year, month, day, hour, minute = string.find(timeString, '(%d+)-(%d+)-(%d+) (%d+):(%d+)')
            fmtString = os.date('%A, %d %B %Y (%H:%M)',os.time({year=year, month=month, day=day, hour=hour, minute=minute })):gsub(' 0',' ')
            dz.log(fmtString)
            return fmtString                                 -- outgoing format: ddd d mmmm yyyy (hh:mm)
        end

        local function showResult(str)
            textDevice.updateText(str)
            dz.log(str,dz.LOG_FORCE)
        end

        local function getTimeWindow(hours)
            local to   = os.time(os.date('*t'))
            local from = os.date('%A, %d %B %Y (%H:%M)',to - hours * 3600)
            local to   = os.date('%A, %d %B %Y (%H:%M)',to)
            return to, from
        end

        local function notify(now, from, extremes)
            local notificationString
            for device, r in pairs(extremes) do
                dz.log(device)
                dz.log(r)
                notificationString =  '\n' ..   device ..' high temp: '     .. r.highTemperature .. ' C (' .. r.highTemperatureTime .. ')\n' ..
                                                device ..' low temp: '      .. r.lowTemperature .. ' C (' .. r.lowTemperatureTime .. ')\n'..
                                                device ..' high humidity: ' .. r.highHumidity .. '% (' .. r.highHumidityTime .. ')\n' ..
                                                device ..' low humidity: '  .. r.lowHumidity .. '% (' .. r.lowHumidityTime .. ')\n'
                    
                dz.log(notificationString .. from .. ' until ' .. now,dz.LOG_FORCE)
                dz.notify(device .. ':' .. from .. ' until ' .. now, notificationString, dz.PRIORITY_NORMAL, nil,nil, dz.NSS_TELEGRAM)
            end
        end

        local function getExtremes(rt )
            local dvExtremes = {}  -- extremes per device
            dvExtremes.lowTemperature    = 10000
            dvExtremes.lowHumidity       = 100
            dvExtremes.highHumidity      = 0
            dvExtremes.highTemperature   = -256

            for key in ipairs(rt) do
                if tonumber(rt[key].hu) > dvExtremes.highHumidity then
                    -- dz.log('New max humidity found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].hu )
                    dvExtremes.highHumidity = tonumber(rt[key].hu)
                    dvExtremes.highHumidityTime = rt[key].d
                end
                if tonumber(rt[key].hu) < dvExtremes.lowHumidity then
                    -- dz.log('New min humidity found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].hu )
                    dvExtremes.lowHumidity = tonumber(rt[key].hu)
                    dvExtremes.lowHumidityTime = rt[key].d
                end
                if tonumber(rt[key].te) > dvExtremes.highTemperature then
                    -- dz.log('New max temperature found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].te )
                    dvExtremes.highTemperature = tonumber(rt[key].te)
                    dvExtremes.highTemperatureTime = rt[key].d
                end
                if tonumber(rt[key].te) < dvExtremes.lowTemperature then
                    -- dz.log('New min temperature found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].te )
                    dvExtremes.lowTemperature = tonumber(rt[key].te)
                    dvExtremes.lowTemperatureTime = rt[key].d
                end
            end
            return dvExtremes
        end

        -- Main
        if item.isTime or item.isDevice then
            local delay = 0
            for _, deviceName in ipairs(temphumDevices) do
                triggerJSON(dz.devices(deviceName).id, delay)
                delay = delay + 5
                dz.data.extremes.lastDevice = deviceName
            end
        elseif item.isJSON and #item.json.result > 10 then         -- statusCode = OK and JSON contains enough records
            local extremes = dz.data.extremes -- get table from persistent data
            local deviceName = dz.devices(tonumber( ( item.trigger:gsub(scriptVar .. '_','' )) )).name
            dz.log('Handling device  ' .. deviceName ,dz.LOG_DEBUG )
            extremes[deviceName] = getExtremes(item.json.result) -- Merge device extremes in total extremes
            if deviceName == dz.data.extremes.lastDevice then -- all devices done
                dz.log('All devices are done. Extremes can be found in table extremes and in persistent data' ,dz.LOG_DEBUG )
                extremes.lastDevice = nil -- We do not need this anymore
                local from, now = getTimeWindow(24)
                -- dz.utils.dumpTable(extremes) -- for debugging
                notify(from, now, extremes)
            end
            dz.data.extremes = extremes -- store Table in persistent data
        else
            dz.log('Could not get (good) data from domoticz. Error (' .. (temphumDevice.statusCode or 999) .. ')'  ,dz.LOG_ERROR)
            dz.log(temphumDevice.data,dz.LOG_DEBUG)
        end
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by Nautilus »

Thanks, this is great! Unfortunately I may need a sligthly harder push :)

First I was not getting anything else in the log than start, "nil" and stop. I then changed some value from device to devices, cannot remember anymore which. At this point I started getting errors in the log and noticed that the first if clause in main is not true at any point. I then changed it to what I originally had, i.e. "if not item.isHTTPResponse then". This seemed to take it a step further so script is running until the notify section. But there I get nil value errors from all the variables that should contain the high/low values and times, e.g:

Error: dzVents: Error: (3.0.14) getMaxTempHum: ...e/pi/domoticz/scripts/dzVents/generated_scripts/Test.lua:91: attempt to concatenate a nil value (field 'highHumidityTime')

I tried a few things but I'm afraid I keep adding new error on top of old ones if I keep going :) After enabling debugging I can see in the log:
2020-10-09 15:56:00.398 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Olohuoneen lämpötila: Temperature+humidity device adapter
2020-10-09 15:56:00.398 Status: dzVents: Debug: getMaxTempHum: OpenURL: url = http://127.0.0.1:30/json.htm?type=graph ... day&idx=14
2020-10-09 15:56:00.398 Status: dzVents: Debug: getMaxTempHum: OpenURL: method = GET
2020-10-09 15:56:00.398 Status: dzVents: Debug: getMaxTempHum: OpenURL: post data = nil
2020-10-09 15:56:00.398 Status: dzVents: Debug: getMaxTempHum: OpenURL: headers = nil
2020-10-09 15:56:00.398 Status: dzVents: Debug: getMaxTempHum: OpenURL: callback = getMaxTempHum_14
2020-10-09 15:56:00.399 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Makuuhuoneen lämpötila: Temperature+humidity device adapter
2020-10-09 15:56:00.399 Status: dzVents: Debug: getMaxTempHum: OpenURL: url = http://127.0.0.1:30/json.htm?type=graph ... day&idx=66
2020-10-09 15:56:00.399 Status: dzVents: Debug: getMaxTempHum: OpenURL: method = GET
2020-10-09 15:56:00.399 Status: dzVents: Debug: getMaxTempHum: OpenURL: post data = nil
2020-10-09 15:56:00.399 Status: dzVents: Debug: getMaxTempHum: OpenURL: headers = nil
2020-10-09 15:56:00.399 Status: dzVents: Debug: getMaxTempHum: OpenURL: callback = getMaxTempHum_66
2020-10-09 15:56:00.399 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Danielin huoneen lämpötila: Temperature+humidity device adapter
2020-10-09 15:56:00.400 Status: dzVents: Debug: getMaxTempHum: OpenURL: url = http://127.0.0.1:30/json.htm?type=graph ... day&idx=75
2020-10-09 15:56:00.400 Status: dzVents: Debug: getMaxTempHum: OpenURL: method = GET
2020-10-09 15:56:00.400 Status: dzVents: Debug: getMaxTempHum: OpenURL: post data = nil
2020-10-09 15:56:00.400 Status: dzVents: Debug: getMaxTempHum: OpenURL: headers = nil
2020-10-09 15:56:00.400 Status: dzVents: Debug: getMaxTempHum: OpenURL: callback = getMaxTempHum_75
2020-10-09 15:56:00.400 Status: dzVents: Info: getMaxTempHum: ------ Finished Test
2020-10-09 15:56:00.401 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-10-09 15:56:00.545 Status: dzVents: Info: Handling httpResponse-events for: "getMaxTempHum_14"
2020-10-09 15:56:00.545 Status: dzVents: Info: getMaxTempHum: ------ Start internal script: Test: HTTPResponse: "getMaxTempHum_14"
2020-10-09 15:56:00.633 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Olohuoneen lämpötila: Temperature+humidity device adapter
2020-10-09 15:56:00.633 Status: dzVents: Debug: getMaxTempHum: Handling device Olohuoneen lämpötila
2020-10-09 15:56:00.633 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (15:00)
2020-10-09 15:56:00.633 Status: dzVents: Info: getMaxTempHum: New max humidity found on Sunday, 4 October 2020 (15:00) ==>> 48
2020-10-09 15:56:00.633 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (15:00)
2020-10-09 15:56:00.633 Status: dzVents: Info: getMaxTempHum: New min humidity found on Sunday, 4 October 2020 (15:00) ==>> 48
2020-10-09 15:56:00.633 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (15:00)
2020-10-09 15:56:00.633 Status: dzVents: Info: getMaxTempHum: New max temperature found on Sunday, 4 October 2020 (15:00) ==>> 21.6
2020-10-09 15:56:00.633 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (15:00)
2020-10-09 15:56:00.633 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (15:00) ==>> 21.6
2020-10-09 15:56:00.633 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (16:00)
2020-10-09 15:56:00.633 Status: dzVents: Info: getMaxTempHum: New max humidity found on Sunday, 4 October 2020 (16:00) ==>> 49
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (16:00)
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (16:00) ==>> 21.4
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (18:00)
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (18:00) ==>> 21.1
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (19:00)
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (19:00) ==>> 21.0
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (20:00)
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: New max humidity found on Sunday, 4 October 2020 (20:00) ==>> 50
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (20:00)
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (20:00) ==>> 20.9
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (21:00)
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (21:00) ==>> 20.8
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (23:00)
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (23:00) ==>> 20.7
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (02:00)
2020-10-09 15:56:00.634 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (02:00) ==>> 20.6
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (13:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (13:00) ==>> 22.1
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (14:00) ==>> 47
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 22.6
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (14:00) ==>> 46
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 23.2
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (14:00) ==>> 45
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 23.3
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 23.7
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (14:00) ==>> 44
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 24.2
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (15:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (15:00) ==>> 43
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (15:00)
2020-10-09 15:56:00.635 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (15:00) ==>> 24.7
2020-10-09 15:56:00.636 Status: dzVents: Info: getMaxTempHum: Tuesday, 6 October 2020 (18:00)
2020-10-09 15:56:00.636 Status: dzVents: Info: getMaxTempHum: New max humidity found on Tuesday, 6 October 2020 (18:00) ==>> 51
2020-10-09 15:56:00.637 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (09:00)
2020-10-09 15:56:00.637 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (09:00) ==>> 20.5
2020-10-09 15:56:00.638 Status: dzVents: Info: getMaxTempHum: ------ Finished Test
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: New max temperature found on Sunday, 4 October 2020 (15:00) ==>> 19.9
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (15:00)
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (15:00) ==>> 19.9
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (16:00)
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: New max temperature found on Sunday, 4 October 2020 (16:00) ==>> 20.0
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (22:00)
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (22:00) ==>> 19.8
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (03:00)
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (03:00) ==>> 19.7
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (04:00)
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (04:00) ==>> 19.6
2020-10-09 15:56:05.682 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 20.1
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: New max humidity found on Monday, 5 October 2020 (14:00) ==>> 55
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (15:00)
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (15:00) ==>> 20.2
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (16:00)
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (16:00) ==>> 20.3
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (17:00)
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (17:00) ==>> 20.4
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (18:00)
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (18:00) ==>> 20.5
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (20:00)
2020-10-09 15:56:05.683 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (20:00) ==>> 20.6
2020-10-09 15:56:05.685 Status: dzVents: Info: getMaxTempHum: ------ Finished Test
2020-10-09 15:56:10.570 Status: dzVents: Info: Handling httpResponse-events for: "getMaxTempHum_75"
2020-10-09 15:56:10.570 Status: dzVents: Info: getMaxTempHum: ------ Start internal script: Test: HTTPResponse: "getMaxTempHum_75"
2020-10-09 15:56:10.656 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Danielin huoneen lämpötila: Temperature+humidity device adapter
2020-10-09 15:56:10.656 Status: dzVents: Debug: getMaxTempHum: Handling device Danielin huoneen lämpötila
2020-10-09 15:56:10.656 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (15:00)
2020-10-09 15:56:10.656 Status: dzVents: Info: getMaxTempHum: New max humidity found on Sunday, 4 October 2020 (15:00) ==>> 52
2020-10-09 15:56:10.656 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (15:00)
2020-10-09 15:56:10.656 Status: dzVents: Info: getMaxTempHum: New min humidity found on Sunday, 4 October 2020 (15:00) ==>> 52
2020-10-09 15:56:10.656 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (15:00)
2020-10-09 15:56:10.656 Status: dzVents: Info: getMaxTempHum: New max temperature found on Sunday, 4 October 2020 (15:00) ==>> 20.5
2020-10-09 15:56:10.656 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (15:00)
2020-10-09 15:56:10.656 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (15:00) ==>> 20.5
2020-10-09 15:56:10.656 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (16:00)
2020-10-09 15:56:10.656 Status: dzVents: Info: getMaxTempHum: New max temperature found on Sunday, 4 October 2020 (16:00) ==>> 20.6
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (20:00)
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (20:00) ==>> 20.4
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (22:00)
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: New max humidity found on Sunday, 4 October 2020 (22:00) ==>> 53
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: Sunday, 4 October 2020 (22:00)
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: New min temperature found on Sunday, 4 October 2020 (22:00) ==>> 20.3
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (00:00)
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (00:00) ==>> 20.2
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (00:00)
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (00:00) ==>> 20.1
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (04:00)
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (04:00) ==>> 20.0
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (15:00)
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (15:00) ==>> 20.8
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (15:00)
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (15:00) ==>> 21.0
2020-10-09 15:56:10.657 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (16:00)
2020-10-09 15:56:10.658 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (16:00) ==>> 21.1
2020-10-09 15:56:10.658 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (17:00)
2020-10-09 15:56:10.658 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (17:00) ==>> 21.2
2020-10-09 15:56:10.658 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (17:00)
2020-10-09 15:56:10.658 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (17:00) ==>> 21.4
2020-10-09 15:56:10.658 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (18:00)
2020-10-09 15:56:10.658 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (18:00) ==>> 21.5
2020-10-09 15:56:10.658 Status: dzVents: Info: getMaxTempHum: Wednesday, 7 October 2020 (08:00)
2020-10-09 15:56:10.658 Status: dzVents: Info: getMaxTempHum: New max humidity found on Wednesday, 7 October 2020 (08:00) ==>> 54
2020-10-09 15:56:10.659 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (08:00)
2020-10-09 15:56:10.659 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (08:00) ==>> 19.9
2020-10-09 15:56:10.659 Status: dzVents: Debug: getMaxTempHum: All devices are done. Extremes can be found in table extremes and in persistent data
2020-10-09 15:56:10.659 Status: dzVents: > 1:
2020-10-09 15:56:10.659 Status: dzVents: > Makuuhuoneen lämpötila:
2020-10-09 15:56:10.659 Status: dzVents: > lowTemperatureTime: 2020-10-05 04:35
2020-10-09 15:56:10.659 Status: dzVents: > highTemperatureTime: 2020-10-05 20:15
2020-10-09 15:56:10.659 Status: dzVents: > lowHumidity: 54
2020-10-09 15:56:10.659 Status: dzVents: > highHumidity: 55
2020-10-09 15:56:10.659 Status: dzVents: > highTemperature: 20.6
2020-10-09 15:56:10.659 Status: dzVents: > lowHumidityTime: 2020-10-04 15:55
2020-10-09 15:56:10.659 Status: dzVents: > highHumidityTime: 2020-10-05 14:50
2020-10-09 15:56:10.659 Status: dzVents: > lowTemperature: 19.6
2020-10-09 15:56:10.659 Status: dzVents: > Olohuoneen lämpötila:
2020-10-09 15:56:10.660 Status: dzVents: > lowTemperatureTime: 2020-10-09 09:35
2020-10-09 15:56:10.660 Status: dzVents: > highTemperatureTime: 2020-10-05 15:35
2020-10-09 15:56:10.660 Status: dzVents: > lowHumidity: 43
2020-10-09 15:56:10.660 Status: dzVents: > highHumidity: 51
2020-10-09 15:56:10.660 Status: dzVents: > highTemperature: 24.7
2020-10-09 15:56:10.660 Status: dzVents: > lowHumidityTime: 2020-10-05 15:35
2020-10-09 15:56:10.660 Status: dzVents: > highHumidityTime: 2020-10-06 18:55
2020-10-09 15:56:10.660 Status: dzVents: > lowTemperature: 20.5
2020-10-09 15:56:10.660 Status: dzVents: > Danielin huoneen lämpötila:
2020-10-09 15:56:10.660 Status: dzVents: > lowTemperatureTime: 2020-10-09 08:50
2020-10-09 15:56:10.660 Status: dzVents: > lowTemperature: 19.9
2020-10-09 15:56:10.660 Status: dzVents: > lowHumidity: 52
2020-10-09 15:56:10.660 Status: dzVents: > highHumidity: 54
2020-10-09 15:56:10.660 Status: dzVents: > highTemperature: 21.5
2020-10-09 15:56:10.660 Status: dzVents: > lowHumidityTime: 2020-10-04 15:55
2020-10-09 15:56:10.660 Status: dzVents: > highTemperatureTime: 2020-10-05 18:45
2020-10-09 15:56:10.660 Status: dzVents: > highHumidityTime: 2020-10-07 08:20
2020-10-09 15:56:10.660 Status: dzVents: Info: getMaxTempHum: 1
2020-10-09 15:56:10.660 Status: dzVents: Info: getMaxTempHum: {}
2020-10-09 15:56:10.660 Status: dzVents: Info: getMaxTempHum: ------ Finished Test
2020-10-09 15:56:10.660 Error: dzVents: Error: (3.0.14) getMaxTempHum: An error occurred when calling event handler Test
2020-10-09 15:56:10.660 Error: dzVents: Error: (3.0.14) getMaxTempHum: ...e/pi/domoticz/scripts/dzVents/generated_scripts/Test.lua:91: attempt to concatenate a nil value (field 'lowHumidity')
2020-10-09 15:56:56.093 Proxy: Error, reconnecting (Connection timed out)
It must be some mistake I have made along the way or some feature of dzVents I have not enabled?
Last edited by Nautilus on Saturday 10 October 2020 0:36, 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: dzVents: MaxMin Temp and Humidity

Post by waaren »

Nautilus wrote: Friday 09 October 2020 15:06 I may need a sligthly harder push :)
It must be some mistake I have made along the way or some feature of dzVents I have not enabled?

Code: Select all

2020-10-09 15:56:10.659 Status: dzVents: > 1:
This 1 should not be there and when I (successfully) test the script I don't see it.
Only thing I can think of now is that there is still some old data left in the persistent data file.

If you can remove the persistent data file from <domoticz dir>/scripts/dzVents/data/ and change

Code: Select all

if item.isTime or item.isDevice then
to

Code: Select all

if item.isTime or item.isDevice then
            dz.data.extremes = {} -- this will remove any data from this persistent table

and try again with only names of temp+hum sensors in temphumDevices.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by Nautilus »

Ok, if I change it from "if not item.isHTTPResponse then" back to "if item.isTime or item.isDevice then" and add dz.data.extremes = {} I go back to getting the same error as initially got:
2020-10-10 01:14:47.928 Status: EventSystem: reset all events...
2020-10-10 01:14:47.929 Status: dzVents: Write file: /home/pi/domoticz/scripts/dzVents/generated_scripts/Test.lua
2020-10-10 01:15:00.262 Status: dzVents: Info: getMaxTempHum: ------ Start internal script: Test:, trigger: "at 01:15"
2020-10-10 01:15:00.263 Status: dzVents: Debug: getMaxTempHum: nil
2020-10-10 01:15:00.264 Status: dzVents: Info: getMaxTempHum: ------ Finished Test
2020-10-10 01:15:00.263 Error: dzVents: Error: (3.0.14) getMaxTempHum: Could not get (good) data from domoticz. Error (999)
So the first if clause (item.isTime or item.isDevice) does not seem to be true.
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by Nautilus »

I then went back to "if not item.isHTTPResponse then" and included dz.data.extremes = {}. This actually worked and I got the notification for each three devices on a separate message. Btw, I also checked the data directory, but I didn't have anyting there except:
-rw-r----- 1 root root 1140 Oct 10 01:21 __data_Test.lua
-rw-r--r-- 1 pi pi 278 Jul 14 16:12 README.md
edit: sorry, __data_Test.lua --> this was of course the file as I named the script "Test" :)

With the succesful run the log says:
Spoiler: show
2020-10-10 01:21:00.333 Status: dzVents: Info: getMaxTempHum: ------ Start internal script: Test:, trigger: "at 01:21"
2020-10-10 01:21:00.350 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Olohuoneen lämpötila: Temperature+humidity device adapter
2020-10-10 01:21:00.350 Status: dzVents: Debug: getMaxTempHum: OpenURL: url = http://127.0.0.1:30/json.htm?type=graph ... day&idx=14
2020-10-10 01:21:00.350 Status: dzVents: Debug: getMaxTempHum: OpenURL: method = GET
2020-10-10 01:21:00.350 Status: dzVents: Debug: getMaxTempHum: OpenURL: post data = nil
2020-10-10 01:21:00.350 Status: dzVents: Debug: getMaxTempHum: OpenURL: headers = nil
2020-10-10 01:21:00.350 Status: dzVents: Debug: getMaxTempHum: OpenURL: callback = getMaxTempHum_14
2020-10-10 01:21:00.351 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Makuuhuoneen lämpötila: Temperature+humidity device adapter
2020-10-10 01:21:00.351 Status: dzVents: Debug: getMaxTempHum: OpenURL: url = http://127.0.0.1:30/json.htm?type=graph ... day&idx=66
2020-10-10 01:21:00.351 Status: dzVents: Debug: getMaxTempHum: OpenURL: method = GET
2020-10-10 01:21:00.351 Status: dzVents: Debug: getMaxTempHum: OpenURL: post data = nil
2020-10-10 01:21:00.351 Status: dzVents: Debug: getMaxTempHum: OpenURL: headers = nil
2020-10-10 01:21:00.351 Status: dzVents: Debug: getMaxTempHum: OpenURL: callback = getMaxTempHum_66
2020-10-10 01:21:00.352 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Danielin huoneen lämpötila: Temperature+humidity device adapter
2020-10-10 01:21:00.352 Status: dzVents: Debug: getMaxTempHum: OpenURL: url = http://127.0.0.1:30/json.htm?type=graph ... day&idx=75
2020-10-10 01:21:00.352 Status: dzVents: Debug: getMaxTempHum: OpenURL: method = GET
2020-10-10 01:21:00.352 Status: dzVents: Debug: getMaxTempHum: OpenURL: post data = nil
2020-10-10 01:21:00.352 Status: dzVents: Debug: getMaxTempHum: OpenURL: headers = nil
2020-10-10 01:21:00.352 Status: dzVents: Debug: getMaxTempHum: OpenURL: callback = getMaxTempHum_75
2020-10-10 01:21:00.353 Status: dzVents: Info: getMaxTempHum: ------ Finished Test
2020-10-10 01:21:00.354 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-10-10 01:21:00.510 Status: dzVents: Info: Handling httpResponse-events for: "getMaxTempHum_14"
2020-10-10 01:21:00.510 Status: dzVents: Info: getMaxTempHum: ------ Start internal script: Test: HTTPResponse: "getMaxTempHum_14"
2020-10-10 01:21:00.607 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Olohuoneen lämpötila: Temperature+humidity device adapter
2020-10-10 01:21:00.607 Status: dzVents: Debug: getMaxTempHum: Handling device Olohuoneen lämpötila
2020-10-10 01:21:00.607 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:00.607 Status: dzVents: Info: getMaxTempHum: New max humidity found on Monday, 5 October 2020 (01:00) ==>> 50
2020-10-10 01:21:00.607 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:00.607 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (01:00) ==>> 50
2020-10-10 01:21:00.607 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (01:00) ==>> 20.7
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (01:00) ==>> 20.7
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (02:00)
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (02:00) ==>> 20.6
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (10:00)
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (10:00) ==>> 20.8
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (11:00)
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (11:00) ==>> 20.9
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (12:00)
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (12:00) ==>> 21.1
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (13:00)
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (13:00) ==>> 49
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (13:00)
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (13:00) ==>> 21.3
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (13:00)
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (13:00) ==>> 21.6
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (13:00)
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (13:00) ==>> 48
2020-10-10 01:21:00.608 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (13:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (13:00) ==>> 22.1
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (14:00) ==>> 47
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 22.6
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (14:00) ==>> 46
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 23.2
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (14:00) ==>> 45
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 23.3
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 23.7
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (14:00) ==>> 44
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 24.2
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (15:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (15:00) ==>> 43
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (15:00)
2020-10-10 01:21:00.609 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (15:00) ==>> 24.7
2020-10-10 01:21:00.610 Status: dzVents: Info: getMaxTempHum: Tuesday, 6 October 2020 (18:00)
2020-10-10 01:21:00.610 Status: dzVents: Info: getMaxTempHum: New max humidity found on Tuesday, 6 October 2020 (18:00) ==>> 51
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (09:00)
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (09:00) ==>> 20.5
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (19:00)
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (19:00) ==>> 20.4
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (21:00)
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (21:00) ==>> 20.3
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (22:00)
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (22:00) ==>> 20.2
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (22:00)
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (22:00) ==>> 20.1
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: Saturday, 10 October 2020 (00:00)
2020-10-10 01:21:00.611 Status: dzVents: Info: getMaxTempHum: New min temperature found on Saturday, 10 October 2020 (00:00) ==>> 20.0
2020-10-10 01:21:00.612 Status: dzVents: Info: getMaxTempHum: ------ Finished Test
2020-10-10 01:21:05.505 Status: dzVents: Info: Handling httpResponse-events for: "getMaxTempHum_66"
2020-10-10 01:21:05.505 Status: dzVents: Info: getMaxTempHum: ------ Start internal script: Test: HTTPResponse: "getMaxTempHum_66"
2020-10-10 01:21:05.591 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Makuuhuoneen lämpötila: Temperature+humidity device adapter
2020-10-10 01:21:05.591 Status: dzVents: Debug: getMaxTempHum: Handling device Makuuhuoneen lämpötila
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: New max humidity found on Monday, 5 October 2020 (01:00) ==>> 54
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (01:00) ==>> 54
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (01:00) ==>> 19.8
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (01:00) ==>> 19.8
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (03:00)
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (03:00) ==>> 19.7
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (04:00)
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (04:00) ==>> 19.6
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (12:00)
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (12:00) ==>> 19.9
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (13:00)
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (13:00) ==>> 20.0
2020-10-10 01:21:05.592 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 20.1
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: New max humidity found on Monday, 5 October 2020 (14:00) ==>> 55
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (15:00)
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (15:00) ==>> 20.2
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (16:00)
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (16:00) ==>> 20.3
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (17:00)
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (17:00) ==>> 20.4
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (18:00)
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (18:00) ==>> 20.5
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (20:00)
2020-10-10 01:21:05.593 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (20:00) ==>> 20.6
2020-10-10 01:21:05.595 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (22:00)
2020-10-10 01:21:05.595 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (22:00) ==>> 19.5
2020-10-10 01:21:05.595 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (22:00)
2020-10-10 01:21:05.595 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (22:00) ==>> 19.4
2020-10-10 01:21:05.595 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (23:00)
2020-10-10 01:21:05.595 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (23:00) ==>> 19.3
2020-10-10 01:21:05.595 Status: dzVents: Info: getMaxTempHum: Saturday, 10 October 2020 (00:00)
2020-10-10 01:21:05.595 Status: dzVents: Info: getMaxTempHum: New min humidity found on Saturday, 10 October 2020 (00:00) ==>> 53
2020-10-10 01:21:05.595 Status: dzVents: Info: getMaxTempHum: Saturday, 10 October 2020 (00:00)
2020-10-10 01:21:05.595 Status: dzVents: Info: getMaxTempHum: New min temperature found on Saturday, 10 October 2020 (00:00) ==>> 19.2
2020-10-10 01:21:05.596 Status: dzVents: Info: getMaxTempHum: ------ Finished Test
2020-10-10 01:21:10.992 Notification sent (telegram) => Success
2020-10-10 01:21:10.531 Status: dzVents: Info: Handling httpResponse-events for: "getMaxTempHum_75"
2020-10-10 01:21:10.531 Status: dzVents: Info: getMaxTempHum: ------ Start internal script: Test: HTTPResponse: "getMaxTempHum_75"
2020-10-10 01:21:10.618 Status: dzVents: Debug: getMaxTempHum: Processing device-adapter for Danielin huoneen lämpötila: Temperature+humidity device adapter
2020-10-10 01:21:10.618 Status: dzVents: Debug: getMaxTempHum: Handling device Danielin huoneen lämpötila
2020-10-10 01:21:10.618 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:10.618 Status: dzVents: Info: getMaxTempHum: New max humidity found on Monday, 5 October 2020 (01:00) ==>> 53
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: New min humidity found on Monday, 5 October 2020 (01:00) ==>> 53
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (01:00) ==>> 20.2
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (01:00) ==>> 20.2
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (01:00)
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (01:00) ==>> 20.1
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (04:00)
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: New min temperature found on Monday, 5 October 2020 (04:00) ==>> 20.0
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (11:00)
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (11:00) ==>> 20.3
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 20.4
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (14:00)
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (14:00) ==>> 20.6
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (15:00)
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (15:00) ==>> 20.8
2020-10-10 01:21:10.619 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (15:00)
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (15:00) ==>> 21.0
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (16:00)
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (16:00) ==>> 21.1
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (17:00)
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (17:00) ==>> 21.2
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (17:00)
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (17:00) ==>> 21.4
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: Monday, 5 October 2020 (18:00)
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: New max temperature found on Monday, 5 October 2020 (18:00) ==>> 21.5
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: Wednesday, 7 October 2020 (08:00)
2020-10-10 01:21:10.620 Status: dzVents: Info: getMaxTempHum: New max humidity found on Wednesday, 7 October 2020 (08:00) ==>> 54
2020-10-10 01:21:10.621 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (08:00)
2020-10-10 01:21:10.621 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (08:00) ==>> 19.9
2020-10-10 01:21:10.621 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (20:00)
2020-10-10 01:21:10.621 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (20:00) ==>> 19.8
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (20:00)
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (20:00) ==>> 19.6
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (21:00)
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (21:00) ==>> 19.5
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (22:00)
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (22:00) ==>> 19.3
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (23:00)
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (23:00) ==>> 19.2
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: Friday, 9 October 2020 (23:00)
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: New min temperature found on Friday, 9 October 2020 (23:00) ==>> 19.1
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: Saturday, 10 October 2020 (00:00)
2020-10-10 01:21:10.622 Status: dzVents: Info: getMaxTempHum: New min temperature found on Saturday, 10 October 2020 (00:00) ==>> 19.0
2020-10-10 01:21:10.622 Status: dzVents: Debug: getMaxTempHum: All devices are done. Extremes can be found in table extremes and in persistent data
2020-10-10 01:21:10.622 Status: dzVents: > Makuuhuoneen lämpötila:
2020-10-10 01:21:10.622 Status: dzVents: > lowTemperatureTime: 2020-10-10 00:45
2020-10-10 01:21:10.622 Status: dzVents: > highTemperature: 20.6
2020-10-10 01:21:10.622 Status: dzVents: > highHumidity: 55
2020-10-10 01:21:10.622 Status: dzVents: > highHumidityTime: 2020-10-05 14:50
2020-10-10 01:21:10.622 Status: dzVents: > lowTemperature: 19.2
2020-10-10 01:21:10.622 Status: dzVents: > lowHumidityTime: 2020-10-10 00:45
2020-10-10 01:21:10.622 Status: dzVents: > lowHumidity: 53
2020-10-10 01:21:10.622 Status: dzVents: > highTemperatureTime: 2020-10-05 20:15
2020-10-10 01:21:10.622 Status: dzVents: > Danielin huoneen lämpötila:
2020-10-10 01:21:10.622 Status: dzVents: > lowTemperatureTime: 2020-10-10 00:30
2020-10-10 01:21:10.622 Status: dzVents: > highHumidityTime: 2020-10-07 08:20
2020-10-10 01:21:10.622 Status: dzVents: > highHumidity: 54
2020-10-10 01:21:10.622 Status: dzVents: > highTemperature: 21.5
2020-10-10 01:21:10.622 Status: dzVents: > lowTemperature: 19.0
2020-10-10 01:21:10.622 Status: dzVents: > lowHumidity: 53
2020-10-10 01:21:10.622 Status: dzVents: > lowHumidityTime: 2020-10-05 01:20
2020-10-10 01:21:10.622 Status: dzVents: > highTemperatureTime: 2020-10-05 18:45
2020-10-10 01:21:10.622 Status: dzVents: > Olohuoneen lämpötila:
2020-10-10 01:21:10.622 Status: dzVents: > lowTemperatureTime: 2020-10-10 00:10
2020-10-10 01:21:10.622 Status: dzVents: > highTemperature: 24.7
2020-10-10 01:21:10.622 Status: dzVents: > highHumidity: 51
2020-10-10 01:21:10.623 Status: dzVents: > highHumidityTime: 2020-10-06 18:55
2020-10-10 01:21:10.623 Status: dzVents: > lowTemperature: 20.0
2020-10-10 01:21:10.623 Status: dzVents: > lowHumidityTime: 2020-10-05 15:35
2020-10-10 01:21:10.623 Status: dzVents: > lowHumidity: 43
2020-10-10 01:21:10.623 Status: dzVents: > highTemperatureTime: 2020-10-05 15:35
2020-10-10 01:21:10.623 Status: dzVents: Info: getMaxTempHum: Makuuhuoneen lämpötila
2020-10-10 01:21:10.623 Status: dzVents: Info: getMaxTempHum: {["lowTemperatureTime"]="2020-10-10 00:45", ["highTemperature"]=20.6, ["highHumidity"]=55, ["highHumidityTime"]="2020-10-05 14:50", ["lowTemperature"]=19.2, ["lowHumidityTime"]="2020-10-10 00:45", ["lowHumidity"]=53, ["highTemperatureTime"]="2020-10-05 20:15"}
2020-10-10 01:21:10.623 Status: dzVents: !Info: getMaxTempHum:
2020-10-10 01:21:10.623 Makuuhuoneen lämpötila high temp: 20.6 C
2020-10-10 01:21:10.623 Makuuhuoneen lämpötila low temp: 19.2 C
2020-10-10 01:21:10.623 Makuuhuoneen lämpötila high humidity: 55%
2020-10-10 01:21:10.623 Makuuhuoneen lämpötila low humidity: 53%
2020-10-10 01:21:10.623 Friday, 09 October 2020 (01:21) until Saturday, 10 October 2020 (01:21)
2020-10-10 01:21:10.623 Status: dzVents: Info: getMaxTempHum: Danielin huoneen lämpötila
2020-10-10 01:21:10.623 Status: dzVents: Info: getMaxTempHum: {["lowTemperatureTime"]="2020-10-10 00:30", ["highHumidityTime"]="2020-10-07 08:20", ["highHumidity"]=54, ["highTemperature"]=21.5, ["lowTemperature"]=19.0, ["lowHumidity"]=53, ["lowHumidityTime"]="2020-10-05 01:20", ["highTemperatureTime"]="2020-10-05 18:45"}
2020-10-10 01:21:10.623 Status: dzVents: !Info: getMaxTempHum:
2020-10-10 01:21:10.623 Danielin huoneen lämpötila high temp: 21.5 C
2020-10-10 01:21:10.623 Danielin huoneen lämpötila low temp: 19.0 C
2020-10-10 01:21:10.623 Danielin huoneen lämpötila high humidity: 54%
2020-10-10 01:21:10.623 Danielin huoneen lämpötila low humidity: 53%
2020-10-10 01:21:10.623 Friday, 09 October 2020 (01:21) until Saturday, 10 October 2020 (01:21)
2020-10-10 01:21:10.623 Status: dzVents: Info: getMaxTempHum: Olohuoneen lämpötila
2020-10-10 01:21:10.623 Status: dzVents: Info: getMaxTempHum: {["lowTemperatureTime"]="2020-10-10 00:10", ["highTemperature"]=24.7, ["highHumidity"]=51, ["highHumidityTime"]="2020-10-06 18:55", ["lowTemperature"]=20.0, ["lowHumidityTime"]="2020-10-05 15:35", ["lowHumidity"]=43, ["highTemperatureTime"]="2020-10-05 15:35"}
2020-10-10 01:21:10.623 Status: dzVents: !Info: getMaxTempHum:
2020-10-10 01:21:10.623 Olohuoneen lämpötila high temp: 24.7 C
2020-10-10 01:21:10.623 Olohuoneen lämpötila low temp: 20.0 C
2020-10-10 01:21:10.623 Olohuoneen lämpötila high humidity: 51%
2020-10-10 01:21:10.623 Olohuoneen lämpötila low humidity: 43%
2020-10-10 01:21:10.623 Friday, 09 October 2020 (01:21) until Saturday, 10 October 2020 (01:21)
2020-10-10 01:21:10.624 Status: dzVents: Info: getMaxTempHum: ------ Finished Test
2020-10-10 01:21:10.624 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-10-10 01:21:10.640 Status: Notification: Makuuhuoneen lämpötila:Friday, 09 October 2020 (01:21) until Saturday, 10 October 2020 (01:21)
2020-10-10 01:21:10.640 Status: Notification: Danielin huoneen lämpötila:Friday, 09 October 2020 (01:21) until Saturday, 10 October 2020 (01:21)
2020-10-10 01:21:10.640 Status: Notification: Olohuoneen lämpötila:Friday, 09 October 2020 (01:21) until Saturday, 10 October 2020 (01:21)
It came to my mind that does it matter which type I select for the dzVent script in the event editor? For Lua scripts I know it matters (you should select device for those that are triggered from device change etc.), but for dzVents I'm not sure. From where I picked up the script originally it said to select the Http Request but should it rather be timer? Or does this matter for dzVents?
Last edited by Nautilus on Saturday 10 October 2020 1:05, edited 1 time in total.
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by Nautilus »

I tested with type timer, but it did not matter. In any case, in this format:

Code: Select all

-- getMaxTempHum

local scriptVar = 'getMaxTempHum'

return
{
    on =
    {
        timer =
        {
            'at 01:53'  -- Your preferred time
        },
        devices =
        {
            'extremeTrigger', -- just for test can be ignored
        },

        httpResponses =
        {
            scriptVar .. '*',
        },
    },

    logging =
    {
        level = domoticz.LOG_INFO,
        marker = scriptVar,
    },

    data =
    {
        extremes =
        {
            initial =
            {
                {},
            },
        },
    },
    
    execute = function(dz, item)
        -- ****************************** Settings below this line ***************************************************
        local temphumDevices =
        {
        'Olohuoneen lämpötila',
        'Makuuhuoneen lämpötila',
        'Danielin huoneen lämpötila',
        }
        
        -- ****************************** No changes required below this line *********************************************

        local extremes = {}

        local function triggerJSON(id, delay)
            local  URLString   = dz.settings['Domoticz url'] .. '/json.htm?type=graph&sensor=temp&range=day&idx=' .. id
            dz.openURL(
            {
                url = URLString,
                callback = scriptVar .. '_' .. id
            }).afterSec(delay)
        end

        local function convertTime(timeString)               -- based on incoming format yyyy-mm-dd hh:mm
            local year, month, day, hour, minute
            _,_, year, month, day, hour, minute = string.find(timeString, '(%d+)-(%d+)-(%d+) (%d+):(%d+)')
            fmtString = os.date('%A, %d %B %Y (%H:%M)',os.time({year=year, month=month, day=day, hour=hour, minute=minute })):gsub(' 0',' ')
            dz.log(fmtString)
            return fmtString                                 -- outgoing format: ddd d mmmm yyyy (hh:mm)
        end

        local function showResult(str)
            textDevice.updateText(str)
            dz.log(str,dz.LOG_FORCE)
        end

        local function getTimeWindow(hours)
            local to   = os.time(os.date('*t'))
            local from = os.date('%A, %d %B %Y (%H:%M)',to - hours * 3600)
            local to   = os.date('%A, %d %B %Y (%H:%M)',to)
            return to, from
        end

        local function notify(now, from, extremes)
            local notificationString
            for device, r in pairs(extremes) do
                dz.log(device)
                dz.log(r)
                notificationString =  '\n' ..   device ..' high temp: '     .. r.highTemperature .. ' C (' .. r.highTemperatureTime .. ')\n' ..
                                                device ..' low temp: '      .. r.lowTemperature .. ' C (' .. r.lowTemperatureTime .. ')\n'..
                                                device ..' high humidity: ' .. r.highHumidity .. '% (' .. r.highHumidityTime .. ')\n' ..
                                                device ..' low humidity: '  .. r.lowHumidity .. '% (' .. r.lowHumidityTime .. ')\n'
                    
                dz.log(notificationString .. from .. ' until ' .. now,dz.LOG_FORCE)
                dz.notify(device .. ':' .. from .. ' until ' .. now, notificationString, dz.PRIORITY_NORMAL, nil,nil, dz.NSS_TELEGRAM)
            end
        end

        local function getExtremes(rt )
            local dvExtremes = {}  -- extremes per device
            dvExtremes.lowTemperature    = 10000
            dvExtremes.lowHumidity       = 100
            dvExtremes.highHumidity      = 0
            dvExtremes.highTemperature   = -256

            for key in ipairs(rt) do
                if tonumber(rt[key].hu) > dvExtremes.highHumidity then
                    -- dz.log('New max humidity found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].hu )
                    dvExtremes.highHumidity = tonumber(rt[key].hu)
                    dvExtremes.highHumidityTime = rt[key].d
                end
                if tonumber(rt[key].hu) < dvExtremes.lowHumidity then
                    -- dz.log('New min humidity found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].hu )
                    dvExtremes.lowHumidity = tonumber(rt[key].hu)
                    dvExtremes.lowHumidityTime = rt[key].d
                end
                if tonumber(rt[key].te) > dvExtremes.highTemperature then
                    -- dz.log('New max temperature found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].te )
                    dvExtremes.highTemperature = tonumber(rt[key].te)
                    dvExtremes.highTemperatureTime = rt[key].d
                end
                if tonumber(rt[key].te) < dvExtremes.lowTemperature then
                    -- dz.log('New min temperature found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].te )
                    dvExtremes.lowTemperature = tonumber(rt[key].te)
                    dvExtremes.lowTemperatureTime = rt[key].d
                end
            end
            return dvExtremes
        end

        -- Main
        if not item.isHTTPResponse then
            dz.data.extremes = {} -- this will remove any data from this persistent table
            local delay = 0
            for _, deviceName in ipairs(temphumDevices) do
                triggerJSON(dz.devices(deviceName).id, delay)
                delay = delay + 5
                dz.data.extremes.lastDevice = deviceName
            end
        elseif item.isJSON and #item.json.result > 10 then         -- statusCode = OK and JSON contains enough records
            local extremes = dz.data.extremes -- get table from persistent data
            local deviceName = dz.devices(tonumber( ( item.trigger:gsub(scriptVar .. '_','' )) )).name
            dz.log('Handling device  ' .. deviceName ,dz.LOG_DEBUG )
            extremes[deviceName] = getExtremes(item.json.result) -- Merge device extremes in total extremes
            if deviceName == dz.data.extremes.lastDevice then -- all devices done
                dz.log('All devices are done. Extremes can be found in table extremes and in persistent data' ,dz.LOG_DEBUG )
                extremes.lastDevice = nil -- We do not need this anymore
                local from, now = getTimeWindow(24)
                -- dz.utils.dumpTable(extremes) -- for debugging
                notify(from, now, extremes)
            end
            dz.data.extremes = extremes -- store Table in persistent data
        else
            dz.log('Could not get (good) data from domoticz. Error (' .. (temphumDevice.statusCode or 999) .. ')'  ,dz.LOG_ERROR)
            dz.log(temphumDevice.data,dz.LOG_DEBUG)
        end
    end
}
...the script provides the output I was looking for. So thanks a lot! :) Of course, if we can find an exlanation for this inconsistency between my system and yours I'd appreciate it very much as it would help me to understand the logic. Also, Iäd be interested to understand for which purpose are these in the beginning of the scirpt:

Code: Select all

        devices =
        {
            'extremeTrigger', -- just for test can be ignored
        },

        httpResponses =
        {
            scriptVar .. '*',
        },
edit: One challenge remains I noticed. I'd like the range to be 24 hours, but the json seems to return the whole short log which is defined for 5 days in my setup. So extremes are picked from the course of 5 days. I guess I need a condition for looping the array, somethin like:

Code: Select all

            for key in ipairs(rt) do
                if rt[key].d > "time now - 24h"
But I did not succeed in making this work. With Lua I've used timedifference function in this type of situations. Would that be preferred here with dzVents as well?

edit2: One more thing :D Now the Telegram messages come in seemingly random order. I guess I would need to tell dzVents to wait until one message is sent and then move to next so that it would respect the order in which I've listed the devices? Any pointers to this?
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by waaren »

Nautilus wrote: Saturday 10 October 2020 0:51 ...the script provides the output I was looking for.
Of course, if we can find an explanation for this inconsistency between my system and yours I'd appreciate it very much as it would help me to understand the logic.
I don't think there are any inconsistencies but expect the issues encountered were caused by a typo I made. I used "item.isTime" and it should have been "item.isTimer" . Because I test with a device as trigger, I did not notice that before.

In this script

Code: Select all

        if not item.isHTTPResponse then
            dz.data.extremes = {} -- this will remove any data from this persistent table
and

Code: Select all

        if item.isTimer or item.isDevice then
            dz.data.extremes = {}
Will do the same as besides HTTPResponses there are no other triggers used then Time and Devices. So if it is not a HTTPResponse it can only be Time or Device.
Also, Iäd be interested to understand for which purpose are these in the beginning of the scirpt:

Code: Select all

        devices =
        {
            'extremeTrigger', -- just for test can be ignored
        },

        httpResponses =
        {
            scriptVar .. '*',
        },
I use a dummy device named extremeTrigger to trigger the script when testing so I don't have to modify the time and wait until the next full minute. That is also why I use "if item.isTime or item.isDevice"
edit: One challenge remains I noticed. I'd like the range to be 24 hours, but the json seems to return the whole short log which is defined for 5 days in my setup. So extremes are picked from the course of 5 days. I guess I need a condition for looping the array, somethin like:

Code: Select all

            for key in ipairs(rt) do
                if rt[key].d > "time now - 24h"
But I did not succeed in making this work. With Lua I've used timedifference function in this type of situations. Would that be preferred here with dzVents as well?
See below (I use the dzVents addHours method for time objects to create a new time object with a time of 24 hours ago)
edit2: One more thing :D Now the Telegram messages come in seemingly random order. I guess I would need to tell dzVents to wait until one message is sent and then move to next so that it would respect the order in which I've listed the devices? Any pointers to this?
See below for the changes I made in function notify to have the script do this.

Code: Select all

-- getMaxTempHum

local scriptVar = 'getMaxTempHum'

return
{
    on =
    {
        timer =
        {
            'at 01:53'  -- Your preferred time
        },
        devices =
        {
            'extremeTrigger', -- just for test can be ignored
        },

        httpResponses =
        {
            scriptVar .. '*',
        },
    },

    logging =
    {
        level = domoticz.LOG_INFO,
        marker = scriptVar,
    },

    data =
    {
        extremes =
        {
            initial =
            {
                {},
            },
        },
    },

    execute = function(dz, item)
        -- ****************************** Settings below this line ***************************************************
        local temphumDevices =
        {
        'Olohuoneen lämpötila',
        'Makuuhuoneen lämpötila',
        'Danielin huoneen lämpötila',
        }
        
        local reportHours = 36 -- Amount of hours in the past until now (cannot be more then what you defined as short log period)
        local secondsBetweenApiCalls = 5 -- used in main to allow for some time between API calls (do not overload system)
        local secondsBetweenNotifications = 5 -- used in notify function to allow for some time between messages
        -- ****************************** No changes required below this line *********************************************

        local extremes = {}

        local function triggerJSON(id, delay)
            local  URLString   = dz.settings['Domoticz url'] .. '/json.htm?type=graph&sensor=temp&range=day&idx=' .. id
            dz.openURL(
            {
                url = URLString,
                callback = scriptVar .. '_' .. id
            }).afterSec(delay)
        end

        local function convertTime(timeString)               -- based on incoming format yyyy-mm-dd hh:mm
            local year, month, day, hour, minute
            _,_, year, month, day, hour, minute = string.find(timeString, '(%d+)-(%d+)-(%d+) (%d+):(%d+)')
            fmtString = os.date('%A, %d %B %Y (%H:%M)',os.time({year=year, month=month, day=day, hour=hour, minute=minute })):gsub(' 0',' ')
            dz.log(fmtString)
            return fmtString                                 -- outgoing format: ddd d mmmm yyyy (hh:mm)
        end

        local function showResult(str)
            textDevice.updateText(str)
            dz.log(str,dz.LOG_FORCE)
        end

        local function getTimeWindow(hours)
            local to   = os.time(os.date('*t'))
            local from = os.date('%A, %d %B %Y (%H:%M)',to - hours * 3600)
            local to   = os.date('%A, %d %B %Y (%H:%M)',to)
            return to, from
        end

       local function notify(now, from, extremes)
            local notificationString
            local delay = 0

               for _, sensorName in pairs(temphumDevices) do
                dz.log('Now processing records from sensor ' .. sensorName, dz.LOG_DEBUG)
                r = extremes[sensorName] -- get the right record
                notificationString =  '\n' ..   sensorName ..' high temp: '     .. r.highTemperature .. ' C (' .. r.highTemperatureTime .. ')\n' ..
                                                sensorName ..' low temp: '      .. r.lowTemperature .. ' C (' .. r.lowTemperatureTime .. ')\n'..
                                                sensorName ..' high humidity: ' .. r.highHumidity .. '% (' .. r.highHumidityTime .. ')\n' ..
                                                sensorName ..' low humidity: '  .. r.lowHumidity .. '% (' .. r.lowHumidityTime .. ')\n'

                dz.log(notificationString .. from .. ' until ' .. now,dz.LOG_FORCE)
                dz.notify(sensorName .. ':' .. from .. ' until ' .. now, notificationString, dz.PRIORITY_NORMAL, nil,nil, dz.NSS_TELEGRAM, delay)
                delay = delay + secondsBetweenNotifications -- Allow some time between messages
            end
        end

        local function getExtremes(rt )
            local dvExtremes = {}  -- extremes per device
            dvExtremes.lowTemperature    = 10000
            dvExtremes.lowHumidity       = 100
            dvExtremes.highHumidity      = 0
            dvExtremes.highTemperature   = -256

            local pastTime = dz.time.addHours(reportHours  * -1).raw
            dz.log(reportHours .. ' hours ago...   ' .. pastTime, dz.LOG_DEBUG)
            
            for key in ipairs(rt) do
                if rt[key].d >= pastTime then
                    if tonumber(rt[key].hu) > dvExtremes.highHumidity then
                        -- dz.log('New max humidity found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].hu )
                        dvExtremes.highHumidity = tonumber(rt[key].hu)
                        dvExtremes.highHumidityTime = rt[key].d
                    end
                    if tonumber(rt[key].hu) < dvExtremes.lowHumidity then
                        -- dz.log('New min humidity found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].hu )
                        dvExtremes.lowHumidity = tonumber(rt[key].hu)
                        dvExtremes.lowHumidityTime = rt[key].d
                    end
                    if tonumber(rt[key].te) > dvExtremes.highTemperature then
                        -- dz.log('New max temperature found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].te )
                        dvExtremes.highTemperature = tonumber(rt[key].te)
                        dvExtremes.highTemperatureTime = rt[key].d
                    end
                    if tonumber(rt[key].te) < dvExtremes.lowTemperature then
                        -- dz.log('New min temperature found on ' .. convertTime(rt[key].d) .. ' ==>> ' .. rt[key].te )
                        dvExtremes.lowTemperature = tonumber(rt[key].te)
                        dvExtremes.lowTemperatureTime = rt[key].d
                    end
                end
            end
            return dvExtremes
        end

        -- Main
        if item.isTimer or item.isDevice then
            dz.data.extremes = {} -- this will remove any data from this persistent table
            local delay = 0
            for _, deviceName in ipairs(temphumDevices) do
                triggerJSON(dz.devices(deviceName).id, delay)
                delay = delay + secondsBetweenApiCalls
                dz.data.extremes.lastDevice = deviceName
            end
        elseif item.isJSON and #item.json.result > 10 then         -- statusCode = OK and JSON contains enough records
            local extremes = dz.data.extremes -- get table from persistent data
            local deviceName = dz.devices(tonumber( ( item.trigger:gsub(scriptVar .. '_','' )) )).name
            dz.log('Handling device  ' .. deviceName ,dz.LOG_DEBUG )
            extremes[deviceName] = getExtremes(item.json.result) -- Merge device extremes in total extremes
            if deviceName == dz.data.extremes.lastDevice then -- all devices done
                dz.log('All devices are done. Extremes can be found in table extremes and in persistent data' ,dz.LOG_DEBUG )
                extremes.lastDevice = nil -- We do not need this anymore
                local from, now = getTimeWindow(reportHours)
                -- dz.utils.dumpTable(extremes) -- for debugging
                notify(from, now, extremes)
            end
            dz.data.extremes = extremes -- store Table in persistent data
        else
            dz.log('Could not get (good) data from domoticz. Error (' .. (temphumDevice.statusCode or 999) .. ')'  ,dz.LOG_ERROR)
            dz.log(temphumDevice.data,dz.LOG_DEBUG)
        end
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Nautilus
Posts: 722
Joined: Friday 02 October 2015 12:12
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Finland
Contact:

Re: dzVents: MaxMin Temp and Humidity

Post by Nautilus »

Thanks a million, this is working great! :D I also sure I gained a lot of understanding about dzVents and can use it instead of traditional lua scripts in the future...:)
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest