Automation failing - "running_script: false"

I’m writing an automation to add a Google calendar entry and send a message to my phone when a particular file is updated with new data. It’s triggered successfully (using folder watcher) by the closing of the file. The data is just the date and the value of tomorrow’s electricity cost, in a JSON file. This file is updated programmatically once a day, using data grabbed using an external API.

The error I’m reporting is from today’s update. Once it is triggered I toggle my office light ( - a testing step I was previously using to check whether it was being properly triggered). I have included a pause after it’s triggered and before it starts in case it was a slow write causing it (though it is writing to SSD).

Then it sends the calendar event, then the message to the phone.

The light appears to have triggered (though i wasn’t here to see it) but neither of the other actions have happened

The trace timeline indicates it has completed and doesn’t mention errors.

image

This is how it has made the automation yaml.

alias: A octopus test
description: folder event test
trigger:
  - platform: event
    event_type: folder_watcher
    event_data:
      event_type: closed
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 5
      milliseconds: 0
    enabled: true
  - type: toggle
    device_id: xxx
    entity_id: xxx
    domain: light
    enabled: true
  - service: google.add_event
    data:
      calendar_id: >-
        [email protected]
      summary: Tracker region H {{ states("sensor.tracker_cost_tomorrow") }}p
      start_date: '{{ ( states( ''sensor.tracker_date_tomorrow''))}}'
      end_date: '{{ ( states( ''sensor.tracker_date_tomorrow''))}}'
    enabled: true
  - service: notify.mobile_app_xxx
    data:
      message: '"{{ ( states( ''sensor.tracker_date_tomorrow''))}}"'
mode: single```

The errors can be seen in the trace below but I can't see what might have caused them (nor can I see how to attach this as a file rather than reproduce it here!!!). 

Any help or advice would be appreciated

```"{
  "trace": {
    "last_step": "action/3",
    "run_id": "438b66c20ff3d4017360fa584bdbc251",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2023-07-24T09:55:07.996296+00:00",
      "finish": "2023-07-24T09:55:14.451397+00:00"
    },
    "domain": "automation",
    "item_id": "1689631789416",
    "trigger": "event 'folder_watcher'",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2023-07-24T09:55:07.996473+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.a_octopus_test",
              "state": "on",
              "attributes": {
                "id": "1689631789416",
                "last_triggered": "2023-07-23T11:12:06.235119+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "A octopus test"
              },
              "last_changed": "2023-07-23T11:10:42.910506+00:00",
              "last_updated": "2023-07-23T11:12:12.119537+00:00",
              "context": {
                "id": "XXX",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "event",
              "event": {
                "event_type": "folder_watcher",
                "data": {
                  "event_type": "closed",
                  "path": "/share/haelecpricestomorrow.json",
                  "file": "haelecpricestomorrow.json",
                  "folder": "/share"
                },
                "origin": "LOCAL",
                "time_fired": "2023-07-24T09:55:07.993362+00:00",
                "context": {
                  "id": "XXX",
                  "parent_id": null,
                  "user_id": null
                }
              },
              "description": "event 'folder_watcher'"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2023-07-24T09:55:07.999985+00:00",
          "changed_variables": {
            "context": {
              "id": "XXX",
              "parent_id": "XXX",
              "user_id": null
            }
          },
          "result": {
            "delay": 5,
            "done": true
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2023-07-24T09:55:13.002107+00:00"
        }
      ],
      "action/2": [
        {
          "path": "action/2",
          "timestamp": "2023-07-24T09:55:13.328217+00:00",
          "result": {
            "params": {
              "domain": "google",
              "service": "add_event",
              "service_data": {
                "calendar_id": "[email protected]",
                "summary": "Tracker region H 17.0835p",
                "start_date": "2023-07-24",
                "end_date": "2023-07-24"
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ],
      "action/3": [
        {
          "path": "action/3",
          "timestamp": "2023-07-24T09:55:13.972033+00:00",
          "result": {
            "params": {
              "domain": "notify",
              "service": "mobile_app_XXX",
              "service_data": {
                "message": "\"2023-07-24\""
              },
              "target": {}
            },
            "running_script": false
          }
        }
      ]
    },
    "config": {
      "id": "1689631789416",
      "alias": "A octopus test",
      "description": "folder event test",
      "trigger": [
        {
          "platform": "event",
          "event_type": "folder_watcher",
          "event_data": {
            "event_type": "closed"
          }
        }
      ],
      "condition": [],
      "action": [
        {
          "delay": {
            "hours": 0,
            "minutes": 0,
            "seconds": 5,
            "milliseconds": 0
          },
          "enabled": true
        },
        {
          "type": "toggle",
          "device_id": "XXX",
          "entity_id": "XXX",
          "domain": "light",
          "enabled": true
        },
        {
          "service": "google.add_event",
          "data": {
            "calendar_id": "[email protected]",
            "summary": "Tracker region H {{ states(\"sensor.tracker_cost_tomorrow\") }}p",
            "start_date": "{{ ( states( 'sensor.tracker_date_tomorrow'))}}",
            "end_date": "{{ ( states( 'sensor.tracker_date_tomorrow'))}}"
          },
          "enabled": true
        },
        {
          "service": "notify.mobile_app_XXX",
          "data": {
            "message": "\"{{ ( states( 'sensor.tracker_date_tomorrow'))}}\""
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "XXX",
      "parent_id": "XXX",
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "A octopus test",
      "message": "triggered by event 'folder_watcher'",
      "source": "event 'folder_watcher'",
      "entity_id": "automation.a_octopus_test",
      "context_id": "XXX",
      "when": 1690192507.996688,
      "domain": "automation"
    },
    {
      "when": 1690192513.319752,
      "state": "on",
      "entity_id": "light.office_light",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "A octopus test",
      "context_message": "triggered by event 'folder_watcher'",
      "context_source": "event 'folder_watcher'",
      "context_entity_id": "automation.a_octopus_test"
    }
  ]
}
"```

This is why we have a sticky post with, amongst other things, formatting guidance.

1 Like

Ah thanks, missed that, I will try to apply it to the post. I don’t see how I can preview it so it may appear oddly a few times while it’s “in progress”. :slight_smile:

EDIT: Thanks, think it’s fixed now

According to the documentation for the Google Calendar integration, the service call is google.create_event (not google.add_event).

Can’t disagree with that ,but I didn’t make up google.add_event though I can’t find where I got it from - and it works, if I run that part of the automation manually.

I have duplicated the action and changed the second instance to google.create_event. The parameters are a little different so I’ll need to work on it a bit.

Normally I have to wait till it runs automatically tomorrow morning to see if it’s worked… and I won’t really be confident until it has worked a few times without issue.

I don’t understand the google.create_event for defining which calendar to use. It says

A calendar target is selected with a Target Selector

which I’m not clear how to set up, with a fixed calendar name. I presume an entry in configuration.yaml?

Can anyone assist here please with what is meant by a target selector? It’s mentioned in the Calendar integration [Calendar - Home Assistant]

If you have installed the Google Calendar integration, your calendars will appear as calendar entities in the Developer > States view. The “target” for google.create_event is one of your calendar entities produced by the Google Calendar integration.


EDIT

In case you were wondering, the google.add_event service call was deprecated over a year ago.

Thanks on both. Funnily enough the Add still works.

However on a simple automation I can’t get the create event to work. This is how the YAML looks, but I get an error which says “Could not parse date for dictionary value @ data[‘end_date’]. Got None Could not parse date for dictionary value @ data[‘start_date’]. Got None”

service: calendar.create_event
target:
  entity_id: calendar.octopus_tracker_h_region
data:
  summary: "CREATED"
  start_date: "23-07-26"
  end_date: "23-07-26"

I must be missing something but I’ve no idea what…

The error says:

Could not parse date for dictionary value @ data[‘end_date’]. Got None
Could not parse date for dictionary value @ data[‘start_date’]. Got None

The documentation says:

image

Therefore supply the date values in YYYY-MM-DD format.

  start_date: "2023-07-26"
  end_date: "2023-07-27"

I missed that, apologies and thanks. Also maybe not surprisingly for a full day event the end date must be different from the start date.

Maybe now I have that working I can get back to teh original problem, if it remains!!

I hesitate to rush but this triggered autonomously at the right time and did what was expected. As it only does this once a day (and running it manually seemed to sometimes work and sometimes not) I am going to give this one more day before declaring it fixed.

In the end it was a matter of doing stuff according to the book, instead of the sloppy way I’d imagined it should be. :slight_smile: I also did eventually start a new automation from scratch which seemed to work more consistently, as I felt (probably unreasonably) that trying to bodge up the original one wasn’t helping.

So thank you Taras for your help with this. It’s made me think I must be much more careful in future, as I wasted a load of my (and your) time by being a bit slapdash.