I am trying to get it right since hours, but I can’t figure out what is actually the problem. I setup the template sensor as described above. My sensors forecast attribute is looking like this:
[{'datetime': datetime.datetime(2024, 6, 2, 17, 0, tzinfo=datetime.timezone.utc), 'precipitation': None, 'precipitation_probability': None, 'cloudcover_percentage': 100, 'cloudless_percentage': 0, 'cloud_area_fraction': 100, 'cloud_area_fraction_high': 100, 'cloud_area_fraction_medium': 2, 'cloud_area_fraction_low': 21, 'fog_area_fraction': 0, 'seeing_percentage': 75, 'transparency_percentage': 35, 'lifted_index': -4, 'condition': 41, 'precipitation_amount': 0.0, 'calm_percentage': 74, 'wind_speed': 4.2, 'wind_bearing': 'NW', 'temperature': 17.8, 'humidity': 85}, {'datetime': datetime.datetime(2024, 6, 2, 18, 0, tzinfo=datetime.timezone.utc), 'precipitation': None, 'precipitation_probability': None, 'cloudcover_percentage': 100, 'cloudless_percentage': 0, 'cloud_area_fraction': 100, 'cloud_area_fraction_high': 100, 'cloud_area_fraction_medium': 19, 'cloud_area_fraction_low': 44, 'fog_area_fraction': 0, 'seeing_percentage': 65, 'transparency_percentage': 0, 'lifted_index': -1, 'condition': 35, 'precipitation_amount': 0.1, 'calm_percentage': 75, 'wind_speed': 4.1, 'wind_bearing': 'NW', 'temperature': 17.3, 'humidity': 86},..]
When trying to use the apex charts as I used to and as described above, the chart states “loading…”. Is this related to the date being stored as python date format? When I call the service I receive normal datestring, but it looks like storing it as a template saves it in this python date format that js cannot understand.
For completeness, here is the chart I am using, which worked before the update (replaced the entity with my template sensor):
type: custom:apexcharts-card
header:
show: true
title: ApexCharts-Card
show_states: true
colorize_states: true
now:
show: true
graph_span: 48h
span:
start: hour
offset: '-1h'
series:
- entity: sensor.astroweather_hourly_forecast
name: Lifted Index
unit: K
data_generator: |
return entity.attributes.forecast.map((entry) => {
return [new Date(entry.datetime).getTime(), entry.lifted_index];
});
And here is my template sensor:
# Astroweather
- trigger:
- platform: time_pattern
hours: /1
action:
- service: weather.get_forecasts
target:
entity_id:
- weather.astroweather
data:
type: hourly
response_variable: hourly_forecast
sensor:
- name: Astroweather hourly Forecast
unique_id: astroweather_hourly_forecast
state: "{{ now().isoformat() }}"
icon: mdi:hours-24
attributes:
forecast: "{{ hourly_forecast['weather.astroweather']['forecast'] }}"