Set schedule via API

I have read these instructions how to set a state via API, but cannot manage to set a next even attribute to a schedule item in homeassistant.
So I have an “schedule.akku_laden” and want to set the attribute “next_event”.

I tried this code in python:

def set_battery_next_event(self):
        data = {"attributes": {"next_event" : "2025-01-08T16:00:00+01:00"}}
        item= "schedule.akku_laden"
        self.set_state(item, data)
        
    
def set_state(self, item, data):
        url = self.url_start + item
        
        try:
            response = post(url, headers=self.headers, json=data)
            print(response.text)
        except Exception as e:
            print('Message from HA was: ',e)
            print('did not get valid response from homeassistant for: ', item)

but it gave me the error: “no state specified”. I dont want to set at state as this might set the state for the current time. I just want to change the attribute.


python ha_connection.py
{"message":"No state specified."}

If I set a state just as I have to, I get this answer:

python ha_connection.py
{“entity_id”:“schedule.akku_laden”,“state”:“25”,“attributes”:{“next_event”:“2025-01-08T16:00:00+01:00”},“last_changed”:“2025-01-08T09:02:34.053372+00:00”,“last_reported”:“2025-01-08T09:04:17.623978+00:00”,“last_updated”:“2025-01-08T09:04:17.623978+00:00”,“context”:{“id”:“01JH2JGM6QYSHB9HAN0283NZDE”,“parent_id”:null,“user_id”:“ba53fb6a5e1444e9abc54ebd7f6c62ec”}}
set event None

But the object in HA is not adapted.

How can I set the attribute properly?

The next_event attribute is defined by the contents of the schedule. Why would you expect to be able to override that? A schedule is AFAIK not meant to be updated programmatically, they can only be edited in the UI or through YAML (depending on how it was initially defined).

If you want to programmatically store and update a date, you should use an input_datetime helper rather than a schedule. Or if you need to keep track of multiple dates use a calendar integration.