Dzvent push data to influxdb

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

Moderator: leecollings

Post Reply
sexyboy
Posts: 14
Joined: Tuesday 25 September 2018 16:34
Target OS: Linux
Domoticz version:
Contact:

Dzvent push data to influxdb

Post by sexyboy »

Hi there,

I'm trying to push some custom metrics to influxdb via domoticz.openURL but I've not managed to succeed so far.
The problem I'm hitting it that the buddy of the request needs to be in binary format.

Please see below:

Code: Select all

curl -i -XPOST 'http://localhost:8086/write?db=mydb' --data-binary 'cpu_load_short,host=server01,region=us-west value=0.64 1434055562000000000'
Influxdb man page:

https://docs.influxdata.com/influxdb/v1 ... ting_data/

Has anyone tried this before?

Thanks in advance.
mehikr
Posts: 1
Joined: Saturday 24 November 2018 17:10
Target OS: Linux
Domoticz version:
Contact:

Re: Dzvent push data to influxdb

Post by mehikr »

Hi, I am using corlysis.com

Code: Select all

curl -i -XPOST 'https://corlysis.com:8086/write?db=test_db' -u token:YOUR-SECRET-PASSWORD --data-binary "meas_test,place=garden value=20.64"
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: Dzvent push data to influxdb

Post by papoo »

influxdb request don't work's with space in name, example :

Code: Select all

curl -i -XPOST 'http://127.0.0.1:8086/write?db=domoticz' --data-binary 'Usage,idx=197,name='Compteur Prises' value=35618.144'
don't work

Code: Select all

curl -i -XPOST 'http://127.0.0.1:8086/write?db=domoticz' --data-binary 'Usage,idx=197,name='Compteur-Prises' value=35618.144'
work fine
User avatar
papoo
Posts: 126
Joined: Friday 22 January 2016 22:14
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.10
Location: France
Contact:

Re: Dzvent push data to influxdb

Post by papoo »

my little script for dummy counters data (this counters don't works with domoticz export data)

Code: Select all

-- v1.00 Auteur papoo 

local influxdbUrl = 'http://127.0.0.1'
local influxdbPort = '8086'
local BDD = 'domoticz'


return {
    active = true,
    on = { devices = { 'Compteur*'}},
    
    logging =   {    level    =   domoticz.LOG_DEBUG,
                    -- level    =   domoticz.LOG_INFO,             -- Seulement un niveau peut être actif; commenter les autres
                    -- level    =   domoticz.LOG_ERROR,            -- Only one level can be active; comment others    
                    -- level    =   domoticz.LOG_MODULE_EXEC_INFO,

                    marker  =   "Export compteurs influxDB v1.0 : " },    

    execute = function(domoticz,compteur)
    

         local nom = string.gsub(compteur.name, ' ', '-')        
         local typeDonnee = 'Usage'

            
            os.execute("curl -i -XPOST '"..influxdbUrl..":"..influxdbPort.."/write?db="..BDD.."' --data-binary '"..typeDonnee..",idx="..compteur.idx..",name='"..nom.."' value="..compteur.counter.."'")
            domoticz.log("curl -i -XPOST '"..influxdbUrl..":"..influxdbPort.."/write?db="..BDD.."' --data-binary '"..typeDonnee..",idx="..compteur.idx..",name='"..nom.."' value="..compteur.counter.."'", domoticz.LOG_DEBUG)

 
            domoticz.log(compteur.idx, domoticz.LOG_DEBUG) 
            domoticz.log(compteur.name, domoticz.LOG_DEBUG)
            domoticz.log(compteur.counter, domoticz.LOG_DEBUG)





   end   
}
xury
Posts: 48
Joined: Monday 10 December 2018 23:32
Target OS: Linux
Domoticz version:
Location: Poland
Contact:

Re: Dzvent push data to influxdb

Post by xury »

Today I just made a script with push data to influxdb in pure dzVent
It's is my first script so in not so nice, but works well:

Code: Select all

return  {
   on = {
    timer = { 'every minute' },
    devices = { 14 }
    },
    execute = function(domoticz, item)
	if (item.isTimer) then
		if (domoticz.devices(14).nValue == 3) then
			domoticz.devices('Stankot').updateCustomSensor(1,1)
			--	print (domoticz.devices('Stankot').rawData)
	    	elseif
			(domoticz.devices(14).nValue == 1) then
			domoticz.devices('Stankot').updateCustomSensor(0,0)
		--	print (domoticz.devices('Stankot').rawData)
	    end
	domoticz.openURL({
         url = 'http://127.0.0.1:8086/write?db=domoticz&u=domoticz&p=domoticz&precision=ms',
         method = 'POST',
         headers = 'application/x-www-form-urlencoded',
         callback = 'mycallbackstring',
         postData = 'stankotla value=' .. domoticz.devices(67).state
         
      })
    
end
	if (item.isDevice) then
		if (domoticz.devices(14).nValue == 3) then
			domoticz.devices('Stankot').updateCustomSensor(1,1)
		--	print (domoticz.devices('Stankot').rawData)
			elseif
				(domoticz.devices(14).nValue == 1) then
				domoticz.devices('Stankot').updateCustomSensor(0,0)
			--	print (domoticz.devices('Stankot').rawData)
		end
		domoticz.openURL({
         url = 'http://127.0.0.1:8086/write?db=domoticz&u=domoticz&p=domoticz&precision=ms',
         method = 'POST',
         callback = 'mycallbackstring',
         postData = 'stankotla value=' .. domoticz.devices(67).state
      })

    end 
end
}
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: Dzvent push data to influxdb

Post by Derik »

Dear all..

Someone can explain what i can do with this scripts?

Is this perhaps a solution for my problem:
viewtopic.php?f=6&t=26209&e=1&view=unread#unread

Is it perhaps possible to push multiple dummy devices to Grafana...
I need some option to make in grafana my dummy switches visible.
Because domoticz is not pushmy dummy's into influxDB:

I found this in the wiki:

Code: Select all

Note to Virtual / Dummy sensors: If the HTTP link or MQTT is not sending any values to the database, check the update method of your virtual sensors in your scripts. If using the ['UpdateDevice'] method, you will directly write the value to the internal database without triggering an HTTPlink or MQTT update for this sensor. Better is to use the JSON API of Domoticz and update your virtual sensors this way. 
https://www.domoticz.com/wiki/HttpLink

Only this part i do not understand...
I use this script, and i cannot get it into influxDB:

Code: Select all

local function DeviceUpdate(idx, value1)
    local cmd = string.format("%d|0|%.2f", idx, value1)
  --print(cmd)
    table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end

Debug = "Yes" -- Debugging aanzetten ("YES") of uitzetten ("NO")
 
commandArray = {}
 
local m = os.date('%M')
if (m % 4 == 0) then -- script loopt iedere 4 minuten

-- Variabelen instellen
local temperature_name	= 'D.M.: Gemiddeld Buiten D'
local temperature_idx	= otherdevices_idx[temperature_name]

local uitlees_name	= 'Buiten: Terras'
local uitlees_idx	= otherdevices_idx[uitlees_name]

--Temperaturen van afgelopen 24 uur opvragen
local sQuery			= 'curl "http://192.168.5.70:8080/json.htm?type=graph&sensor=temp&idx='..tostring(uitlees_idx)..'&range=day"'
local handle=assert(io.popen(sQuery))
local raw = handle:read('*all')
handle:close()

--Ontvangen waarden verwerken
json = assert(loadfile '/home/pi/domoticz/scripts/lua/JSON.lua')()
local jsonData = json:decode(raw)

if Debug=='YES' then
  print (jsonData.title)
  print (jsonData.status)
  print (jsonData.result[1].d)
  print (jsonData.result[1].te)
end

--Gemiddelde temperatuur van afgelopen 24 uur bepalen
local sum = 0
local ave = 0
local elements = #jsonData.result
     
for i = 1, elements do
    sum = sum + jsonData.result[i].te
end
     
ave = sum / elements

if Debug=='YES' then
  print('Gemiddeld: '..tostring(ave))
end

--Gemiddelde temperatuur opslaan in virtuele temperatuur sensor
UpdateDevice  --DeviceUpdate(temperature_idx,ave)

end
return commandArray
So i hope someone :-)
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest