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…

I have a forecast sensor which includes the hourly forecast data from openweathermap.

Example (Attributes):

forecast: 
- datetime: '2024-11-01T18:00:00+00:00'
  condition: cloudy
  temperature: 7.7
  pressure: 1025
  cloud_coverage: 91
  wind_speed: 7.31
  wind_bearing: 292
  uv_index: 0
  precipitation_probability: 0
  precipitation: 0
  apparent_temperature: 6.5
  dew_point: 7
  wind_gust_speed: 7.42
  humidity: 95

I think the uv_index would be fine…but can I bring this forecast into the apex chart as a stepline curve?