Apps Code, where do you run it?

Maybe an Apps category should be created?

I've dumped my influxDB Logger (codersaur's) into the Apps Code and updated a single line (746 to hubitat.device.HubAction) and it saved ok. But where do I run it?

Go to the apps page, then load new app, it should be at the bottom of the list. After installing it, it will show in the apps page.

3 Likes

Oh wow, and I did that for devices. DUH, sorry sir!

Lol, that’s what we’re here for!

1 Like

The app see’s my events but fails to process them. It tells me line null so no idea what to look for:

app:142018-02-03 19:03:10.017:errorNo signature of method: java.lang.Long.replaceAll() is applicable for argument types: (java.lang.String, java.lang.String) values: [ , \\ ] on line null
app:142018-02-03 19:03:09.980:debugInfluxDB Logger: handleEvent(): Work Office Outlet(power:null) 11.9
app:142018-02-03 19:03:06.336:errorNo signature of method: java.lang.Long.replaceAll() is applicable for argument types: (java.lang.String, java.lang.String) values: [ , \\ ] on line null
app:142018-02-03 19:03:06.306:debugInfluxDB Logger: handleEvent(): Work Office Outlet(power:null) 2.8
app:142018-02-03 19:02:59.829:errorNo signature of method: java.lang.Long.replaceAll() is applicable for argument types: (java.lang.String, java.lang.String) values: [ , \\ ] on line null
app:142018-02-03 19:02:59.812:debugInfluxDB Logger: handleEvent(): Work Office Outlet(power:null) 0

I see the replaceall thing used to cleanup the data before sending, it’s str = str.replaceall

Might it be a simple command that replaces that?

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?

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”)}”