What can be set with a state set?

Summary: I can create entities by forcefully setting their state and attributes. I do not know how to force a unique ID though. An example of attributes would be

        "icon": "mdi:web", 
        "name": f"monitoring something",
        "object_id": "hksdjlhfsdkjfhqdskjhfnbd",
        "unique_id": "kjljlkjlkjlkjlkj"
        "id": "lkjlkjlkjlkjlkjklj"

The entity is created and its icon is indeed mdi:web.


  • "name": f"monitoring something", is not taken into account → I can live with that
  • there is no unique ID for that entity, despite an attempt to push one via the three last entries

This means the status can’t be edited via the UI, and I would like to know why:

  • is this because the entity ID cannot be set that way
  • or whether I am setting it wrong
  • or something else?

EDIT: I found an old question of mine where I mentioned that I can create an almost working entity via MQTT discovery:

        payload = json.dumps({
            "icon": "mdi:web", 
            "name": f"monitoring {endpoint_name}",
            "state_topic": f'homeassistant/binary_sensor/{endpoint_name}/state',
            "object_id": endpoint_name,
            "unique_id": endpoint_name

I thought initially that setting the state would not be able to set anything else than, well, the state (and creation of the entity). But somehow the icon can be set as well via the attributes.

Note: this issue appeared when I was setting entities via pyscript but th problem is with the creation itself (it is the same in pyscript and in the dev tools.