How to automatically update entity that is created programatically?
Not really. To figure out if an entity exists, you have to check that somehow.

If you're trying to optimize, you could run an entity query instead of loading it completely. But in case you want to update, you need to load the original entity anyway, so just do that.

$entity = SomeEntity::load(['my_id' =&gt; 'id123']);
if (!$entity) {
  $entity = SomeEntity::create(['my_id' =&gt; 'id123']);
}
$entity-&gt;save();