# How can I use sunrise / sunset time dynamically?

Hi,
the graph shows a cumulative kWh value over the day. The value is set to 0 at 0:00 each night. I calculate the kWh each day in a time period from 10:00-16:00. Because the cumulative value already summed up by the sensor, I calculate a delta (16:00 value minus 10:00 value).

Question: How can I calculate the result more dynamically with day time values (sunrise/sunset) which I have in a separate table.

``````import "timezone"
option location = timezone.location(name: "Europe/Berlin")

data1 = from(bucket: "homey-downsample")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "Wattcher")
|> filter(fn: (r) => r["_field"] == "meter_power")
until_16 = data1
|> hourSelection(start: 16, stop: 16)
|> aggregateWindow(every: 1d, offset: -1s, fn: first, createEmpty: false)
|> set(key: "_field", value: "_16")
until_10 = data1
|> hourSelection(start: 10, stop: 10)
|> aggregateWindow(every: 1d, offset: -1s, fn: first, createEmpty: false)
|> set(key: "_field", value: "_10")
union(tables: [until_16, until_10])
|> group()
|> pivot(rowKey: ["_time"], columnKey: ["_field"], valueColumn: "_value")
|> map(fn: (r) => ({time: r._time, kWh_10_16: float(v: if exists r._16 and exists r._10 then r._16-r._10 else 0.0)}),)
``````

must be dynamically modified:
hourSelection(start: 16, stop: 16)
hourSelection(start: 10, stop: 10)

Table with sensor data:

Table with sunrise data:

I am a newbie with flux, thx for your help!