Google Calender - Automation - Homeoffice Tracking

Hello Everybody,

I’m new to Home-Assistant and started to learn automations.
I want to track my homeoffice activity with a complete google-calendar entry, day after day. I ping my work notebook for this. The calendar integration works so far, but I need help with the end time. Currently only a new calendar entry is created for a period of 5 minutes, but i want a complete calendar entry as soon as the notebook goes online and ended when the notebook is offline. Can somebody help me with it?

Thats the part in my configuration.yaml

binary_sensor:
  - platform: ping
    host: 192.168.x.x
    name: "PING"
    count: 2
    scan_interval: 30

Thats the part in my automation.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)}}"

image

push, anyone there who can help?

Welcome to the community, please read the community guidelines and format your code correctly. Also bumping your thread will not help you, most people dislike this behaviour.

At the time you create the event, how would the system know when it will end? It can’t know this.
The only workaround that comes to my mind is to create one event when you start and a second event when you end your workday.

1 Like

That would also be a solution, but it should also be possible to track the time and to transfer this time to the google calendar as working time, the only question is how I can implement it to start_ and end_time

I don’t think that’s possible. Can you do it with another program?
The problem is that the end time is not known when you create the event. So the only possibilities you have is to create the event at the end of the day or you modify the existing event created in the morning at the end of the day (and as far as I can see there’s no service to modify events from Home Assistant).

It is possible with home-assistant as you can see in the following youtube-video, however this video is not released and I have no idea how to get to this information :[

The guy in the video does this:[quote=“Burningstone, post:5, topic:273299”]
So the only possibilities you have is to create the event at the end of the day
[/quote]
He’s not creating the event when the binary sensor turns on, he creates the event when the binary sensor goes off.

thank you for your suggestion, the calendar entry is now created as soon as the notebook goes offline! i have read and researched a lot on the subject, now it works the way I imagined.
here is the code if someone wants to recreate it:

configuration.yaml

binary_sensor:
  - platform: ping
    host: 192.168.xxx.xxx
    name: "PING"
    count: 2
    scan_interval: 60
    
input_datetime:
  nb_last_on: 
    name: nb_last_on
    has_date: true
    has_time: true

automations.yaml

* id: ‘xxxx’
  alias: create an google calendar
  trigger:
  - platform: state
    entity_id: binary_sensor.ping
    from: 'on'
    to: 'off'
  action:
  - service: google.add_event
    data:
        calendar_id: xxxx
        summary: Homeoffice
    data_template:
      start_date_time: '{{ states("input_datetime.nb_last_on") }}'
      end_date_time: '{{ as_timestamp(states.binary_sensor.ping.last_changed) | timestamp_custom(''%Y-%m-%d
      %H:%M:%S'',true) }}'
        
- alias: nb work on
  trigger:
    platform: state
    entity_id: binary_sensor.ping
    from: 'off'
    to: 'on'
  action:
    - service: input_datetime.set_datetime
      data_template:
        entity_id: input_datetime.nb_last_on
        time: '{{ (as_timestamp(now()) | timestamp_custom("%H:%M:%S", true)) }}'
        date: '{{ (as_timestamp(now()) | timestamp_custom("%Y-%m-%d", true)) }}'

Please use the </> button to format your code correctly, as stated in the community guidelines point 11.

good to know, its done;)