Set weather.home_hourly.[0].datetime in an automation

Hi

I have a template weather sensor created in configuration.yaml that I update from a met.no integration.

weather:
  - platform: template
    name: MetNO Daily
    condition_template: "{{ states('weather.hjem') }}"
    temperature_template: "{{ state_attr('weather.hjem', 'temperature') | float }}"
    humidity_template: "{{ state_attr('weather.hjem', 'humidity') | float }}"
    attribution_template: "{{ state_attr('weather.hjem', 'attribution') }}"
    pressure_template: "{{ state_attr('weather.hjem', 'pressure') | int }}"
    wind_speed_template: "{{ state_attr('weather.hjem', 'wind_speed') | float }}"
    wind_bearing_template: "{{ state_attr('weather.hjem', 'wind_bearing') | float }}"
    forecast_template: "{{ state_attr('weather.hjem_hourly', 'forecast') }}"

the forecast is a list with the first and last shown below.

[
  {
    "condition": "cloudy",
    "precipitation_probability": 0,
    "datetime": "2022-12-13T11:00:00+00:00",
    "wind_bearing": 118.7,
    "temperature": -5.9,
    "wind_speed": 2.2,
    "precipitation": 0
  },
  {
    "condition": "cloudy",
    "precipitation_probability": 27.1,
    "datetime": "2022-12-14T10:00:00+00:00",
    "wind_bearing": 241.9,
    "temperature": -0.2,
    "wind_speed": 9.7,
    "precipitation": 0
  }
]

I would like to update the datetime, temperature and precipitation of these in an automation. (and is it possible to add / remove the number of items in the forecast list?)

Br
Palle

I dont think it would be possible to change the datetime of the present sensor but there could be another work arround by creating an mqtt sensor, the state and attributes of which can be controlled freely by you. In this case, you can publish the modified values and attriutes of the weather sensor.

Another work around would be to use nodered to modify these values and pass it on to HA using the entity nodes. This would give you more capabilities to modify and simpler.

May I ask why you want to change those values? They are predictions from .no so changing them is then no longer using the same source. If needed, then why not create a separate sensor with dates you can fully control?
Adding to @sheminasalam…you can change with some work but as soon as the integration reconnects, it will update to the .no data.

it is because I am trying to solve this “problem”:

The sensor that I advised to create is independent from the integration and so with nodered or home assistant automation, the states, attributes or when to update and all can be controlled.

[quote=" vingerha, post:3, topic:502191"]
but as soon as the integration reconnects, it will update to the .no data.
[/quote]

I didn’t realize, I thought It was static.

I will look into the mqtt sensor as sheminasalam suggested.
Thanks both :smile:

Br
Palle

I see, then in that case I would do as @sheminasalam copy it e.g. once a day at e/g. midnight

On the side…I myself have another problem with similar challenge. I am trying to compare forecast temperature with actual values and discovered just recently that the data under ‘forecast’ is not historized :frowning: …but let’s not get distracted from your topic

Since you have such broad requirements with the data, I would suggest you to go with node red. It would be simpler in extracting and manipulating data.

So in the end, for my use, comparing actual temp with forecast temp… I am copying the forecast figures every morning at 06:00 to a input_text helper.

Thanks for pointing me in the right direction :smiley:

(another post that also helped me alot: Mqtt sensor - how to load attributes - #6 by 123)

For the solution:
I got the MQTT broker installed and spent a few days working with node-red, but was still using automations from HA, so I skipped node-red because I couldn’t see the advantage?
So I ended up with a MQTT sensor with a forecast attribute that is a list (array) with 47 items, that each has temperature, precipitation and datetime and starts the day with being all blank.
From config.yaml:

mqtt:
  sensor:
    - name: "Vejret"
      unique_id: "MQTT_Sensor_Vejret_2022_12_18"
      state_topic: "outside/weather_sensor"
      value_template: "{{ value_json.state }}"
      json_attributes_topic: "outside/weather_sensor_attr"
      json_attributes_template: >
        { "temperature": {{ value_json.forecast[0].temperature }},
          "temperature": {{ value_json.forecast[1].temperature }},
          "temperature": {{ value_json.forecast[2].temperature }},
          "temperature": {{ value_json.forecast[3].temperature }},
          "temperature": {{ value_json.forecast[4].temperature }},
          "temperature": {{ value_json.forecast[5].temperature }},
          "temperature": {{ value_json.forecast[6].temperature }},
          "temperature": {{ value_json.forecast[7].temperature }},
          "temperature": {{ value_json.forecast[8].temperature }},
          "temperature": {{ value_json.forecast[9].temperature }},
          "temperature": {{ value_json.forecast[10].temperature }},
          "temperature": {{ value_json.forecast[11].temperature }},
          "temperature": {{ value_json.forecast[12].temperature }},
          "temperature": {{ value_json.forecast[13].temperature }},
          "temperature": {{ value_json.forecast[14].temperature }},
          "temperature": {{ value_json.forecast[15].temperature }},
          "temperature": {{ value_json.forecast[16].temperature }},
          "temperature": {{ value_json.forecast[17].temperature }},
          "temperature": {{ value_json.forecast[18].temperature }},
          "temperature": {{ value_json.forecast[19].temperature }},
          "temperature": {{ value_json.forecast[20].temperature }},
          "temperature": {{ value_json.forecast[21].temperature }},
          "temperature": {{ value_json.forecast[22].temperature }},
          "temperature": {{ value_json.forecast[23].temperature }},
          "temperature": {{ value_json.forecast[24].temperature }},
          "temperature": {{ value_json.forecast[25].temperature }},
          "temperature": {{ value_json.forecast[26].temperature }},
          "temperature": {{ value_json.forecast[27].temperature }},
          "temperature": {{ value_json.forecast[28].temperature }},
          "temperature": {{ value_json.forecast[29].temperature }},
          "temperature": {{ value_json.forecast[30].temperature }},
          "temperature": {{ value_json.forecast[31].temperature }},
          "temperature": {{ value_json.forecast[32].temperature }},
          "temperature": {{ value_json.forecast[33].temperature }},
          "temperature": {{ value_json.forecast[34].temperature }},
          "temperature": {{ value_json.forecast[35].temperature }},
          "temperature": {{ value_json.forecast[36].temperature }},
          "temperature": {{ value_json.forecast[37].temperature }},
          "temperature": {{ value_json.forecast[38].temperature }},
          "temperature": {{ value_json.forecast[39].temperature }},
          "temperature": {{ value_json.forecast[40].temperature }},
          "temperature": {{ value_json.forecast[41].temperature }},
          "temperature": {{ value_json.forecast[42].temperature }},
          "temperature": {{ value_json.forecast[43].temperature }},
          "temperature": {{ value_json.forecast[44].temperature }},
          "temperature": {{ value_json.forecast[45].temperature }},
          "temperature": {{ value_json.forecast[46].temperature }},
          "precipitation": {{ value_json.forecast[0].precipitation }},
          "precipitation": {{ value_json.forecast[1].precipitation }},
          "precipitation": {{ value_json.forecast[2].precipitation }},
          "precipitation": {{ value_json.forecast[3].precipitation }},
          "precipitation": {{ value_json.forecast[4].precipitation }},
          "precipitation": {{ value_json.forecast[5].precipitation }},
          "precipitation": {{ value_json.forecast[6].precipitation }},
          "precipitation": {{ value_json.forecast[7].precipitation }},
          "precipitation": {{ value_json.forecast[8].precipitation }},
          "precipitation": {{ value_json.forecast[9].precipitation }},
          "precipitation": {{ value_json.forecast[10].precipitation }},
          "precipitation": {{ value_json.forecast[11].precipitation }},
          "precipitation": {{ value_json.forecast[12].precipitation }},
          "precipitation": {{ value_json.forecast[13].precipitation }},
          "precipitation": {{ value_json.forecast[14].precipitation }},
          "precipitation": {{ value_json.forecast[15].precipitation }},
          "precipitation": {{ value_json.forecast[16].precipitation }},
          "precipitation": {{ value_json.forecast[17].precipitation }},
          "precipitation": {{ value_json.forecast[18].precipitation }},
          "precipitation": {{ value_json.forecast[19].precipitation }},
          "precipitation": {{ value_json.forecast[20].precipitation }},
          "precipitation": {{ value_json.forecast[21].precipitation }},
          "precipitation": {{ value_json.forecast[22].precipitation }},
          "precipitation": {{ value_json.forecast[23].precipitation }},
          "precipitation": {{ value_json.forecast[24].precipitation }},
          "precipitation": {{ value_json.forecast[25].precipitation }},
          "precipitation": {{ value_json.forecast[26].precipitation }},
          "precipitation": {{ value_json.forecast[27].precipitation }},
          "precipitation": {{ value_json.forecast[28].precipitation }},
          "precipitation": {{ value_json.forecast[29].precipitation }},
          "precipitation": {{ value_json.forecast[30].precipitation }},
          "precipitation": {{ value_json.forecast[31].precipitation }},
          "precipitation": {{ value_json.forecast[32].precipitation }},
          "precipitation": {{ value_json.forecast[33].precipitation }},
          "precipitation": {{ value_json.forecast[34].precipitation }},
          "precipitation": {{ value_json.forecast[35].precipitation }},
          "precipitation": {{ value_json.forecast[36].precipitation }},
          "precipitation": {{ value_json.forecast[37].precipitation }},
          "precipitation": {{ value_json.forecast[38].precipitation }},
          "precipitation": {{ value_json.forecast[39].precipitation }},
          "precipitation": {{ value_json.forecast[40].precipitation }},
          "precipitation": {{ value_json.forecast[41].precipitation }},
          "precipitation": {{ value_json.forecast[42].precipitation }},
          "precipitation": {{ value_json.forecast[43].precipitation }},
          "precipitation": {{ value_json.forecast[44].precipitation }},
          "precipitation": {{ value_json.forecast[45].precipitation }},
          "precipitation": {{ value_json.forecast[46].precipitation }},
          "datetime": "{{ value_json.forecast[0].datetime }}", 
          "datetime": "{{ value_json.forecast[1].datetime }}", 
          "datetime": "{{ value_json.forecast[2].datetime }}", 
          "datetime": "{{ value_json.forecast[3].datetime }}", 
          "datetime": "{{ value_json.forecast[4].datetime }}", 
          "datetime": "{{ value_json.forecast[5].datetime }}", 
          "datetime": "{{ value_json.forecast[6].datetime }}", 
          "datetime": "{{ value_json.forecast[7].datetime }}", 
          "datetime": "{{ value_json.forecast[8].datetime }}", 
          "datetime": "{{ value_json.forecast[9].datetime }}", 
          "datetime": "{{ value_json.forecast[10].datetime }}", 
          "datetime": "{{ value_json.forecast[11].datetime }}", 
          "datetime": "{{ value_json.forecast[12].datetime }}", 
          "datetime": "{{ value_json.forecast[13].datetime }}", 
          "datetime": "{{ value_json.forecast[14].datetime }}", 
          "datetime": "{{ value_json.forecast[15].datetime }}", 
          "datetime": "{{ value_json.forecast[16].datetime }}", 
          "datetime": "{{ value_json.forecast[17].datetime }}", 
          "datetime": "{{ value_json.forecast[18].datetime }}", 
          "datetime": "{{ value_json.forecast[19].datetime }}", 
          "datetime": "{{ value_json.forecast[20].datetime }}", 
          "datetime": "{{ value_json.forecast[21].datetime }}", 
          "datetime": "{{ value_json.forecast[22].datetime }}", 
          "datetime": "{{ value_json.forecast[23].datetime }}", 
          "datetime": "{{ value_json.forecast[24].datetime }}", 
          "datetime": "{{ value_json.forecast[25].datetime }}", 
          "datetime": "{{ value_json.forecast[26].datetime }}", 
          "datetime": "{{ value_json.forecast[27].datetime }}", 
          "datetime": "{{ value_json.forecast[28].datetime }}", 
          "datetime": "{{ value_json.forecast[29].datetime }}", 
          "datetime": "{{ value_json.forecast[30].datetime }}", 
          "datetime": "{{ value_json.forecast[31].datetime }}", 
          "datetime": "{{ value_json.forecast[32].datetime }}", 
          "datetime": "{{ value_json.forecast[33].datetime }}", 
          "datetime": "{{ value_json.forecast[34].datetime }}", 
          "datetime": "{{ value_json.forecast[35].datetime }}", 
          "datetime": "{{ value_json.forecast[36].datetime }}", 
          "datetime": "{{ value_json.forecast[37].datetime }}", 
          "datetime": "{{ value_json.forecast[38].datetime }}", 
          "datetime": "{{ value_json.forecast[39].datetime }}", 
          "datetime": "{{ value_json.forecast[40].datetime }}", 
          "datetime": "{{ value_json.forecast[41].datetime }}", 
          "datetime": "{{ value_json.forecast[42].datetime }}", 
          "datetime": "{{ value_json.forecast[43].datetime }}", 
          "datetime": "{{ value_json.forecast[44].datetime }}", 
          "datetime": "{{ value_json.forecast[45].datetime }}", 
          "datetime": "{{ value_json.forecast[46].datetime }}"  }

Then I have made 24 automations that trigger on state change on the original weather sensor (that only has 24h of weather data that updates hourly) with a condition on the time (between 00-01, 01-02 and so on)

The automation action is a MQTT: Publish with the following code: (this is the 00-01 automation)

service: mqtt.publish
data:
  topic: outside/weather_sensor_attr
  qos: "1"
  payload: |-
    { 
      "forecast" : [
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').0.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').0.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').0.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').1.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').1.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').1.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').2.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').2.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').2.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').3.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').3.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').3.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').4.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').4.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').4.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').5.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').5.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').5.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').6.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').6.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').6.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').7.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').7.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').7.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').8.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').8.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').8.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').9.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').9.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').9.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').10.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').10.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').10.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').11.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').11.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').11.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').12.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').12.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').12.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').13.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').13.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').13.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').14.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').14.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').14.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').15.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').15.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').15.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').16.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').16.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').16.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').17.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').17.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').17.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').18.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').18.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').18.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').19.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').19.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').19.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').20.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').20.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').20.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').21.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').21.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').21.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').22.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').22.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').22.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').23.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').23.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').23.datetime }}"
        }
       ]
    }

For the automations that trigger later (e.g. 08-09) I added the values from the sensor that recieves the update in the first positions that is the “historical” list (array) positions.
So the 08-09 automation looks like this:

service: mqtt.publish
data:
  topic: outside/weather_sensor_attr
  qos: "1"
  payload: |-
    { 
      "forecast" : [
        {
          "temperature" : {{ state_attr('sensor.vejret', 'forecast').0.temperature }},
          "precipitation" : {{ state_attr('sensor.vejret', 'forecast').0.precipitation }}, 
          "datetime" : "{{ state_attr('sensor.vejret', 'forecast').0.datetime }}"
        },
        {
          "temperature" : {{ state_attr('sensor.vejret', 'forecast').1.temperature }},
          "precipitation" : {{ state_attr('sensor.vejret', 'forecast').1.precipitation }}, 
          "datetime" : "{{ state_attr('sensor.vejret', 'forecast').1.datetime }}"
        },
        {
          "temperature" : {{ state_attr('sensor.vejret', 'forecast').2.temperature }},
          "precipitation" : {{ state_attr('sensor.vejret', 'forecast').2.precipitation }}, 
          "datetime" : "{{ state_attr('sensor.vejret', 'forecast').2.datetime }}"
        },
        {
          "temperature" : {{ state_attr('sensor.vejret', 'forecast').3.temperature }},
          "precipitation" : {{ state_attr('sensor.vejret', 'forecast').3.precipitation }}, 
          "datetime" : "{{ state_attr('sensor.vejret', 'forecast').3.datetime }}"
        },
        {
          "temperature" : {{ state_attr('sensor.vejret', 'forecast').4.temperature }},
          "precipitation" : {{ state_attr('sensor.vejret', 'forecast').4.precipitation }}, 
          "datetime" : "{{ state_attr('sensor.vejret', 'forecast').4.datetime }}"
        },
        {
          "temperature" : {{ state_attr('sensor.vejret', 'forecast').5.temperature }},
          "precipitation" : {{ state_attr('sensor.vejret', 'forecast').5.precipitation }}, 
          "datetime" : "{{ state_attr('sensor.vejret', 'forecast').5.datetime }}"
        },
        {
          "temperature" : {{ state_attr('sensor.vejret', 'forecast').6.temperature }},
          "precipitation" : {{ state_attr('sensor.vejret', 'forecast').6.precipitation }}, 
          "datetime" : "{{ state_attr('sensor.vejret', 'forecast').6.datetime }}"
        },
        {
          "temperature" : {{ state_attr('sensor.vejret', 'forecast').7.temperature }},
          "precipitation" : {{ state_attr('sensor.vejret', 'forecast').7.precipitation }}, 
          "datetime" : "{{ state_attr('sensor.vejret', 'forecast').7.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').0.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').0.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').0.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').1.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').1.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').1.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').2.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').2.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').2.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').3.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').3.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').3.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').4.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').4.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').4.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').5.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').5.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').5.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').6.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').6.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').6.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').7.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').7.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').7.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').8.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').8.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').8.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').9.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').9.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').9.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').10.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').10.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').10.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').11.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').11.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').11.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').12.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').12.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').12.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').13.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').13.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').13.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').14.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').14.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').14.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').15.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').15.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').15.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').16.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').16.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').16.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').17.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').17.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').17.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').18.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').18.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').18.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').19.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').19.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').19.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').20.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').20.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').20.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').21.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').21.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').21.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').22.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').22.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').22.datetime }}"
        },
        {
          "temperature" : {{state_attr('weather.hjem_hourly', 'forecast').23.temperature }},
          "precipitation" : {{state_attr('weather.hjem_hourly', 'forecast').23.precipitation }}, 
          "datetime" : "{{state_attr('weather.hjem_hourly', 'forecast').23.datetime }}"
        }
       ]
    }

Finally, every day just before i load the first data, I delete the sensor data.