Automation using last changed time for ligths

Hi,
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: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: light.xy
            state: "off"
            for:
              hours: 0
              minutes: 10
              seconds: 0
        sequence:
          - service: light.turn_on
            data: 
               …
               …
            target:
              entity_id: light.xy
    default:
      - service: light.toggle
        target:
          entity_id: light.flur

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