How to calculate with Influxdb Interface?

Hello!

We are trying to calculate a specific value but it doesn’t work. Our data gives us an accumulated value which we want to manipulate to only show data with todays timestamp. But we need yesterdays data to be subtracted or the first value of today set to 0. Both ways would work.
So basically we are trying to show todays energy consumption. Therefore we need to display the difference between the current value and the first of the day.

Example:

value = value.rightnow - value.atMidnight

Our implementation:

from(bucket: "ecobucket")
  |> range(start: today())
  |> filter(fn: (r) => r["_measurement"] == "mqtt_consumer")
  |> filter(fn: (r) => r["_field"] == "ENERGY_Today")
  |> filter(fn: (r) => r["host"] == "telegraf")
  |> filter(fn: (r) => r["topic"] == "PowerMeter/001/power/SENSOR")
  |> map(fn: (r) => ({ r with _value: r._value - r._value.today() }))
  |> yield(name: "last")

Thank you!

@anonym I am not clear on the way the map function is written in your query.
today() function returns timestamp truncated to the day unit. So I am not clear the way it is called on _value.
Could you please let me know what does _value stores? Sending some sample records would be useful here.