Reading data from Influx DB and to display in a device attribute

I keep some data from my router on my Influx DB.
And I want to get this data to display on my Hubitat dashboard (and possibly then access via a custom Alexa skill) on a custom device.

Influx has a method to read data with http get request.
but it needs a specific format to produce Json.
examples:

 curl -G 'http://localhost:8086/query?db=mydb&pretty=true' --data-urlencode 'q=SELECT * FROM "mymeas"'
curl -G 'http://localhost:8086/query?db=mydb&epoch=s' --data-urlencode 'q=SELECT * FROM "mymeas"'

I know how to make an http get request from my custom device driver. But I don't know how to provide the "data-urlencode" parameter.
Is this possible with " hubitat.device.HubAction" ?

def host = "192.168.254.20" 
def port = "8086"
def hosthex = convertIPtoHex(host).toUpperCase() 
def porthex = convertPortToHex("8086").toUpperCase()    
def path = "/query?db=mydb&epoch=s"
def headers = [:] 
headers.put("HOST", "$host:$port")
def method = "GET"

try {
def hubAction = new hubitat.device.HubAction(
	method: method,
	path: path,
	headers: headers
    )
    sendHubCommand(hubAction)
}
catch (Exception e) {
	log.debug "Hit Exception $e on $hubAction"
}

It might be the query option in the headers I think it is.

I found the solution:

try {
def hubAction = new hubitat.device.HubAction(
	method: "POST",
	path: path,
    body: 'q=select * from "linequality" order by time desc limit 2',
    headers: [
        HOST: "$host:$port",
        "Content-Type": "application/x-www-form-urlencoded"
      ]
    )
    sendHubCommand(hubAction)
}
catch (Exception e) {
	log.debug "Hit Exception $e on $hubAction"
}
1 Like

Download the Hubitat app