Automation - reverting back to a value at the end (like temp., light)

Hi there!

I have a quite good implementation of an up-to-date HA running (for my capabilities and expectations :wink: ), but I am struggeling with one configuration. The issue Hits me especially in the contest of lights automation or heating automation.

Szenario one: Lights in a room are Manager with time triggered automation for example for the daily Routinen. An additional rufe is set for motion detectors - when motion, 100% light for 15 minutes. At the end of the 15 minutes I would like to return to previos state of dimming (or off). Plus: Maybe the light Was from 9:00 to 12:00 at 20%, then at 11:55 motion. How to manage the Situation that the light should be change from 100% to off instead to 20%, as it is always after 12:00 when the automation end?

Szenario two is very similar, but instead of lights it is with thermostats: time automations for certain Temperaturen, overruled by door open contact that are conflicting with the time automations.

Sorry for the simple question, but I am not having a smart idea to handle the simple Tasks…

Is there a way to preserve Status? Variables? How to overrule These in the background?

Maybe somebody has a smart idea here…

Have a great weekend!

First that comes to mind is scene.create, but that is no good for

Not sure if I can follow.

I am using scenes already - presets to set Devices to a certain scenario (like living room 50%). But how would that help?

In my case: Living room is on 50%, motion detector kicks in to 100%. After a certain time I need to get back to what it was before (here 50%), or depending on time and other sensors, to what it is supposed to be now.

something like

- id: '1567689065684'
  alias: Licht badkamer aan
  description: Licht badkamer aan
  trigger:
  - entity_id: binary_sensor.ikeapir_occupancy
    platform: state
    to: 'on'
  action:
  - scene.create 
    data:
      scene_id: my_scene
      entities:
        light.lichtbadkamer
  - data:
      entity_id: light.lichtbadkamer
    service: light.turn_on
  mode: restart

and

- id: '1567689065685'
  alias: Licht badkamer af
  trigger:
  - entity_id: binary_sensor.ikeapir_occupancy
    platform: state
    to: 'off'
    for: 00:00:10
  condition: []
  action:
  - data:
      entity_id: light.lichtbadkamer
    service: light.turn_off
  - service: scene.turn_on
    target:
      entity_id: scene.my_scene