Automation using last changed time for ligths

I have an automation in a Shelly device to turn on hue device on switch pressed.
I wanted to do an automation like this

On switch pressed do a ligth toogle but with two conditions.
If ligth was off for X time turn on with some scene and in other case simply toogle.

Thanks for your help

You could create a binary template sensor that triggers to “on” when the light has been off for ‘x’ minutes, and then “off” when the light is not off. Then in your automation, check the state of this binary sensor, and do the appropriate action.

Hi! I have been trying to do it but I’m not an expert on templates. It’s first time trying that.
I have try with the template editor doing a trigger template but the template editor I think that dos not work with triggers.

With regards,

Would the automation choose action fit to your needs?

trigger: []
condition: []
  - choose:
      - conditions:
          - condition: state
            entity_id: light.xy
            state: "off"
              hours: 0
              minutes: 10
              seconds: 0
          - service: light.turn_on
              entity_id: light.xy
      - service: light.toggle
          entity_id: light.flur

Instead of light.turn on you also can select a scene.