I have an item which represents the power consumption yesterday. Because of that, the time stamp in InfluxDB is not correct. (E.g., the power consumption of July 16 has the timestamp July 17, 2am). Since I didn’t find a way to move the data in a chart page by one day, I want to create an item representing the power consumption with a corrected date.
Here an example. On July 17 at 2am openhab receives the value “power consumption yesterday”. This value should be stored to the item “power consumption corrected” in InfluxDB with the time stamp July 16, 12 o’clock noon.
My approach is to do this daily by a rule. But I didn’t find a way to write data to influxdb with a specific date and time by a rule. I know this can be done by command line in the influx console with the “insert” command, but I didn’t find a way to do this in an openhab rule. Is there a possibility to do this?
Thanks a lot for your help! @glhopital: That looks very interesting, but it seems it is only working with InfluxDB v2.0 and not v1.8 which I’m still using. @Wolfgang_S: Thanks for the hint. I figured out how to write value and time stamp by using the curl command. I can do that by e.g. curl -i -XPOST 'http://localhost:8086/write?u=USER&p=PASSWORD&db=DATABASE' --data-binary 'item_corrected value=10 1658163599945000000'.
But I’m still struggling how to do that in the openhab rule. I assumed best way is to use the http binding. But I didn’t manage to pass the --data-binary correctly.
I tried the following syntax but it is not working. val output = sendHttpPostRequest('http://localhost:8086/write?u=USER&p=PASSWORD&db=DATABASE',"application/octet-string", 'item_corrected value=10 1658163599945000000', 8000)
With regard to the http binding I am not that well experienced . …
But what is the content of ( val ) output ? Shouldn’t that contain information about the error in case somethign is wrong ? Does it report success or a problem ? Is there any information in the influxdb log files that could help ?
Great thanks. That works, here my final command: val input = executeCommandLine(Duration.ofSeconds(5), "curl", "-i", "-XPOST", "http://localhost:8086/write?u=USER&p=PASSWORD&db=DATABASE", "--data-binary", "item_corrected value=10 1658163599945000000" )