Tracking Home Office Hours with Google Calendar

Hi everyone, I’m new to Home Assistant and I’m trying to set up an automation to track my home office hours using Google Calendar. I’ve got a setup with a binary sensor that pings my work laptop to detect when it’s online. Right now, I can create a calendar entry when the laptop connects, but it only lasts for 5 minutes. I want it to start when the laptop goes online and end when it goes offline. Here’s what my current configuration looks like:

Configuration.yaml
yaml
binary_sensor:

  • platform: ping
    host: 192.168.x.x
    name: “PING”
    count: 2
    scan_interval: 30

Automation.yaml
yaml

  • id: ‘xxxx’
    alias: create a google calendar event when the notebook is online
    trigger:
    • platform: state
      entity_id: binary_sensor.ping
      to: ‘on’
      action:
    • service: google.add_event
      data:
      calendar_id: xxxx
      summary: Homeoffice
      data_template:
      start_date_time: “{{ now().timestamp() | timestamp_custom(‘%Y-%m-%d %H:%M:%S’, true) }}”
      end_date_time: “{{ (now().timestamp() + 300) | timestamp_custom(‘%Y-%m-%d %H:%M:%S’, true) }}”

I’m not sure how to make the event last until the laptop goes offline. Any tips or advice would be really helpful! Thanks in advance!