Page 2 of 3

Re: Values are not sent to influxdb

Posted: Saturday 27 July 2019 9:57
by nclgius
PZEM_DzVents.lua:14: attempt to index global 'device' (a nil value)

I added line 14

Grazie

Code: Select all

return {
    on = {
        devices = {
            'PZEM'
        }
    },
    
    data = { lastExecutionTime = { initial = 0 }},
    
    execute = function(dz, item)

        dz.log('Device ' .. item.name .. ' was changed', dz.LOG_INFO)

        pushToInfluxdb('67','0',device.rawData[1]) --Aggiunto Riga 14

        local function pushToInfluxdb(idx , nValue, rawData )
            local sValue = table.concat(rawData,';') 
            local nValue = nValue or 0
            dz.log('idx: ' .. idx, dz.LOG_DEBUG)
            dz.log('nValue: ' .. nValue, dz.LOG_DEBUG)
            dz.log('sValue: ' .. sValue, dz.LOG_DEBUG)
            
            local url = dz.settings['Domoticz url'] ..  '/json.htm?type=command&param=udevice&idx=' .. idx  ..
                        '&nvalue=' .. nValue ..
                        '&svalue=' .. sValue 
            dz.openURL(url)
        end
        
        if dz.data.lastExecutionTime < ( dz.time.dDate - 5 ) then
            pushToInfluxdb( item.idx, 0, item.rawData )
            dz.data.lastExecutionTime = dz.time.dDate
        else
            dz.log('Too soon after last update; we don\'t want an endless loop', dz.LOG_DEBUG)
        end
    end
}

Re: Values are not sent to influxdb

Posted: Saturday 27 July 2019 10:03
by waaren
nclgius wrote: Saturday 27 July 2019 9:57 PZEM_DzVents.lua:14: attempt to index global 'device' (a nil value)
Change 'device' to 'item' and move line 14 below the function (so after current line 27) to get a working code.

Re: Values are not sent to influxdb

Posted: Sunday 28 July 2019 23:08
by nclgius
Non ci siamo ancora:
lua:20: attempt to concatenate local 'rawData' (a table value)

Code: Select all

return {
    on = {
        devices = {
            'PZEM'
        }
    },
    
    data = { lastExecutionTime = { initial = 0 }},
    
    execute = function(dz, item)

        dz.log('Device ' .. item.name .. ' was changed ' .. item.rawData[1], dz.LOG_INFO)
        
        local function pushToInfluxdb(idx , nValue, rawData )
            --local sValue = table.concat(rawData,';') 
            local sValue = rawData
            local nValue = nValue or 0
            dz.log('idx: ' .. idx, dz.LOG_DEBUG)
            dz.log('nValue: ' .. nValue, dz.LOG_DEBUG)
            dz.log('sValue: ' .. rawData, dz.LOG_DEBUG)
            
            local url = dz.settings['Domoticz url'] ..  '/json.htm?type=command&param=udevice&idx=' .. idx  ..
                        '&nvalue=' .. nValue ..
                        '&svalue=' .. rawData 
            dz.openURL(url)
        end
        
        pushToInfluxdb('67','0',tostring(item.rawData[1]))
        
        if dz.data.lastExecutionTime < ( dz.time.dDate - 5 ) then
            pushToInfluxdb( item.idx, 0, item.rawData )
            dz.data.lastExecutionTime = dz.time.dDate
        else
            dz.log('Too soon after last update; we don\'t want an endless loop', dz.LOG_DEBUG)
        end
    end
}
if enabled:

Code: Select all

local sValue = table.concat(rawData,';')
lua:15: bad argument #1 to 'concat' (table expected, got string)

Re: Values are not sent to influxdb  [Solved]

Posted: Monday 29 July 2019 2:36
by waaren
nclgius wrote: Sunday 28 July 2019 23:08 lua:20: attempt to concatenate local 'rawData' (a table value)
if enabled:

Code: Select all

local sValue = table.concat(rawData,';')
lua:15: bad argument #1 to 'concat' (table expected, got string)
You tried to mix the original function with a different call to that function that will very likely not lead to the expected result.
Try this and please revert with all loglines if still not working.

Code: Select all

return {
    on = {
        devices = {
            'PZEM'
        }
    },
        
    logging = { level = domoticz.LOG_DEBUG,
                marker = 'Push to Influx',
              },

    execute = function(dz, item)

        dz.log('Device ' .. item.name .. ' was changed ' .. item.rawData[1], dz.LOG_DEBUG)
        
        local function pushToInfluxdb(idx , nValue, myData )
            local nValue = nValue or 0
            dz.log('idx: ' .. idx, dz.LOG_DEBUG)
            dz.log('nValue: ' .. nValue, dz.LOG_DEBUG)
            dz.log('sValue: ' .. myData, dz.LOG_DEBUG)
            
            local url = dz.settings['Domoticz url'] ..  '/json.htm?type=command&param=udevice&idx=' .. idx  ..
                        '&nvalue=' .. nValue ..
                        '&svalue=' .. myData 
            dz.openURL(url)
        end
        
        pushToInfluxdb(67, 0, tostring(dz.devices(67).rawData[1]))
        
    end

Re: Values are not sent to influxdb

Posted: Tuesday 30 July 2019 20:41
by nclgius
Grazie, finalmente funziona.
Thanks, it finally works.
Thanks for everything.

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 18:13
by lobolobo
Hi everybody,

Sorry but i´m a noob in DzVents.

With this dzvents scrit how can you decide in what InfluxDB yo want to insert de data in case, for example, you have more than one.

Thanks in advance.

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 18:18
by lobolobo
I have a dummy device whose data I want to send to InfluxDB. This device (the dummy one) is filled with data through the following script:

Code: Select all

function update(device, id, power, energy, index)
      commandArray[index] = {['UpdateDevice'] = id .. "|0|" .. power .. ";" .. energy}
end

commandArray = {}

local voltage = 220
local owlvoltage = 230
local deviceid = 1029   --el IDX of the dummy device called "Owl CM119 SCRIPT"

if devicechanged['OWL_CM119'] then
   owl = otherdevices_svalues['OWL_CM119']
   print('OWL_CM119         : '..owl)

   words = {}
   for w in string.gmatch(owl, "%d+%.?%d*") do
      words[#words + 1] = w
   end

   voltage = voltage / owlvoltage
   power = voltage * tonumber(words[1])
   energy = voltage * tonumber(words[2])

   housepower =  math.floor( (power * 10^1) + 0.5) / (10^1)
   print('Owl CM119 SCRIPT : '..housepower)

--   commandArray['Owl Switch'] = 'On'
   update("Owl CM119 SCRIPT", deviceid, power, energy, 1)

end



But the data of the dummy device does not reach InfluxDB. I try to push the dummy device data via HTTP PUSH but nothing. (I got it with the original device but not with de dummy device)

How can i manage that?

Thanks in advance.

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 18:42
by waaren
lobolobo wrote: Saturday 07 September 2019 18:13 Sorry but i´m a noob in DzVents.
When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

With this dzvents scrit how can you decide in what InfluxDB yo want to insert de data in case, for example, you have more than one.
If you use the original script in from this post You could enter the names of all devices you want to push to influxDB in the On = section.

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 18:52
by lobolobo
Thanks waaren for your response.

Regarding what you say here:
"Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
, everything it´s OK. Other DZvents works perfect.


Regarding what you say here:
"If you use the original script in from this post You could enter the names of all devices you want to push to influxDB in the On = section."
I speak of having several databases. I don't mean several devices. I´ve two InfluxDB databases, one called DomoticInflixDB and oher EnergyInfluxDB.

Very grateful for your valuable help. Thanks in advance.

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 21:10
by waaren
lobolobo wrote: Saturday 07 September 2019 18:52 I speak of having several databases. I don't mean several devices. I´ve two InfluxDB databases, one called DomoticInflixDB and oher EnergyInfluxDB.
Missed that nuance :)
Using the script that I referred to in my previous post, that's not possible because that will just force domoticz to use the general settings for the influx link on update.
One way to go forward is to use the aformentioned (dzVents script) mechanism for your primary influxDB and use the influx API in combination with dzVents openURL for the other influx instance(s). I am not in favor of this because you will have to kind of replicate the domoticz code per deice type to send the right data.

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 21:16
by lobolobo
Thanks again waaren for your help.

The problem is that even if i use the script in this post, it doesn't send data to InfluxDB. My default DB is DomoticInfluxDB configured inside Domoticz, in the InfluxDB push site of Domoticz. I mean, in the dummy device case. As i told you, there is no problem with de original device.

What I mean is that I don't see any data from the dummy device in the Influx database. In the queries I can choose the device OWL_CM119 (the original) but it does not seem OWL_CM119_SCRIPT (the dummy one) so I suspect that the dummy device data does not reach InfluxDB when the script is operational

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 21:29
by waaren
lobolobo wrote: Saturday 07 September 2019 21:16 The problem is that even if i use the script in this post, it doesn't send data to InfluxDB. My default DB is DomoticInfluxDB configured inside Domoticz, in the InfluxDB push site of Domoticz. I mean, in the dummy device case. As i told you, there is no problem with de original device.
OK. Couple of questions
  • I have seen different versions of this dzVents script can you share which one you use ?
  • Is the dzVents script triggered when the device is updated ?
  • Do you see anything in the log ?
  • Do you see data from domoticz to influx for any other device ?

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 21:32
by lobolobo
waaren wrote: Saturday 07 September 2019 21:29
lobolobo wrote: Saturday 07 September 2019 21:16 The problem is that even if i use the script in this post, it doesn't send data to InfluxDB. My default DB is DomoticInfluxDB configured inside Domoticz, in the InfluxDB push site of Domoticz. I mean, in the dummy device case. As i told you, there is no problem with de original device.
OK. Couple of questions
  • I have seen different versions of this dzVents script can you share which one you use ?
  • Is the dzVents script triggered when the device is updated ?
  • Do you see anything in the log ?
  • Do you see data from domoticz to influx for any other device ?

While I prepare another answer to your questions I show you the script I use.

Code: Select all

return {
    on = {
        devices = {
            'Owl CM119 SCRIPT'
        }
    },
        
    logging = { level = domoticz.LOG_DEBUG,
                marker = 'Push to InfluxDB',
              },

    execute = function(dz, item)

        dz.log('Device ' .. item.name .. ' was changed ' .. item.rawData[1], dz.LOG_DEBUG)
        
        local function pushToInfluxdb(idx , nValue, myData )
            local nValue = nValue or 0
            dz.log('idx: ' .. idx, dz.LOG_DEBUG)
            dz.log('nValue: ' .. nValue, dz.LOG_DEBUG)
            dz.log('sValue: ' .. myData, dz.LOG_DEBUG)
            
            local url = dz.settings['http://127.0.0.1:6969'] ..  '/json.htm?type=command&param=udevice&idx=' .. idx  ..
                        '&nvalue=' .. nValue ..
                        '&svalue=' .. myData 
            dz.openURL(url)
        end
        
        pushToInfluxdb(67, 0, tostring(dz.devices(67).rawData[1]))
        
    end
    
    }

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 21:37
by lobolobo
OK. Couple of questions
  • I have seen different versions of this dzVents script can you share which one you use ?
  • Is the dzVents script triggered when the device is updated ?
  • Do you see anything in the log ?
  • Do you see data from domoticz to influx for any other device ?

Regarding if I see things in the log, the answer is yes. From device OWL_CM119 (the original one), yes, from the dummy device (OWL_CM119_SCRIPT), no.

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 21:48
by waaren
lobolobo wrote: Saturday 07 September 2019 21:32
While I prepare another answer to your questions I show you the script I use.
your version of the script will not work. Main difference is that you replaced the key 'Domoticz url' with the actual IP:Port and that will prevent dzVents from open any url. DzVents 'knows' the domoticz URL without the need for you to enter it.

Can you try this one ?

Code: Select all

return {
    on = {
        devices = {
					'Owl CM119 SCRIPT'
             }
    },

    logging = { level = domoticz.LOG_DEBUG,
                marker = 'Push to InfluxDB',
              },
    
    data = { lastExecutionTime = { initial = 0 }},
    
    execute = function(dz, item)

        dz.log('Device ' .. item.name .. ' was changed ' .. item.rawData[1], dz.LOG_DEBUG)
        
        local function pushToInfluxdb(idx , nValue, rawData )
            local sValue = table.concat(rawData,';') 
            local nValue = nValue or 0
            dz.log('idx: ' .. idx, dz.LOG_DEBUG)
            dz.log('nValue: ' .. nValue, dz.LOG_DEBUG)
            dz.log('sValue: ' .. sValue, dz.LOG_DEBUG)
            
            local url = dz.settings['Domoticz url'] ..  '/json.htm?type=command&param=udevice&idx=' .. idx  ..
                        '&nvalue=' .. nValue ..
                        '&svalue=' .. sValue 
            dz.openURL(url)
        end
        
        if dz.data.lastExecutionTime < ( dz.time.dDate - 5 ) then
            pushToInfluxdb( item.idx, 0, item.rawData )
            dz.data.lastExecutionTime = dz.time.dDate
        else
            dz.log('Too soon after last update; we don\'t want an endless loop', dz.LOG_DEBUG)
        end
    end
}

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 21:56
by lobolobo
I try it right now. Thank you.

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 22:07
by lobolobo
Nothing, the OWL_CM119_SCRIPT device does not appear in InfluxDB. Dammit! I don't know what can happen.

Re: Values are not sent to influxdb

Posted: Saturday 07 September 2019 23:35
by waaren
lobolobo wrote: Saturday 07 September 2019 22:07 Nothing, the OWL_CM119_SCRIPT device does not appear in InfluxDB. Dammit! I don't know what can happen.
Can you share the part of the logfile where the devices are updated and the dzVents script executes ?
You can send it as PM.

Re: Values are not sent to influxdb

Posted: Sunday 08 September 2019 11:50
by lobolobo
waaren wrote: Saturday 07 September 2019 23:35
lobolobo wrote: Saturday 07 September 2019 22:07 Nothing, the OWL_CM119_SCRIPT device does not appear in InfluxDB. Dammit! I don't know what can happen.
Can you share the part of the logfile where the devices are updated and the dzVents script executes ?
You can send it as PM.
I have sent you a PM

Re: Values are not sent to influxdb

Posted: Sunday 15 March 2020 20:58
by MeAlbert
Hi I undestand now the way Domoticz works when it comes to dummy devices you want to push to influx. I have the following script made in dzVents.

Code: Select all

return {
    on = {
        devices = {
            (64)
        }
    },
        logging = { level = domoticz.LOG_DEBUG,
                marker = 'Push to Influx',
              },
    data = { lastExecutionTime = { initial = 0 }},
    
    execute = function(dz, item)

--        dz.log('Device ' .. item.name .. ' was changed', dz.LOG_INFO)
        dz.log('Device ' .. item.name .. ' was changed ' .. item.rawData[1], dz.LOG_DEBUG)
        
        local function pushToInfluxdb(idx , nValue, rawData )
            local sValue = table.concat(rawData,';') 
            local nValue = nValue or 0
            dz.log('idx: ' .. idx, dz.LOG_DEBUG)
            dz.log('nValue: ' .. nValue, dz.LOG_DEBUG)
            dz.log('sValue: ' .. sValue, dz.LOG_DEBUG)
            
            local url = dz.settings['Domoticz url'] ..  '/json.htm?type=command&param=udevice&idx=' .. idx  ..
                        '&nvalue=' .. nValue ..
                        '&svalue=' .. sValue 
            dz.openURL(url)
        end
        
        if dz.data.lastExecutionTime < ( dz.time.dDate - 5 ) then
            pushToInfluxdb( item.idx, 0, item.rawData )
            dz.data.lastExecutionTime = dz.time.dDate
        else
            dz.log('Too soon after last update; we don\'t want an endless loop', dz.LOG_DEBUG)
        end
    end
}
But I see no values coming in the influx database. I have all settings correct. The logging is giving the folowing result.

Code: Select all

2020-03-15 17:24:05.693 Status: dzVents: Debug: Push to Influx: Device WP Opgewekt was changed 1646
2020-03-15 17:24:05.693 Status: dzVents: Debug: Push to Influx: idx: 64
2020-03-15 17:24:05.693 Status: dzVents: Debug: Push to Influx: nValue: 0
2020-03-15 17:24:05.694 Status: dzVents: Debug: Push to Influx: sValue: 1646;1162285.9500067
2020-03-15 17:24:05.694 Status: dzVents: Debug: Push to Influx: OpenURL: url = http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=64&nvalue=0&svalue=1646;1162285.9500067
2020-03-15 17:24:05.694 Status: dzVents: Debug: Push to Influx: OpenURL: method = GET
2020-03-15 17:24:05.694 Status: dzVents: Debug: Push to Influx: OpenURL: post data = nil
2020-03-15 17:24:05.695 Status: dzVents: Debug: Push to Influx: OpenURL: headers = nil
2020-03-15 17:24:05.695 Status: dzVents: Debug: Push to Influx: OpenURL: callback = nil
2020-03-15 17:24:05.697 Status: dzVents: Info: Push to Influx: ------ Finished Script #4
I assume the nil values are the problem. But how to fix???