Automation based on email subject

I am trying to automatically reset a doorbell camera after it hangs. This happens regularly unfortunately, that is why I want to automate it.
The doorbell camera rtsp stream is recorded on my NVR, and the NVR sends an email upon detection of video loss.
I am using the following code to check if an e-mail with the right subject arrives:

sensor:
  - platform: imap_email_content
    server: imap.bla.com
    port: 993
    username: [email protected]
    password: mail_pw
    folder: INBOX
    senders:
      - [email protected]
    name: videoloss_doorbird
    value_template: >-
      {% if 'NVR: Video Signal Lost On Channel D12' in subject %}
        true
      {% else %}
        false
      {% endif %}

So based on the sensor turning true, I could create an automation:

alias: Reset Doorbird after Video Loss
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.videoloss_doorbird
    from: "false"
    to: "true"
condition: []
action:
  - service: rest_command.restart_doorbird
    data: {}
mode: single

and

rest_command:
  restart_doorbird:
    url:"http://user:[email protected]/bha-api/restart.cgi"

but that would only work once (or until a mail with a different subject arrives, but in this case that does not happen, as it is a dedicated mail account). I would want to add an action to the automation and reset the sensor to false, but since a sensor is read-only, I cannot do that.
How should I proceed here?
I am relatively new to HA, so please be gentle on me :confused:

BTW: this is a workaround for the missing Video Loss signal in the Hikvision Binary Sensor integration:
https://community.home-assistant.io/t/add-video-loss-to-hikvision-binary-sensor/554450

I found a way how it can be done, and created the following automation, using the IMAP Integration (that is a different integration than the one in the code above!):

alias: Reset Doorbird after Video Loss
description: Reset Doorbird after Video Loss
trigger:
  - platform: event
    event_type: imap_content
    id: custom_event
    event_data: {}
condition:
  - condition: template
    value_template: >-
      {{ ( as_timestamp(now()) -
      as_timestamp(state_attr('automation.reset_doorbird_after_video_loss_2',
      'last_triggered')) |int(0) ) > 200 }}
  - condition: template
    value_template: "{{ 'Video Signal Lost On Channel D12' in trigger.event.data.subject }}"
action:
  - delay: "00:02:00"
  - service: rest_command.restart_doorbird
    data: {}
mode: single

The 2 minute delay before the action is executed is because I am currently not sure if someone ringing the doorbell will result in videoloss (the device may only allow one client at the time), and I do not want to reset it while talking to someone at the gate. I may remove this in case it turns out to not cause a video loss.

The 200s dead time is to prevent that the automation creates its own starting condition: the reset action in itself causes the video to be interrupted, and may therefore trigger another ‘video loss email’ from my NVR. I also found out the NVR sends an email every minute while there is no video, so the automation may already have executed the reset action of the DoorBird while there is still an email on it’s way.