@@ -429,6 +429,73 @@ def scene(self, name: str) -> Scene:
429429
430430 return self ._get_or_create ("scene" , name , _Scene )
431431
432+ async def create_scene (
433+ self ,
434+ scene_id : str ,
435+ entities : dict [str , dict [str , Any ]],
436+ * ,
437+ snapshot_entities : list [str ] | None = None ,
438+ ) -> Scene :
439+ """Create a dynamic scene and return the `Scene` object.
440+
441+ This calls the ``scene.create`` service, which creates (or updates)
442+ a scene at runtime. The resulting scene can later be deleted with
443+ `Scene.delete`.
444+
445+ Parameters
446+ ----------
447+ scene_id : str
448+ The object-id for the new scene (e.g. ``"romantic"`` becomes
449+ ``scene.romantic``).
450+ entities : dict[str, dict[str, Any]]
451+ Mapping of entity IDs to the state/attribute dicts that the
452+ scene should apply. For example::
453+
454+ {"light.ceiling": {"state": "on", "brightness": 120}}
455+ snapshot_entities : list of str or None, optional
456+ Entity IDs whose **current** state should be captured into
457+ the scene instead of using explicit values.
458+
459+ Returns
460+ -------
461+ Scene
462+ The newly created (or updated) `Scene` instance.
463+ """
464+ from .domains .scene import Scene as _Scene
465+
466+ data : dict [str , Any ] = {
467+ "scene_id" : scene_id ,
468+ "entities" : entities ,
469+ }
470+ if snapshot_entities is not None :
471+ data ["snapshot_entities" ] = snapshot_entities
472+
473+ await self ._call_service ("scene" , "create" , data )
474+ return self ._get_or_create ("scene" , scene_id , _Scene )
475+
476+ async def apply_scene (
477+ self ,
478+ entities : dict [str , dict [str , Any ]],
479+ * ,
480+ transition : float | None = None ,
481+ ) -> None :
482+ """Apply entity states without creating a persistent scene.
483+
484+ This calls the ``scene.apply`` service. It works like activating
485+ a scene, but the state combination is not saved.
486+
487+ Parameters
488+ ----------
489+ entities : dict[str, dict[str, Any]]
490+ Mapping of entity IDs to desired state/attribute dicts.
491+ transition : float or None, optional
492+ Transition time in seconds for entities that support it.
493+ """
494+ data : dict [str , Any ] = {"entities" : entities }
495+ if transition is not None :
496+ data ["transition" ] = transition
497+ await self ._call_service ("scene" , "apply" , data )
498+
432499 def timer (self , name : str | None = None , * , persistent : bool = False ) -> Timer :
433500 """Return a `Timer`, creating the Python object if needed.
434501
0 commit comments