Can anyone suggest why the following rule doesn’t work:
rule "Store usage for day with timestamp at start of day"
when
Item electricityTestInfluxDBUpdateSwitch received update
then
logWarn("dev", "InfluxDB test rule starting...")
if (influxWriteTimer === null) {
val Number epochThisMorning = now.withTimeAtStartOfDay().millis / 1000
logWarn("dev", "InfluxDB test rule timestamp = (" + epochThisMorning + ").")
influxWriteTimer = createTimer(now, [|
sendHttpPostRequest(INFLUXDB_WRITE, "application/json", "electricityTestInfluxDBUpdate value=30 " + epochThisMorning, 3000)
// sendHttpPostRequest(INFLUXDB_WRITE, "application/json", "electricityTestInfluxDBUpdate value=30 ", 3000)
influxWriteTimer = null
])
} else {
logWarn("dev", "Influx write timer is still running, not creating another")
}
end
My understanding of the InfluxDB documentation is that to specify a timestamp you add an epoch time after the “value=X” statement. However, if I try that then no data is written to InfluxDB. If I remove the timestamp statement (as shown in the commented out httppost above) then the value of 30 is written to InfluxDB with a timestamp of the current time. So, I’m part way to a solution.
Could the trailing space at the end of the "value=30 " be being stripped out so the “30” and the epoch time are being concatenated? Or have I misunderstood the documentation?