Future day/night visualisation in a apex-charts

For the past, I use a sensor.day_night to show the night-period in a apex chart. But how can I show the night period in future in the chart?

The grey block is the night period (from sunset to sunrise)

- entity: sensor.day_night
    curve: stepline
    type: area
    transform: "return x === 'Day' ? 0 : 30 ;"
    color: grey
    stroke_width: 0
    opacity: 0.3
    show:
      in_header: false
      legend_value: false

image

Hi,

i was on same track for visualization of dynamic energy prices.

My solution (that works) uses the “sunpower” forecast of a German weather forecast (DWD). I transformed every forecast with sunpower > 0 to zero and everything else to max of my graph.

entity: sensor.wetter_sonneneinstrahlung_2
type: area
color: lightgray
show:
in_chart: true
data_generator: |
return entity.attributes.data.map((entry) => {
return [new Date(entry.datetime).getTime(), entry.value > 0 ? 0 : 50];
});
show:
header_color_threshold: true

Works out like this

Hope that helps

interesting approach, but for my situation it’s not possible because I don’t live in Germany (so DWD is not availiabe).

In my openweather forecast I don’t have a sunpower and I think the sunpower value isn’t similar with the sunset/sunrise, or? (and what’s happen on foggy days?)

You could try to use UV index in OWM or a solar forecast. Both match sunrise/sunset quite good (±30min). For a visualization this should be precise enough.

sensor.openweathermap_uv_index

grafik

but it’s not working?

- entity: sensor.openweathermap_uv_index
    type: area
    color: grey
    opacity: 0.3
    stroke_width: 2
    data_generator: |
      return [new Date(entry.datetime).getTime(), entry.value > 0 ? 0 : 30];
      });

Hey,
i think you are running in a problem with the new service get_forecasts thing. At least my OpenWeatherMap Sensor don’t include any forecasts any more and you will need a template sensor:
https://community.home-assistant.io/t/met-no-hourly-forecast-entity-not-available-in-latest-ha/616504/11?u=felixm

Alternativly we have to create a template sensor relying on sunset and sunrise…