Apps Code, where do you run it?

Try just replaceAll (drop java.lang.Long)

1 Like

@michaelahess Did you get this working?

I am guessing this is where it’s failing but not sure why

private escapeStringForInfluxDB(str) {
    if (str) {
        str = str.replaceAll(" ", "\\\\ ") // Escape spaces.
        str = str.replaceAll(",", "\\\\,") // Escape commas.
        str = str.replaceAll("=", "\\\\=") // Escape equal signs.
        str = str.replaceAll("\"", "\\\\\"") // Escape double quotes.
        //str = str.replaceAll("'", "_")  // Replace apostrophes with underscores.
    }
    else {
        str = 'null'
    }
    return str
}

Have not yet had time to dig into this. I haven’t tried Mike’s recommendation, but will attempt to do so tonight.

I’m failing on this, now I don’t get any logging responses at all after changing the str.replaceAll to just replaceAll.

It will take someone smarter than me to work this out. Not that I’m surprised. :slight_smile:

I was able to get it the code to save and correct the issues you were encountering by adding
.toString()
for the following lines:
def deviceId = escapeStringForInfluxDB(evt.deviceId.toString())
def hubId = escapeStringForInfluxDB(evt?.device.device.hubId.toString())
def locationId = escapeStringForInfluxDB(location.id.toString())
I no longer receive the errors but it does not appear to be saving to my InfluxDB as I have no series, tag or field keys.

It also doesn’t appear to be trying to send loging or polling updates so I imagine there is quite a bit that needs to be refined and will take more time once I can digest but thought I would keep you moving forward.

1 Like

Oh nice, getting so close! Here’s ST output followed by Hubitat output:

Influx Logging: postToInfluxDB(): Posting data to InfluxDB: Host: 10.54.25.66, Port: 8086, Database: SmartThings, Data: [power,deviceId=77684a62-1409-48ec-996c-720ef409097e,deviceName=Energy\ Meter,groupId=a2a60898-3778-4909-959f-dfdcf2937946,groupName=Garage,hubId=32ba9767-966c-4237-bfae-67d851678415,hubName=Home\ Hub,locationId=c2b9ade5-a7ce-46c0-9c0e-8ac1d2e6df23,locationName=Home,unit=W value=1056.880]

InfluxDB Logger: postToInfluxDB(): Posting data to InfluxDB: Host: 10.54.25.66, Port: 8086, Database: Hubitat, Data: [power,deviceId=12,deviceName=MO\ Work\ Office\ Outlet,groupId=null,groupName=Home,hubId=1,hubName=com.hubitat.hub.domain.Hub@3281603b,locationId=1,locationName=Home,unit=null value=2.8] 

My new DB is also not seeing anything actually going to it though. I’ve changed it to my ST DB and should be able to see it quickly if anything comes through to rule out my DB config.

Influxdb is sending back a 204 response code but data is not writing. From what I quickly found it may be related to the timestamp formatting. That’s where I am focused now to see what timestamp is being sent w/ the measurement.

I was thinking something to do with the null unit attribute. After seeing how many references exist to pull the unit for each device type, my eyes and neurons just crossed.

No timestamp is being tagged on it is using it on insert…

I can copy and paste the data string that is being produced and logged and have it insert successfully via the CLI and Curl, just not from Hubitat…

Log data:
[switch,deviceId=9,deviceName=Hubduino\ switch5,groupId=null,groupName=Home,hubId=1,hubName=com.hubitat.hub.domain.Hub@ XYSLEc,locationId=1,locationName=Home,unit=switch value="off",valueBinary=0i]

Curl succeeds too:
curl -i -XPOST 'http://1.1.1.1:8086/write?db=Hubitat' --data-binary 'switch,deviceId=9,deviceName=Hubduino\ switch5,groupId=null,groupName=Home,hubId=1,hubName=com.hubitat.hub.domain.Hub@ XYSLEc,locationId=1,locationName=Home,unit=switch value="off",valueBinary=0i'

Result:
HTTP/1.1 204 No Content
Content-Type: application/json
Request-Id: 5fa56b8c-1086-11e8-86bd-000000000000
X-Influxdb-Build: OSS
X-Influxdb-Version: v1.4.3
X-Request-Id: 5fa56b8c-1086-11e8-86bd-000000000000
Date: Tue, 13 Feb 2018 06:23:15 GMT

Insert for influx:
insert switch,deviceId=9,deviceName=Hubduino\ switch5,groupId=null,groupName=Home,hubId=1,hubName=com.hubitat.hub.domain.Hub@XYSLEc,locationId=1,locationName=Home,unit=switch value="off",valueBinary=0i

Show measurements:
name
----
switch

Progress… I uncommented the code to submit a post action and it writes (I can see it in the database); however, each entry logs an error in Hubitat…
postToInfluxDB(): Something went wrong when posting: java.lang.IllegalArgumentException: Response does not contain data
Commenting out this line as the content type is throwing an error
log.debug "Response contentType: ${response.contentType}"
So it appears to be working but not as intended completely and I’m sure there are plenty of other issues to address - much better people out there more qualified than I to fumble through…

1 Like

Still getting this error

2018-02-16 10:35:22.218:errorlogSystemProperties(): Unable to log Hub properties: groovy.lang.MissingMethodException: No signature of method: java.lang.Long.replaceAll() is applicable for argument types: (java.lang.String, java.lang.String) values: [ , \ ]

Update: I ended up commenting out the entire logging of the HUB Properties since most of those does not exist for Hubitat.

That is because a property in hubitat is a number where was a string in ST. Add a.toString to the hub property before parsing to function.

Are you using the version I have ported over and posted on GitHub?

https://community.hubitat.com/t/compatible-devices-list/113/84?u=lehighkid

Yup. It’s working but some of the hub properties does not exist in hubitat hence the error. Just toggle the setting to not collect hub properties.

Here are the commands to get most of the hub properties…

def hub = location.hubs[0]
log.debug "id: ${hub.id}"
log.debug "zigbeeId: ${hub.zigbeeId}"
log.debug "zigbeeEui: ${hub.zigbeeEui}"
log.debug "type: ${hub.type}"
log.debug “name: ${hub.name}”
//note change to these two calls for IP and Port information
log.debug "localIP: ${hub.getDataValue(“localIP”)}"
log.debug “localSrvPortTCP: ${hub.getDataValue(“localSrvPortTCP”)}”

Have you guys had luck with this doing Temp/Energy/Contact? None of those are forwarding to my database.

Hey, yesterday my temperature sensors (but nothing else) stopped reporting to the InfluxDB. At first I thought it was a problem with the ESP8266 setup I'm using for this and it took my a looong time to figure out the real problem.
At least for me, the InfluxDB logger app logged a unique "hubName" for every entry. There is a standard config in Influx (which can be changed) that limits the unique tag values (not "value values") to 100,000. As every temperature reading created a unique hubName, the whole thing crapped out after 100,000 readings.

I don't know why this is happening, but I simply set the hubName to "Home Hub" permanently in the app code.
Maybe my experience helps someone else.


2 Likes

Is this working for people? I’m not logging anything to my bd, is there a link to the latest code with the fixes?

I just got this working. I had to remove a ".encodeAsBase64().toString()" on line 761 and now everything is reporting. Hope this helps.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.