Local Calendar - Automation

I have problem with local calendar automation. Im set automation which send notification 6h before event start, but notification do not include correct information about event and show wrong(old) event…

Event which trigger automation:

Im set simple automation with notify event:


But notify message include old data from event which has been triggered yesterday(Yesterday I get same message as today)…

This is trace of automation:

{
  "trace": {
    "last_step": "action/0",
    "run_id": "874f6dd80dfff0e923b8b3d859e38d6f",
    "state": "stopped",
    "script_execution": "finished",
    "timestamp": {
      "start": "2022-12-15T17:00:00.001422+00:00",
      "finish": "2022-12-15T17:00:00.454806+00:00"
    },
    "domain": "automation",
    "item_id": "1670485314684",
    "trigger": null,
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-12-15T17:00:00.001508+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.odvoz_smeti",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-12-14T17:00:00.002029+00:00",
                "mode": "single",
                "current": 0,
                "id": "1670485314684",
                "friendly_name": "Odvoz smeti"
              },
              "last_changed": "2022-12-15T06:25:32.704551+00:00",
              "last_updated": "2022-12-15T06:25:32.704551+00:00",
              "context": {
                "id": "01GMA7B9H0QZWVT1R83K758C36",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "alias": null,
              "platform": "calendar",
              "event": "start",
              "offset": {
                "__type": "<class 'datetime.timedelta'>",
                "total_seconds": -21600
              },
              "calendar_event": {
                "start": "2022-12-16",
                "end": "2022-12-17",
                "summary": "Embalaža",
                "description": "Odvoz embalaže",
                "uid": "102f83b0-76c7-11ed-94e3-5254004facd4",
                "recurrence_id": "20221216",
                "rrule": "FREQ=WEEKLY;INTERVAL=2",
                "all_day": true
              }
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-12-15T17:00:00.002236+00:00",
          "changed_variables": {
            "context": {
              "id": "01GMBBN0M17HPWTQCY63KVANNN",
              "parent_id": null,
              "user_id": null
            }
          },
          "result": {
            "params": {
              "domain": "notify",
              "service": "notify",
              "service_data": {
                "title": "Odvoz smeti: Mešani odpadki",
                "message": "Odvoz mešanih komunalnih odpadkov",
                "data": {
                  "channel": "OdvozSmeti"
                }
              },
              "target": {}
            },
            "running_script": false,
            "limit": 10
          }
        }
      ]
    },
    "config": {
      "id": "1670485314684",
      "alias": "Odvoz smeti",
      "description": "",
      "trigger": [
        {
          "platform": "calendar",
          "event": "start",
          "offset": "-6:0:0",
          "entity_id": "calendar.odvoz_smeti"
        }
      ],
      "condition": [],
      "action": [
        {
          "service": "notify.notify",
          "data": {
            "title": "Odvoz smeti: {{ state_attr('calendar.odvoz_smeti', 'message') }}",
            "message": "{{ state_attr('calendar.odvoz_smeti', 'description') }}",
            "data": {
              "channel": "OdvozSmeti"
            }
          }
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01GMBBN0M17HPWTQCY63KVANNN",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Odvoz smeti",
      "message": "triggered",
      "source": null,
      "entity_id": "automation.odvoz_smeti",
      "context_id": "01GMBBN0M17HPWTQCY63KVANNN",
      "when": 1671123600.001677,
      "domain": "automation"
    }
  ]
}

What Im do wrong in notify event to show wrong data?

It is important when using offsets to use the trigger variable for your title and message since the current state of the calendar entitiy might not match the event you are triggering off of.

If you do not use conditions to limit it, the actions will be executed for every event in your calendar. To limit execution of the actions to a specific event, use a Calendar Trigger then use conditions to limit execution of the actions based on one of the attributes of the calendar event. You can use State or Template conditions. Again, it will be better to use template conditions based on the trigger variable, especially if you are using an offset or your calendar has overlapping events.

trigger:
  - platform: calendar
    event: start
    offset: "-6:0:0"
    entity_id: calendar.odvoz_smeti
condition:
    - "{{ trigger.calendar_event.summary == 'Embalaza' }}"
action:
  - service: notify.notify
    data:
      title: "Odvoz smeti: {{ trigger.calendar_event.summary }}"
      message: "{{ trigger.calendar_event.description }}"
      data:
        channel: OdvozSmeti
mode: parallel

Hi @Didgeridrew thanks for your reply and solution. I see what I did wrong. Im use wrong functions in action… Im replace my functions with your and now work as must. I don’t have condition set because I don’t need it. I use seperate calendars for seperate things, because there is no way to set different colors for events of some type(Trash pickup, vacations … ) This autamation is for trash pickup and need to be triggered for all events in this calendar. For some other calendars I will probably need conditions to filter events…
Thanks again for fast reply.

1 Like