Sleep automation for Fire TV

Hi,
I wanted to create an automation which automatically turns off my Fire TV after a certain time e.g. 30 minutes.
First I created an helper of type toggle. When I change the state to on I want the automation to start a countdown. After that it should check whether the switch was turned off by then or maybe I will change that to parallell. If the virtual switch is in state off, the automation should stop.
But if the switch is in state on the scene “turn off TV” will be executed. This should turn off the Fire TV.
After this the virtual switch on my dashboard should reset itself to off.

My questions are:

  • Has anyone setup something similar already?
  • Is there a way to set the state of a helper from an automation?
  • How should I save a state like “Timer is reached”?

Thanks for all your comments.

You could work with 3 triggers


trigger:
  - platform: state
    entity_id:
      - input_boolean.xy
    from: "off"
    to: "on"
    id: start

  - platform: state
    entity_id:
      - input_boolean.xy
    from: "on"
    to: "off"
    id: cancel

  - platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.abc
    id: end

and 3 choose actions depending on trigger.id.